public ActionResult SendMessage(SendMessageViewModel SendMessageViewModel, int?messageID) { var user = _userServices.GetUser(SendMessageViewModel.Username); if (user == null) { ModelState.AddModelError("Username", "User doesn't exist."); } else if (user.UserID == _currentUser.UserID) { ModelState.AddModelError("Username", "You can't send a message to yourself!"); } if (IsModelValidAndPersistErrors()) { var message = _messageServices.SendMessage(_currentUser.UserID, user.UserID, SendMessageViewModel.Subject, SendMessageViewModel.Message); SetSuccess("Message sent to <b>" + user.Username + "</b>"); string messageURL = Url.Action("ViewMessage", "Messages", new { MessageID = message.MessageID }); _emailServices.NewMessage(message, user, messageURL); return(RedirectToAction("ViewMessage", new { messageID = message.MessageID })); } if (messageID.HasValue) { return(RedirectToAction("ViewMessage", new { messageID = messageID.Value })); } else { return(RedirectToSelf()); } }