public async Task <ActionResult> CreateMessage([FromBody] CreateMessageServiceModel message) { var userId = await this.userService.GetUserId(this.User); var result = await this.messageService.Create(message, userId); return(this.Ok(result)); }
public async Task <ActionResult> UpdateMessage([FromBody] CreateMessageServiceModel message) { var userId = await this.userService.GetUserId(this.User); var result = await this.messageService.Update(message, userId); if (result == null) { return(this.BadRequest()); } return(this.Ok(result)); }
public async Task <CreateMessageServiceModel> Update(CreateMessageServiceModel model, string userId) { var message = new Message { SendingTime = model.SendingTime, TextMessage = model.TextMessage, ChatRoomId = model.ChatRoomId, UserId = userId, }; this.messagesRepository.Update(message); await this.messagesRepository.SaveChangesAsync(); return(model); }
public async Task Send(string message) { // Add Message to database var currentMessage = new CreateMessageServiceModel { SendingTime = DateTime.UtcNow, TextMessage = message, ChatRoomId = 1, }; var userID = await this.userService.GetUserId(this.Context.User); var result = await this.messageService.Create(currentMessage, userID); await this.Clients.All.SendAsync( "NewMessage", new MessageViewModel { Id = result, User = this.Context.User.Identity.Name, Text = message, DateOfMessage = DateTime.UtcNow.ToShortTimeString(), }); }