public AISTrack Add(AISTrack AISTrackModel) { try { using (AISTrackRepository aisTrackRepo = new AISTrackRepository()) { // Validate and Map data over here if (AISTrackModel != null) { var rowId = aisTrackRepo.Insert <AISTrack>(AISTrackModel); AISTrackModel.AISTrackId = rowId; } if (MemCache.IsIncache("AllAISTracksKey")) { MemCache.GetFromCache <List <AISTrack> >("AllAISTracksKey").Add(AISTrackModel); } else { List <AISTrack> tracks = new List <AISTrack>(); tracks.Add(AISTrackModel); MemCache.AddToCache("AllAISTracksKey", tracks); } return(AISTrackModel); } } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); string timeZone = "Pakistan Standard Time"; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(Login.Email, Login.Password, Login.RememberMe, lockoutOnFailure : false); user = await _userManager.FindByEmailAsync(Login.Email); if (result.Succeeded) { //if (!_hostingEnvironment.IsDevelopment()) //{ // if (string.IsNullOrWhiteSpace(Login.Token)) // { // ModelState.AddModelError(string.Empty, "Please provide token"); // await HttpContext.SignOutAsync(); // return Page(); // } // else // { // EncryptorDecryptorEngine.DecryptString(Login.Token, out string decryptedString, out string errorMessage); // if (!string.IsNullOrWhiteSpace(errorMessage)) // { // ModelState.AddModelError(string.Empty, errorMessage); // await HttpContext.SignOutAsync(); // return Page(); // } // else // { // string[] stringParts = decryptedString.Split("|"); // if (stringParts.Length > 0) // { // timeZone = stringParts[1]; // DateTime tokenDateTime = Convert.ToDateTime(stringParts[0]); // if (!(Common.GetLocalDateTime(timeZone, tokenDateTime) > Common.GetLocalDateTime(timeZone, DateTime.Now).AddMinutes(-1))) // { // ModelState.AddModelError(string.Empty, "Token Expired. Please regenerate"); // await HttpContext.SignOutAsync(); // return Page(); // } // } // else // { // ModelState.AddModelError(string.Empty, "Invalid Token"); // await HttpContext.SignOutAsync(); // return Page(); // } // } // } //} if (!MemCache.IsIncache("Timezone_" + user.Subscriber_Id)) { MemCache.AddToCache("Timezone_" + user.Subscriber_Id, timeZone); } _logger.LogInformation("User logged in."); //user = await _userManager.FindByEmailAsync(Login.Email); UserEventLogging(user, "User Signed In", Convert.ToInt32(EventTypes.User_Signed_In)); // Get the roles for the user var roles = await _userManager.GetRolesAsync(user); if (roles.Contains("ADMIN")) { return(LocalRedirect("~/Canvas")); } else if (roles.Contains("OPERATOR")) { return(LocalRedirect("~/Canvas")); } else if (roles.Contains("OIC")) { return(LocalRedirect("~/Canvas")); } else if (roles.Contains("ORO")) { return(LocalRedirect("~/Canvas")); } else { return(LocalRedirect("~Login")); } } if (result.RequiresTwoFactor) { return(RedirectToPage("~/LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Login.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); UserEventLogging(user, "User account locked out", Convert.ToInt32(EventTypes.User_Account_Locked_Out)); return(RedirectToPage("~/Lockout")); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); UserEventLogging(user, "Invalid login attempt", Convert.ToInt32(EventTypes.Invalid_Login_Attempt)); return(Page()); } } // If we got this far, something failed, redisplay form return(Page()); }