public async Task <IActionResult> Create([Bind("Reciever,Title,text")] Message message) { List <string> users = CommunityUser.getEmails(_context2); ViewData["users"] = users; try //creates new message, gets receivers id and send back confirmation { message.Reciever = _context2.Users.Single(u => u.Email == message.Reciever).Id; var userId = _userManager.GetUserId(User); message.Sender = userId; message.TimeSent = DateTime.Now; message.Read = false; _context.Add(message); await _context.SaveChangesAsync(); ViewData["Confirmation"] = "Message sent to " + CommunityUser.getEmail(message.Reciever, _context2) + ", " + DateTime.Now; ViewData["users"] = users; return(View(message)); } catch (InvalidOperationException e) { ViewData["users"] = users; ViewData["Confirmation"] = "Failed to deliver"; return(View(message)); } return(View(message)); }
// GET: Messages/Create public IActionResult Create() { List <string> users = CommunityUser.getEmails(_context2); ViewData["users"] = users; ViewData["Confirmation"] = ""; return(View()); }