Beispiel #1
0
        public static void UpdateLoginHistory(LoginHistory objLoginHistory)
        {
            TeachersEntities db = new TeachersEntities();

            db.Entry(objLoginHistory).State = EntityState.Modified;
            db.SaveChanges();
        }
Beispiel #2
0
        /// <summary>
        /// Page Load functionality
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(Convert.ToString(Session["UserId"])) || !string.IsNullOrEmpty(Convert.ToString(Session["UserName"])))
                {
                    int          userId = Convert.ToInt32(Session["UserId"]);
                    LoginHistory objLoginLogoutHistory = new LoginHistory();
                    UserBLL      objUserBLL            = new UserBLL();

                    objLoginLogoutHistory.UserId     = userId;
                    objLoginLogoutHistory.LogoutTime = DateTime.Now;
                    objLoginLogoutHistory.UpdatedBy  = userId;
                    objLoginLogoutHistory.UpdatedOn  = DateTime.Now;
                    objLoginLogoutHistory.UpdatedIp  = CommonUtils.GetIPAddresses();
                    objLoginLogoutHistory.UserName   = Convert.ToString(Session["UserName"]);

                    objUserBLL.LogLogoutTime(objLoginLogoutHistory);
                    ClearSession();
                    Response.Redirect("login.aspx");
                }
                Response.Redirect("login.aspx");
            }
            catch (Exception ex)
            {
                log.Error("Page_Load \n Message: " + ex.Message + "\n Source: " + ex.Source + "\n StackTrace: " + ex.StackTrace);
                ExceptionLog.WriteLog(PageName + " @ Page_Load ", ex.Message + " \n " + ex.StackTrace);
                Response.Redirect("login.aspx");
            }
        }
Beispiel #3
0
        public void LoginTime(string userName)
        {
            using (var dbContext = new ApplicationDbContext())
            {
                var user      = dbContext.Users.Where(w => w.UserName == userName).FirstOrDefault();
                var modelView = dbContext.LoginHistories.Where(w => w.UserId == user.Id).OrderByDescending(w => w.Id).FirstOrDefault();

                if (modelView == null)
                {
                    var model = new LoginHistory
                    {
                        UserId     = user.Id,
                        LoginTime  = DateTime.UtcNow,
                        LogoutTime = null,
                        IsLogedIn  = true
                    };

                    dbContext.LoginHistories.Add(model);
                }
                else
                {
                    modelView.UserId     = user.Id;
                    modelView.LoginTime  = DateTime.UtcNow;
                    modelView.LogoutTime = null;
                    modelView.IsLogedIn  = true;
                }

                dbContext.SaveChanges();
            }
        }
Beispiel #4
0
        public static void InsertLoginHistory(LoginHistory objLoginHistory)
        {
            TeachersEntities db = new TeachersEntities();

            db.LoginHistories.Add(objLoginHistory);
            db.SaveChanges();
        }
Beispiel #5
0
        /// <summary>
        /// Mehtod to set claims.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        private async Task SetClaims(Users user, string role)
        {
            _loginHistory = new LoginHistory
            {
                LoginTime  = DateTime.Now,
                LogoutTime = DateTime.MinValue,
                UserId     = user.UserId
            };
            _LoginHistoryCol.InsertOne(_loginHistory);

            #region claims
            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, string.Concat(user.FirstName, " ", user.LastName)),
                new Claim(ClaimTypes.Email, user.Email),
                new Claim(ClaimTypes.Role, role),
                new Claim(AppUtility.LoginHistoryId, _loginHistory.UserILoginID.ToString()),
                new Claim(AppUtility.UserId, user.UserId.ToString())
            };

            var claimsIdentity = new ClaimsIdentity(
                claims, CookieAuthenticationDefaults.AuthenticationScheme);

            var authProperties = new AuthenticationProperties
            {
                AllowRefresh = true,
            };

            await HttpContext.SignInAsync(
                CookieAuthenticationDefaults.AuthenticationScheme,
                new ClaimsPrincipal(claimsIdentity),
                authProperties);

            #endregion
        }
