public ActionResult AddContact(Contacts Contacts) { if (ModelState.IsValid) // check if model state is valid(if all required fields are filled). { Accounts accounts = repo.GetAccount(Contacts.Email); // check if given e-mailaddress exist in the database, if not return errormesagge with explanation if (accounts != null) { Accounts account = (Accounts)Session["LoggedInAccounts"]; // gather contact details of logged in user. Contacts.OwnerEmail = account.Email; ContactRepo.AddContacts(Contacts); // call the method that executes the operatian in the DB. return(RedirectToAction("Index")); } else { ModelState.AddModelError("contact-error", "the provided user does not exist"); } } return(View(Contacts)); }
public ActionResult Register(RegisterModel user) { Accounts account = repo.GetAccount(user.Email); // check if given e-mailaddress already exist in the database, if so return errormesagge with explanation if (account != null) { ModelState.AddModelError("Register-error", "Email-Adress already exist"); return(View(user)); } // check if Modelstate is valid (if all required fields are filled in), if valid forward to chat page else if (ModelState.IsValid) { repo.RegisterAccount(user); return(RedirectToAction("Index", "Chat")); } else { ModelState.AddModelError("Register-error", "Please fill in the missing fields"); return(View(user)); } }