Esempio n. 1
0
 public bool Delete(int AISTrackId)
 {
     try
     {
         using (AISTrackRepository aisTrackRepo = new AISTrackRepository())
         {
             var AISTrackExisting = aisTrackRepo.Get <AISTrack>(AISTrackId);
             if (AISTrackExisting == null)
             {
                 return(false);
             }
             else
             {
                 aisTrackRepo.Delete <AISTrack>(AISTrackId);
                 if (MemCache.IsIncache("AllAISTracksKey"))
                 {
                     MemCache.GetFromCache <List <AISTrack> >("AllAISTracksKey").Remove(AISTrackExisting);
                 }
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 2
0
        public bool Update(AISTrack AISTrackModel)
        {
            try
            {
                using (AISTrackRepository aisTrackRepo = new AISTrackRepository())
                {
                    if (MemCache.IsIncache("AllAISTracksKey"))
                    {
                        List <AISTrack> aISTracks = MemCache.GetFromCache <List <AISTrack> >("AllStakeholdersKey");
                        if (aISTracks.Count > 0)
                        {
                            aISTracks.Remove(aISTracks.Find(x => x.AISTrackId == AISTrackModel.AISTrackId));
                        }
                    }

                    aisTrackRepo.Update <AISTrack>(AISTrackModel);
                    if (MemCache.IsIncache("AllStakeholdersKey"))
                    {
                        MemCache.GetFromCache <List <AISTrack> >("AllStakeholdersKey").Add(AISTrackModel);
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
 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;
     }
 }
Esempio n. 4
0
        public List <AISTrack> List(Dictionary <string, string> dic = null)
        {
            try
            {
                List <AISTrack> lstAISTracks = new List <AISTrack>();
                if (MemCache.IsIncache("AllAISTracksKey"))
                {
                    return(MemCache.GetFromCache <List <AISTrack> >("AllAISTracksKey"));
                }
                else
                {
                    if (dic == null)
                    {
                        dic = new Dictionary <string, string>();
                    }

                    dic.Add("orderby", "MMSI");
                    dic.Add("offset", "1");
                    dic.Add("limit", "200");

                    var parameters = this.ParseParameters(dic);
                    using (AISTrackRepository aisTrackRepo = new AISTrackRepository())
                    {
                        lstAISTracks = aisTrackRepo.GetListPaged <AISTrack>(Convert.ToInt32(dic["offset"]), Convert.ToInt32(dic["limit"]), parameters, dic["orderby"]).ToList();
                        return(lstAISTracks);
                    }
                }
            }
            catch (Exception ex)
            {
                //_trace.Error("Error Retrieving Data", exception: ex);
                throw ex;
            }
        }
Esempio n. 5
0
 public AISTrack GetById(int AISTrackId)
 {
     try
     {
         if (MemCache.IsIncache("AllAISTracksKey"))
         {
             return(MemCache.GetFromCache <List <AISTrack> >("AllAISTracksKey").Where <AISTrack>(x => x.AISTrackId == AISTrackId).FirstOrDefault());
         }
         using (AISTrackRepository aisTrackRepo = new AISTrackRepository())
         {
             AISTrack AISTrackModel = new AISTrack();
             {
                 AISTrackModel = aisTrackRepo.Get <AISTrack>(AISTrackId);
                 return(AISTrackModel);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 6
0
        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());
        }