public IActionResult Register(Account a) { if (ModelState.IsValid) { bool isEmailAndUsernameAvailable = true; if (AccountDb.IsEmailTaken(a.Email)) { isEmailAndUsernameAvailable = false; ModelState.AddModelError(string.Empty, "Email address is taken"); } if (AccountDb.IsUsernameTaken(a.Username)) { isEmailAndUsernameAvailable = false; ModelState.AddModelError(string.Empty, "Username is taken"); } if (!isEmailAndUsernameAvailable) { return(View(a)); } AccountDb.Add(a); SessionHelper.LogUserIn(_httpAccessor, a.AccountId, a.Username); TempData["Message"] = "You registered sucessfully"; return(RedirectToAction("Index", "Home")); } return(View(a)); }