Beispiel #6
0
        public ActionResult Login(LoginUser loginUser)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            if (loginUserManager.IsExistUserNamePassword(loginUser.UserName, loginUser.Password))
            {
                Session["username"] = loginUser.UserName;
                Session["password"] = loginUser.Password;

                string   ip   = Request.UserHostAddress;
                DateTime date = DateTime.Now;

                LoginHistory historymodel = new LoginHistory()
                {
                    UserName = Session["username"].ToString(),
                    Ip       = ip,
                    Time     = date.ToString()
                };
                history.Add(historymodel);
                return(RedirectToAction("Home", "Home"));
            }
            else
            {
                ModelState.Clear();
                ViewBag.message = "Username or Password Went Wrong";
            }
            return(View());
        }
        public string CreateLogin()
        {
            string id;
            var    user = this;

            using (var context = ApplicationDbContext.Create())
            {
                var loginHistory = context.Set <LoginHistory>();

                var existLogin = loginHistory.FirstOrDefault(l =>
                                                             l.LogoutTime == null && l.AgentId == AppIdentity.AgentInfo && l.UserId == user.Id);

                if (existLogin != null)
                {
                    return(existLogin.Id);
                }

                id = AppIdentity.AppInfo + "U" + this.Id + "T" + DateTime.UtcNow.ToLong() + "E" +
                     GeneralHelper.UtcNowTicks;
                var login = new LoginHistory
                {
                    Id           = id,
                    UserId       = user.Id,
                    LoginTime    = DateTime.UtcNow.ToLong(),
                    LogoutTime   = null,
                    AgentId      = AppIdentity.AgentInfo,
                    ModifiedBy   = user.Id,
                    UserBranchId = user.BranchId
                };
                loginHistory.Add(login);
                context.SaveChanges();
            }

            return(id);
        }
Beispiel #8
0
 public void DefaultSetSessionOnFirstLogin(UserLogin userLogin, string token)
 {
     Core.Model.LoginHistory logHist  = new LoginHistory();
     Core.Model.User         userData = new Core.Model.User();
     userData           = _userData.GetUserDetailByUserIDAndPassword(userLogin.UserID, userLogin.Password);
     Session["UserID"]  = userData.UserID;
     Session["Role"]    = userData.Role;
     Session["Email"]   = userData.EmailID;
     Session["SECID"]   = userData.SECID;
     Session["BPID"]    = userData.BPID;
     Session["Partner"] = userData.Partner;
     Session["BPType"]  = userData.BPType;
     FormsAuthentication.SetAuthCookie(userData.UserID, true);
     logHist.UserID = userData.UserID;
     logHist.Server = "";
     _userData.LoginHistory(logHist);
     // check and create directory
     CreateFolder();
     // Custom session management
     userData.UserIPAddress   = Request.UserHostAddress;
     userData.UserBrowserName = Request.Browser.Browser.ToLower().Trim();
     userData.SessionToken    = token;
     TempData["expiredate"]   = DateTime.Today.Date.AddMonths(1);
     _userData.InsertUpdateCustomSessionData(userData, "insert");
 }
Beispiel #9
0
        protected void Unnamed_LoggingOut(object sender, LoginCancelEventArgs e)
        {
            //Log the user out
            Context.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);

            //Record the logout if a record for the login existed
            if (Session["LoginHistoryPK"] != null && !String.IsNullOrWhiteSpace(Session["LoginHistoryPK"].ToString()))
            {
                //Get the login history pk from session
                int historyPK = Convert.ToInt32(Session["LoginHistoryPK"].ToString());

                //Add the record to the database with the logout time
                using (PyramidContext context = new PyramidContext())
                {
                    LoginHistory history = context.LoginHistory.Find(historyPK);
                    history.LogoutTime = DateTime.Now;
                    history.LogoutType = "User logged out via the logout button on the navbar";
                    context.SaveChanges();
                }
            }

            //Ensure that the user's session is clear
            Session.Abandon();

            //Redirect the user to login page
            Response.Redirect("/Account/Login.aspx?messageType=LogOutSuccess");
        }
Beispiel #10
0
        public string LogoutFromWork(AtWork atWork)
        {
            LoginHistory loginHistory = new LoginHistory()
            {
                LoginTime = atWork.LoginTime, LogoutTime = DateTime.Now, EmployeeId = atWork.EmployeeId
            };

            try
            {
                unitOfWork.BeginTransaction();

                unitOfWork.AtWorkManager.Delete(atWork);
                unitOfWork.SaveChanges();

                unitOfWork.LoginHistoryManager.Create(loginHistory);
                unitOfWork.SaveChanges();

                unitOfWork.CommitTransaction();

                return("Logout successful.");
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                return(e.Message);
            }
        }
