Files
podnoms/server/Controllers/ChatController.cs
Fergal Moran 760a26e51a Docker changes
2018-05-08 15:35:23 +01:00

30 lines
1.0 KiB
C#

using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using PodNoms.Api.Models.ViewModels;
using PodNoms.Api.Services.Auth;
using PodNoms.Api.Services.Hubs;
namespace PodNoms.Api.Controllers {
[Route("[controller]")]
[Authorize]
public class ChatController : BaseAuthController {
private readonly HubLifetimeManager<ChatHub> _hub;
public ChatController(IHttpContextAccessor contextAccessor, UserManager<ApplicationUser> userManager,
HubLifetimeManager<ChatHub> chatHubContext) :
base(contextAccessor, userManager) {
this._hub = chatHubContext;
}
[HttpPost]
public async Task<ActionResult<ChatViewModel>> Post([FromBody]ChatViewModel message) {
await this._hub.SendAllAsync("SendMessage", new object[] { message.Message });
return Ok(message);
}
}
}