public async Task <IActionResult> Login(User user) { if (ModelState.IsValid) { var resultToken = _accountAgent.GetToken(user); if (resultToken.Success) { //HttpContext.Session.Set(Constants.SessionKeyState, token.objectResult); //user.Token = token.objectResult; var result = await _signInManager.PasswordSignInAsync(user.Username, user.Password, false, lockoutOnFailure : false); if (result.Succeeded) { var userData = _accountAgent.GetUserByCredentials(user.Username, user.Password, resultToken.objectResult).objectResult; var userId = userData.Id; var establishment = _establishmentAgent.GetEstablishmentById(userId); if (establishment.Success) { userData.Establishment = establishment.objectResult; var menu = _accountAgent.GetModulesByUserId(userId, null); if (menu.Success) { userData.Modules = menu.objectResult; } } else { HttpContext.Session.Set(Constants.SessionKeyState, userData); return(await Task.FromResult(RedirectToAction("NewEstablishment", "Establishment"))); } //this.User.GetUserId(); HttpContext.Session.Set(Constants.SessionKeyState, userData); return(await Task.FromResult(RedirectToAction("Dashboard", "Book"))); } else { ModelState.AddModelError("", "Invalid credentials"); } } } return(await Task.FromResult(View(user))); }