public async Task <IActionResult> Register(RegisterViewModel reg) { if (ModelState.IsValid) { //Check Username is not taken if (!await AccountDb.IsUserNameTaken(reg.UserName, _context)) { Account acc = new Account() { FullName = reg.FullName, Email = reg.Email, Username = reg.UserName, Password = reg.Password }; //add account to database await AccountDb.Register(acc, _context); //create user session SessionHelper.CreateUserSession(_http, acc.AccountID, acc.Username); #region Manual CreateUserSession Practice //HttpContext.Session.SetInt32("Id", acc.AccountID); //HttpContext.Session.SetString("Username", acc.Username); #endregion return(RedirectToAction("Index", "Home")); } else { //Display Error with other username error msg. ModelState.AddModelError(nameof(Account.Username), "Username is already taken, Please pick another."); } } return(View(reg)); }