public IActionResult RegisterUser(User model) { model.UserRole = "User"; //If user input for registration is valid if (ModelState.IsValid) { //Check whether email is already existing in the database Boolean validEmail = _context.CheckExistingEmail(model); if (validEmail) { _context.RegisterUser(model); User registeredUser = _context.GetUserByEmail(model.UserEmail); _context.LogAction("Registration", "User " + registeredUser.FirstName + " " + registeredUser.LastName + " has successfully registered with " + registeredUser.UserEmail + " as ID " + registeredUser.UserID + ".", registeredUser); TempData["Status"] = "Registration successful. Please login here."; return(RedirectToAction("Login")); } else { ViewBag.Message = "Email already exists, please enter another email."; ViewData["Roles"] = model.Roles; return(View()); } } ViewData["Roles"] = model.Roles; return(View()); }