public ActionResult Message(int id, PostMessageForm message) { PostMessage action = new PostMessage(_db, id, Requester(), message); action.Execute(); return(RedirectToAction("Messages", new { id })); }
public async Task <ServiceOperationResult <MessageViewModel> > SendMessageAsync(long userId, PostMessageForm form) { if (!await _unitOfWork.Users.AnyAsync(u => u.Id == userId)) { return(ServiceOperationResult.NotFound <MessageViewModel>("User not found.")); } var translated = _translationService.TranslateMessageToUr(form.Message); if (!translated.IsSuccessful) { return(ServiceOperationResult.UnprocessableEntity <MessageViewModel>("Failed to translate message to UR.")); } var message = new Message { Content = translated.Data, SenderId = userId }; await _unitOfWork.Messages.AddAsync(message); await _unitOfWork.SaveAsync(); var sender = await _unitOfWork.Users.GetAsQueryable().SingleAsync(u => u.Id == userId); return(ServiceOperationResult.Ok(new MessageViewModel { Id = message.Id, Message = message.Content, Sender = sender.Username, SenderId = message.SenderId, SentDate = message.CreatedAt })); }
public PostMessage(ApplicationDbContext db, int groupId, ApplicationUser requester, PostMessageForm message) : base(db, groupId, requester) { this.message = message; }