public IActionResult Send(SendMessageFormViewModel viewModel) { var recipientInDb = _context.Users.SingleOrDefault(u => u.UserName == viewModel.UserName); if (recipientInDb == null) { return(Redirect("/messages/inbox/notfound")); } var currUser = _userManager.GetUserId(HttpContext.User); var newMessage = new Message { UserToId = recipientInDb.Id, UserFromId = currUser, DateSent = DateTime.Now, Subject = viewModel.Subject, MessageBody = viewModel.MessageBody }; _context.Add(newMessage); _context.SaveChanges(); return(Redirect("/messages/inbox/success")); }
public IActionResult Compose(string UserName) { if (!string.IsNullOrWhiteSpace(UserName)) { var recipientInDb = _context.Users.Single(u => u.UserName.Equals(UserName)); var viewModel = new SendMessageFormViewModel { UserName = recipientInDb.UserName }; return(View(viewModel)); } return(View()); }