Ejemplo n.º 1
0
        private void SaveLoginHistory(Models.User user)
        {
            LoginTime = $"{Infrastructure.Utility.PersianCalendar(System.DateTime.Now).ToString()} " +
                        $"{Infrastructure.Utility.ShowTime().ToString()}";

            LogOutTime = $"Null";

            string fullName;

            Models.DataBaseContext dataBaseContext = null;
            try
            {
                if (string.IsNullOrWhiteSpace(user.First_Name) && string.IsNullOrWhiteSpace(user.Last_Name))
                {
                    fullName = "Null";
                }
                else
                {
                    fullName = $"{user.First_Name} {user.First_Name}";
                }

                dataBaseContext =
                    new Models.DataBaseContext();
                Models.LogHistory logHistory =
                    dataBaseContext.LogHistories
                    .OrderBy(current => current.LoginTime)
                    .FirstOrDefault();

                logHistory =
                    new Models.LogHistory
                {
                    FullName    = fullName,
                    Username    = user.Username,
                    UserPicture = user.User_Image,
                    LoginTime   = LoginTime,
                    LogoutTime  = LogOutTime,
                };

                dataBaseContext.LogHistories.Add(logHistory);
                dataBaseContext.SaveChanges();

                Program.AutenticatLogHistory = logHistory;
            }
            catch (System.Exception ex)
            {
                Infrastructure.Utility.PopupNotification(ex);
            }
            if (dataBaseContext != null)
            {
                dataBaseContext.Dispose();
                dataBaseContext = null;
            }
        }
Ejemplo n.º 2
0
        private void SaveLogOutTime(Models.LogHistory log)
        {
            Models.DataBaseContext dataBaseContext = null;
            try
            {
                dataBaseContext =
                    new Models.DataBaseContext();

                Models.LogHistory logHistory =
                    dataBaseContext.LogHistories
                    .Where(curren => string.Compare(curren.Username, log.Username) == 0)
                    .OrderByDescending(current => current.LoginTime)
                    .SingleOrDefault(current => current.Id == log.Id);

                if (logHistory != null)
                {
                    LogOutTime = $"{Infrastructure.Utility.PersianCalendar(System.DateTime.Now).ToString()} " +
                                 $"{Infrastructure.Utility.ShowTime().ToString()}";

                    logHistory.LogoutTime = LogOutTime;
                }

                dataBaseContext.SaveChanges();
            }
            catch (System.Exception ex)
            {
                Infrastructure.Utility.PopupNotification(ex);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }