public async Task <IActionResult> Register(UserProfile userProfile) { try { userProfile.CreateDateTime = DateAndTime.Now; userProfile.UserTypeId = 1; var userProfileCheck = _userProfileRepository.GetByEmail(userProfile.Email); if (userProfileCheck != null) { ModelState.AddModelError("Email", "Please enter unique email"); return(View()); } _userProfileRepository.AddNewUser(userProfile); var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, userProfile.Id.ToString()), new Claim(ClaimTypes.Email, userProfile.Email), new Claim(ClaimTypes.Role, userProfile.UserTypeId.ToString()) }; var claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity)); return(RedirectToAction("Index", "Home")); } catch { return(View(userProfile)); } }