public IActionResult DoRegister(RegisterViewModel registerViewModel) { // Declare some easier to use variables var name = registerViewModel.Name; var pass = registerViewModel.Pass; // Try to register the User if (_userBusinessLogic.Register(name, pass)) { // Log in var userId = _userBusinessLogic.LogIn(name, pass); // Create new Session HttpContext.Session.SetInt32("UserId", (int)userId); // Pass the success-message through the TempData, because the model cannot be passed TempData["SuccessMessage"] = "Successfully registered and logged in"; return(RedirectToAction("Index", "Home")); } return(View("Register", new RegisterViewModel() { ErrorMessage = "Username is already taken" })); }
public ActionResult <ReturnMessage> Register(UserDto userDto) { User user = new User(); user.Username = userDto.Username; user.Password = userDto.Password; user.Email = userDto.Email; return(_userBL.Register(user)); }