last login date and time

  public void RetriveLastLogInInfo()
        {
            HttpResponseMessage usr = client.GetAsync("MasterLoginHistory").Result;
            if (usr.IsSuccessStatusCode)
            {
                MasterLoginHistory = usr.Content.ReadAsAsync<List<Master_Login_History>>().Result;
                if (MasterLoginHistory != null)
                {
                    if (MasterLoginHistory.Where(a => a.Login_User_ID == Convert.ToInt32(Session["PartnerLoginUserID"])).Count() > 1)
                    {
                        var LogHistoryId = (from a in MasterLoginHistory where a.Login_User_ID == Convert.ToInt32(Session["RegistrationId"]) select a).ToList().OrderByDescending(a => a.Login_LogHistory_Id).Take(2).Skip(1).FirstOrDefault();
                        var RegisterInfo = (from c in MasterLoginHistory
                                            where c.Login_LogHistory_Id == Convert.ToInt32(LogHistoryId.Login_LogHistory_Id)
                                            select new
                                            {
                                                c.User_LoginTime,
                                                c.User_LogInDate
                                            }).FirstOrDefault();
                        if (RegisterInfo != null)
                        {
                            lblLastLoginTime.Text = RegisterInfo.User_LoginTime.ToString().Substring(0, 8);
                            lblLastLogindate.Text = Convert.ToDateTime(RegisterInfo.User_LogInDate).Date.ToString("dd-MM-yyyy");
                        }
                    }
                    else
                    {
                        var data = (from a in MasterLoginHistory where a.Login_User_ID == Convert.ToInt32(Session["RegistrationId"]) select a.Login_LogHistory_Id).Max();
                        var RegisterInfo = (from c in MasterLoginHistory
                                            where c.Login_LogHistory_Id == data
                                            select new
                                            {
                                                c.User_LoginTime,
                                                c.User_LogInDate
                                            }).FirstOrDefault();
                        if (RegisterInfo != null)
                        {
                            lblLastLoginTime.Text = RegisterInfo.User_LoginTime.ToString().Substring(0, 8);
                            lblLastLogindate.Text = Convert.ToDateTime(RegisterInfo.User_LogInDate).Date.ToString("dd-MM-yyyy");
                        }
                    }
                }
            }
        }

Comments

Popular posts from this blog

FAQ BIND

Create Schema Using C# Asp .Net Dynamically.

resgination mail