Beispiel #11
0
    public List <LoginHistory> GetLoginTotals()
    {
        List <LoginHistory> retValue = new List <LoginHistory>();
        StringBuilder       sbQuery  = new StringBuilder();

        sbQuery.AppendLine("SELECT username, COUNT(*) ");
        sbQuery.AppendLine("FROM LoginHistory ");
        sbQuery.AppendLine("GROUP BY username");
        using (SqlConnection conn = new SqlConnection(strConn)) {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand(sbQuery.ToString(), conn)) {
                cmd.CommandType = CommandType.Text;
                using (SqlDataReader reader = cmd.ExecuteReader()) {
                    while (reader.Read())
                    {
                        var row = new LoginHistory {
                            UserName    = reader.GetString(0)
                            , Hit_Count = reader.GetInt32(1)
                        };
                        retValue.Add(row);
                    }
                }
            }
            conn.Close();
        }
        return(retValue);
    }
        public async void loginhistory()
        {
            Location location = await Geolocation.GetLocationAsync();

            if (location == null)
            {
                location = await Geolocation.GetLocationAsync(new GeolocationRequest
                {
                    DesiredAccuracy = GeolocationAccuracy.Medium,
                    Timeout         = TimeSpan.FromSeconds(30)
                });
            }

            dispositivo();

            LoginHistory lg = new LoginHistory()
            {
                IdUsuario     = App.usuario.Id,
                Longitud      = location.Longitude.ToString(),
                Latitud       = location.Latitude.ToString(),
                IdDispositivo = App.dispositivo.Id
            };

            await App.MobileService.GetTable <LoginHistory>().InsertAsync(lg);
        }
        public async Task <IActionResult> GetAll()
        {
            User usr      = Functions.getUser(_cache); // get logged user
            var  attempts = await _db.LoginAttempts.Where(a => a.UserId == usr.Id).OrderByDescending(a => a.Date).ToListAsync();

            List <LoginHistory> loginHistories = new List <LoginHistory>();

            foreach (LoginAttempt login in attempts)
            {
                LoginHistory history = new LoginHistory()
                {
                    AddressIp = login.AddressIp,
                    Date      = login.Date.ToString("dddd, dd MMMM yyyy"),
                    Time      = login.Date.ToString("HH:mm:ss"),
                };
                if (login.Successful)
                {
                    history.Successful = "Successful";
                }
                else
                {
                    history.Successful = "Error";
                }
                loginHistories.Add(history);
            }

            return(Json(new { data = loginHistories })); // return his login attempts
        }
Beispiel #14
0
        /// <summary>
        /// Page Load functionality
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                if (!string.IsNullOrEmpty(Convert.ToString(Session["UserId"])) || !string.IsNullOrEmpty(Convert.ToString(Session["UserName"])))
                {
                    int userId = Convert.ToInt32(Session["UserId"]);
                    LoginHistory objLoginLogoutHistory = new LoginHistory();
                    UserBLL objUserBLL = new UserBLL();

                    objLoginLogoutHistory.UserId = userId;
                    objLoginLogoutHistory.LogoutTime = DateTime.Now;
                    objLoginLogoutHistory.UpdatedBy = userId;
                    objLoginLogoutHistory.UpdatedOn = DateTime.Now;
                    objLoginLogoutHistory.UpdatedIp = CommonUtils.GetIPAddresses();
                    objLoginLogoutHistory.UserName = Convert.ToString(Session["UserName"]);

                    objUserBLL.LogLogoutTime(objLoginLogoutHistory);
                    ClearSession();
                    Response.Redirect("login.aspx");
                }
                Response.Redirect("login.aspx");
            }
            catch (Exception ex)
            {
                log.Error("Page_Load \n Message: " + ex.Message + "\n Source: " + ex.Source + "\n StackTrace: " + ex.StackTrace);
                ExceptionLog.WriteLog(PageName + " @ Page_Load ", ex.Message + " \n " + ex.StackTrace);
                Response.Redirect("login.aspx");
            }
        }
