public List <UserRecordViewModel> GetAllUsers()
        {
            List <ApplicationUser>     users = _appUserService.GetAllUsers().Where(x => (DateTime.Now - x.CreatedDate).TotalDays <= 14).OrderByDescending(x => x.CreatedDate).ToList();
            List <UserRecordViewModel> rez   = new List <UserRecordViewModel>();

            foreach (var user in users)
            {
                UserRecordViewModel usr = new UserRecordViewModel(user.Id, _appUserService.DetermineUserRole(user.Id), user.Email, user.FirstName, user.LastName, user.BirthDate, user.Title, user.CabinetAddress, user.PhoneNumber, user.ActiveAccount, user.CreatedDate);
                rez.Add(usr);
            }
            return(rez);
        }
示例#2
0
        public UserRecordDialog(ITableEntry record)
        {
            InitializeComponent();
            if (record is User user)
            {
                DataContext = new UserRecordViewModel(user, this);
            }

            ((UserRecordViewModel)DataContext).MessageBoxDisplayRequested += (sender, e) =>
            {
                CustomMessageBox.Show(e.Title, e.Text);
            };
        }
        public async Task <List <UserRecordViewModel> > CreateUserRecordsModel(DateTime startDate, DateTime endDate)
        {
            //current user
            var currentUser = await _userManager.GetUserAsync(HttpContext.User);

            //Initialize List of UserRecordViewModel
            var listOfUserRecordViewModel = new List <UserRecordViewModel>();

            //Get All Records of current user in period "startDate to endDate"
            var recordsListOfCurrentUser =
                await _context.DayRecords.Where(c => c.UserId == currentUser.Id && c.Data.Date >= startDate && c.Data.Date <= endDate).OrderByDescending(c => c.Data).ToListAsync();

            //create list of UserRecordViewModel
            foreach (var record in recordsListOfCurrentUser)
            {
                //if User forget to stop timer and db.TimeRecords EndTime is NULL
                //Date < Today
                //Normalize Record: set start and end day = user StartWorkTime and EndWorkTime and StartLunchTime and EndLunchTime

                if (record.Data.Date < DateTime.Now.Date)
                {
                    //check if exist TimeRecord with EndTime = null
                    var IsOneRecordNotClosed = CheckIfOneRecordNotClosed(record.Id);
                    if (IsOneRecordNotClosed)
                    {
                        SetNormalizeTimetableInTimerLost(record);
                    }
                }

                //create and initialize UserRecordViewModel
                var userRecord = new UserRecordViewModel()
                {
                    Data                     = record.Data,
                    DayStartTime             = await GetDateStartTime(record.Id),
                    DayEndTime               = await GetDateEndTime(record.Id),
                    IntervalsList            = await GetIntervalsList(record.Id),
                    StartDayDelayExplanation = record.StartDayDelayExplanation,
                    EndDayDelayExplanation   = record.EndDayDelayExplanation
                };

                //if do not exist yet DayEndTime - do not show in table
                if (userRecord.DayEndTime != null)
                {
                    //Add TotalHoursPorDay
                    var TotalHoursPorDay = (TimeSpan)GetTotalWorkHoursPorDay(record.Id);
                    userRecord.TotalHoursPorDay = TotalHoursPorDay.ToString("hh\\:mm\\:ss");

                    //Add Delay flags values
                    //if Today
                    if (userRecord.Data.Date == DateTime.Now.Date)
                    {
                        userRecord.StartDayDelayFlag = userRecord.DayStartTime.TimeOfDay > currentUser.StartWorkTime.Value.AddMinutes(5).TimeOfDay ? true : false;
                        userRecord.EndDayDelayFlag   = userRecord.DayEndTime.Value.AddMinutes(5).TimeOfDay < currentUser.EndWorkTime.Value.TimeOfDay && DateTime.Now.TimeOfDay >= currentUser.EndWorkTime.Value.TimeOfDay ? true : false;
                    }
                    //if more then one day - show explanation and edit button
                    else
                    {
                        userRecord.StartDayDelayFlag = userRecord.DayStartTime.TimeOfDay > currentUser.StartWorkTime.Value.AddMinutes(5).TimeOfDay ? true : false;
                        userRecord.EndDayDelayFlag   = userRecord.DayEndTime.Value.AddMinutes(5).TimeOfDay < currentUser.EndWorkTime.Value.TimeOfDay ? true : false;
                    }
                    listOfUserRecordViewModel.Add(userRecord);
                }
            }

            //return list of UserRecordViewModel
            return(listOfUserRecordViewModel);
        }