public ActionResult ProcessNewMessage(SendMessageViewModel model) { if (ModelState.IsValid) { List <string> MessageFormErrorList = new List <string>(); ViewData["To"] = model.To; ViewData["MessageSubject"] = model.MessageSubject; ViewData["MessageBody"] = model.MessageBody; MessageQuery messageQuery = new MessageQuery(); bool safe = true; // Initialize to true and set to false if error is found if (string.IsNullOrEmpty(model.MessageBody) || string.IsNullOrWhiteSpace(model.MessageBody)) // Check if message body is empty { MessageFormErrorList.Add("Message doesn't contain a message"); safe = false; } if (string.IsNullOrEmpty(model.To)) { MessageFormErrorList.Add("Recipient e-mail address not set"); safe = false; } UserQuery userQuery = new UserQuery(); if (userQuery.CheckIfUserExists(model.To) == false) // Check if recipient is a valid user { MessageFormErrorList.Add("User with e-mail address " + model.To + " doesn't exist"); safe = false; } if (safe == true) // If there are no errors, proceed with sending the message { messageQuery.SendMessage(model.To, User.Identity.Name, model.MessageSubject, model.MessageBody); return(RedirectToAction("Inbox", "Message")); } else { TempData["MessageFormError"] = MessageFormErrorList; return(RedirectToAction("New", "Message")); } } else { return(RedirectToAction("New", "Message")); } }