Beispiel #15
0
        public ActionResult GetLoginAccess(string userName, string password)
        {
            User user = webSearchLogInBll.GetUserLogIn(userName, password);

            if (user != null)
            {
                Session["MainModuleId"] = "12";
                Session["UserId"]       = user.UserId;
                Session["UserName"]     = user.EmpCode;
                Session["IsAdmin"]      = user.IsAdmin;
                Session["EMP_CODE"]     = user.EmpCode;
                Session["EMP_ID"]       = user.EmpId;
                Session["DesigEName"]   = user.DesigEName;
                Session["EMP_ENAME"]    = user.EMP_ENAME;
                string mainModuleId = Session["MainModuleId"].ToString();
                Session["MULRID"] = webSearchLogInBll.ModuleUserLogin(Session["UserName"].ToString(), 12, getUserPC(),
                                                                      getUserIP());
                Session["UserImage"] = "/Content/Images/Masco.jpg";
                Session["EmpName"]   = "Admin";
                if (userName.ToUpper() != "ADMIN")
                {
                    Dictionary <string, object> paramList = new Dictionary <string, object>();
                    paramList.Add("@id", user.EmpCode);
                    DataTable dt = Models.DAL.GetDataTable("sp_EmpImageBYUserID", paramList, DBName.HR);
                    if (dt.Rows.Count > 0)
                    {
                        byte[] image = (byte[])dt.Rows[0]["Attachment"];

                        string fileName = System.Web.HttpContext.Current.Request.MapPath("~/Content/EmpImages/") + "emp" +
                                          user.EmpCode + ".jpg";
                        Session["UserImage"] = "/Content/EmpImages/" + "emp" + user.EmpCode + ".jpg";
                        Session["EmpName"]   = dt.Rows[0]["EMP_ENAME"].ToString();
                        try
                        {
                            System.IO.File.WriteAllBytes(fileName, image);
                        }
                        catch (Exception)
                        {
                            //  throw;
                        }
                    }
                }
                Session["UserName"] = user;
                var LoginHistory = new LoginHistory();
                LoginHistory.EMP_CODE = Session["EMP_CODE"].ToString();
                if (webSearchLogInBll.InsertLoginHistory(LoginHistory))
                {
                    return(Json(user == null ? "false" : "true", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json("false", JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json("false", JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #16
0
        public static void DeleteLoginHistory(int loginHistoryId)
        {
            TeachersEntities db = new TeachersEntities();
            LoginHistory     objLoginHistory = db.LoginHistories.Find(loginHistoryId);

            db.LoginHistories.Remove(objLoginHistory);
            db.SaveChanges();
        }
Beispiel #17
0
        public ActionResult DeleteConfirmed(int id)
        {
            LoginHistory loginHistory = db.LoginHistories.Find(id);

            db.LoginHistories.Remove(loginHistory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #18
0
        public void UpdateLoginHistory(LoginHistory loginHistory)
        {
            if (loginHistory == null)
            {
                throw new ArgumentNullException("loginHistory");
            }

            _loginHistoryRepository.Update(loginHistory);
        }
        public void UpdateLogoutDateTime(DomainModel.BusinessObject.User user)
        {
            LoginHistory loginHistory = (from l in _dbx.LoginHistories
                                         where l.userId == user.UserId
                                         select l).OrderByDescending(l => l.Id).FirstOrDefault();

            loginHistory.logoutDateTimeStamp = DateTime.Now;
            _dbx.SaveChanges();
        }
Beispiel #20
0
 public bool CheckLogin(string password)
 {
     if (password.GetHashCode() == Password)
     {
         LoginHistory.Add(DateTime.Now);
         return(true);
     }
     return(false);
 }
        public void UpdateCashValue(DomainModel.BusinessObject.User user, decimal addedCashAmount)
        {
            LoginHistory loginHistory = (from l in _dbx.LoginHistories
                                         where l.userId == user.UserId
                                         select l).OrderByDescending(l => l.Id).FirstOrDefault();

            loginHistory.totalCashAmount += addedCashAmount;
            _dbx.SaveChanges();
        }
 public long InsertHistory(LoginHistory history)
 {
     using (var dba = new BetEXDataContainer())
     {
         dba.AddToLoginHistories(history);
         dba.SaveChanges();
         return(history.ID);
     }
 }
Beispiel #23
0
        public static string GetLoginHistoryItem(RestCommand command, int loginHistoryID)
        {
            LoginHistoryItem loginHistoryItem = LoginHistory.GetLoginHistoryItem(command.LoginUser, loginHistoryID);

            if (loginHistoryItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(loginHistoryItem.GetXml("LoginHistoryItem", true));
        }
Beispiel #24
0
    /// <summary>
    /// Initializes a new instance of the <see cref="LoginHistory"/> class.
    /// </summary>
    /// <param name="history">History.</param>
    public LoginHistory(string history)
    {
        LoginHistory lh = JsonUtility.FromJson <LoginHistory> (history);

        id      = lh.id;
        user_id = lh.user_id;
        ip      = lh.ip;
        browser = lh.browser;
        time    = lh.time;
    }
        public int AddLoginHistory(LoginHistory loginHistory)
        {
            using (DemsifyEntities dataContext = new DemsifyEntities())
            {
                ObjectParameter result = new ObjectParameter("Result", typeof(int));

                dataContext.LoginHistoryAdd(Utility.TrimString(loginHistory.LoginFrom), loginHistory.UserId, Utility.TrimString(loginHistory.AccessToken), result);

                return(Convert.ToInt32(result.Value));
            }
        }
Beispiel #26
0
        public bool InsertLoginHistory(LoginHistory obj)
        {
            var isSaved = false;

            if (obj != null)
            {
                isSaved = webSearchLogInDal.InsertLoginHistory(obj);
            }

            return(isSaved);
        }
        public void AddLoginRecord(DomainModel.BusinessObject.LoginHistory loginHistoryDomain)
        {
            LoginHistory loginHistory = new LoginHistory();

            loginHistory.userId             = loginHistoryDomain.user.UserId;
            loginHistory.username           = loginHistoryDomain.user.username;
            loginHistory.loginDateTimeStamp = DateTime.Now;
            loginHistory.totalCashAmount    = new Decimal(0.0);
            _dbx.LoginHistories.Add(loginHistory);
            _dbx.SaveChanges();
        }
        public bool CheckAccessToken(LoginHistory loginHistory)
        {
            using (DemsifyEntities dataContext = new DemsifyEntities())
            {
                ObjectParameter isValid = new ObjectParameter("IsValid", typeof(int));

                dataContext.AccessTokenCheck(Utility.TrimString(loginHistory.AccessToken), isValid);

                return(Convert.ToBoolean(isValid.Value));
            }
        }
Beispiel #29
0
 public ActionResult Edit([Bind(Include = "Id,EmployeeId,DateTime,IPAddress")] LoginHistory loginHistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(loginHistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "Name", loginHistory.EmployeeId);
     return(View(loginHistory));
 }
Beispiel #30
0
        public void Add(long UserId, int ClientType)
        {
            var loginHistory = new LoginHistory
            {
                UserId     = UserId,
                ClientType = ClientType,
                Time       = DateTime.UtcNow
            };

            context.LoginHistories.Add(loginHistory);
            context.SaveChanges();
        }
        //Added by sanjeet singh

        public void InsertLoginHistory(LoginHistory loginHistory)
        {
            loginHistory.UserPassword   = _encryptionService.EncryptText(loginHistory.UserPassword, KeyValue("encriptionkey"));
            loginHistory.Deactivate     = "N";
            loginHistory.EnteredBy      = 10;
            loginHistory.EntryDate      = DateTime.Now.Date;
            loginHistory.ModifiedBy     = null;
            loginHistory.ModifiedDate   = null;
            loginHistory.DeactivateBy   = null;
            loginHistory.DeactivateDate = null;
            _loginHistoryRepository.Insert(loginHistory);
        }
Beispiel #32
0
        /// <summary>
        /// Method for logging logout time
        /// </summary>
        /// <param name="objLoginLogoutHistory"></param>
        /// <returns></returns>
        public bool LogLogoutTime(LoginHistory objLoginLogoutHistory)
        {
            bool result = false;
            try
            {
                SqlCommand objSqlCommand = new SqlCommand();

                SqlParameter[] objLstParams = new SqlParameter[6];

                SqlParameter objuserId = new SqlParameter("@userId", SqlDbType.Int);
                objuserId.Value = objLoginLogoutHistory.UserId;
                objLstParams[0] = objuserId;

                SqlParameter objLogoutTime = new SqlParameter("@LogoutTime", SqlDbType.DateTime);
                objLogoutTime.Value = objLoginLogoutHistory.LogoutTime;
                objLstParams[1] = objLogoutTime;

                SqlParameter objUpdatedBy = new SqlParameter("@UpdatedBy", SqlDbType.Int);
                objUpdatedBy.Value = objLoginLogoutHistory.UpdatedBy;
                objLstParams[2] = objUpdatedBy;

                SqlParameter objUpdatedOn = new SqlParameter("@UpdatedOn", SqlDbType.DateTime);
                objUpdatedOn.Value = objLoginLogoutHistory.UpdatedOn;
                objLstParams[3] = objUpdatedOn;

                SqlParameter objUpdatedIp = new SqlParameter("@UpdatedIp", SqlDbType.NVarChar);
                objUpdatedIp.Value = objLoginLogoutHistory.UpdatedIp;
                objLstParams[4] = objUpdatedIp;

                SqlParameter objUserName = new SqlParameter("@UserName", SqlDbType.VarChar);
                objUserName.Value = objLoginLogoutHistory.UserName;
                objLstParams[5] = objUserName;

                result = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.StoredProcedure, SP_LogLogoutTime, objLstParams));
                objSqlCommand.Parameters.Clear();
            }
            catch (Exception ex)
            {
                log.Error("LogLogoutTime \n Message: " + ex.Message + "\n Source: " + ex.Source + "\n StackTrace: " + ex.StackTrace);
                ExceptionLog.WriteLog(COMMONDATA + " @ LogLogoutTime ", ex.Message + " \n " + ex.StackTrace);
            }
            return result;
        }
Beispiel #33
0
 /// <summary>
 ///  Method for logging logout time
 /// </summary>
 /// <param name="objLoginLogoutHistory"></param>
 /// <returns></returns>
 public bool LogLogoutTime(LoginHistory objLoginLogoutHistory)
 {
     return objUserDAL.LogLogoutTime(objLoginLogoutHistory);
 }
Beispiel #34
0
        private void LoadLoginHistory(Dictionary<string, LoginHistory> loginHistory)
        {
            this.m_loginHistory = loginHistory;
            this.cboUser.Text = string.Empty;
            this.cboUser.Items.Clear();

            if (m_loginHistory.Keys.Count > 0)
            {
                LoginHistory[] array = new LoginHistory[m_loginHistory.Count];
                m_loginHistory.Values.CopyTo(array, 0);
                Array.Sort<LoginHistory>(array, new DynamicComparer<LoginHistory>("LastLoginDate desc"));

                foreach (LoginHistory var in array)
                {
                    this.cboUser.Items.Add(var.Username);
                }
                this.cboUser.SelectedIndex = 0;
                this.txtPwd.Text = array[0].Password;
            }
        }
Beispiel #35
0
        /// <summary>
        /// Method for getting login history
        /// </summary>
        /// <param name="searchUser"></param>
        /// <returns></returns>
        public List<LoginHistory> GetLoginHistory(string searchUser)
        {
            List<LoginHistory> objLstLoginHistory = new List<LoginHistory>();
            try
            {
                SqlCommand sqlCommand = new SqlCommand();
                using (DataSet objUserDataSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionString, CommandType.StoredProcedure, SP_GetLoginHistory, new SqlParameter("@SearchUser", searchUser == string.Empty ? null : searchUser)))
                {
                    if (objUserDataSet.Tables[0].Rows.Count > 0)
                    {

                        for (int i = 0; i < objUserDataSet.Tables[0].Rows.Count; i++)
                        {
                            LoginHistory objLoginHistory = new LoginHistory();

                            if (!string.IsNullOrWhiteSpace(Convert.ToString(objUserDataSet.Tables[0].Rows[i]["LoginTime"])))
                            {
                                objLoginHistory.LoginTime = Convert.ToDateTime(objUserDataSet.Tables[0].Rows[i]["LoginTime"]);
                            }

                            if (!string.IsNullOrWhiteSpace(Convert.ToString(objUserDataSet.Tables[0].Rows[i]["LogoutTime"])))
                            {
                                objLoginHistory.LogoutTime = Convert.ToDateTime(objUserDataSet.Tables[0].Rows[i]["LogoutTime"]);
                            }
                            else
                            {
                                objLoginHistory.LogoutTime = null;
                            }

                            if (!string.IsNullOrWhiteSpace(Convert.ToString(objUserDataSet.Tables[0].Rows[i]["CreatedIp"])))
                            {
                                objLoginHistory.CreatedIp = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["CreatedIp"]);
                            }
                            else
                            {
                                objLoginHistory.CreatedIp = null;
                            }

                            if (!string.IsNullOrWhiteSpace(Convert.ToString(objUserDataSet.Tables[0].Rows[i]["UpdatedIp"])))
                            {
                                objLoginHistory.UpdatedIp = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["UpdatedIp"]);
                            }
                            else
                            {
                                objLoginHistory.UpdatedIp = null;
                            }
                            objLoginHistory.UserName = Convert.ToString(objUserDataSet.Tables[0].Rows[i]["UserName"]);

                            objLstLoginHistory.Add(objLoginHistory);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("getLoginHistory \n Message: " + ex.Message + "\n Source: " + ex.Source + "\n StackTrace: " + ex.StackTrace);
                ExceptionLog.WriteLog(COMMONDATA + " @ getLoginHistory ", ex.Message + " \n " + ex.StackTrace);
            }
            return objLstLoginHistory;
        }