Exemplo n.º 1
0
 public static WeekDTO CreateForWeekId(int weekId)
 {
     return(weeksByWeekId.GetOrAdd(weekId, (id) =>
     {
         var candidate = new WeekDTO(WeekEpoch);
         var candidateWeekId = 0;
         while (candidateWeekId != weekId)
         {
             candidate = candidate.Next();
             ++candidateWeekId;
         }
         return candidate;
     }));
 }
Exemplo n.º 2
0
 private int GetWeekId()
 {
     return(weekIdsByWeek.GetOrAdd(this, (week) =>
     {
         var candidate = new WeekDTO(WeekEpoch);
         var weekId = 0;
         while (candidate != this)
         {
             candidate = candidate.Next();
             ++weekId;
         }
         return weekId;
     }));
 }
Exemplo n.º 3
0
        public async Task <WeekListViewModel> GetWeeksAsync(int entriesToShow, int employeeId, DateTime?startDate = null)
        {
            var dt       = DateTime.Now;
            var thisWeek = WeekDTO.CreateWithWeekContaining(startDate ?? DateTime.Now);
            var currWeek = WeekDTO.CreateWithWeekContaining(DateTime.Now).WeekId.Value;
            var weeks    = new List <DetailedWeekIdentifier>();

            while (entriesToShow-- > 0)
            {
                var temp = thisWeek;
                var thisWeekTimeSummary = await timeSummaryService.GetAsync(temp.WeekId.Value, employeeId);

                weeks.Add(new DetailedWeekIdentifier()
                {
                    WeekEnd        = thisWeek.WeekEnd,   //weekService.GetWeekDate(temp.Year, temp.WeekId, WeekIdentifier.WEEK_END),
                    WeekStart      = thisWeek.WeekStart, //weekService.GetWeekDate(temp.Year, temp.WeekId, WeekIdentifier.WEEK_START),
                    WeekId         = temp.WeekId.Value,
                    Year           = temp.Year,
                    ApprovalStatus = thisWeekTimeSummary.ApprovalStatus,
                    TotalOverTime  = thisWeekTimeSummary.OvertimeHours,
                    TotalRegular   = thisWeekTimeSummary.Hours,
                    IsCurrentWeek  = currWeek == temp.WeekId.Value
                });
                thisWeek = thisWeek.Previous();// weekService.Previous(thisWeek.Year, thisWeek.WeekId);
            }
            var user = await _employeeRepository.GetSingleEmployeeAsync(employeeId);

            var name = string.Empty;

            if (user != null)
            {
                name = $"{user.First} {user.Last}";
            }
            return(new WeekListViewModel()
            {
                Weeks = weeks,
                EmployeeId = employeeId,
                EmployeeDisplayName = name,
                WeeksToShow = entriesToShow,
                StartWithDate = startDate ?? DateTime.Now
            });
        }
Exemplo n.º 4
0
        public async Task <TimeApprovalList> GetApprovalListAsync(DateTime?beginDate = null, DateTime?endDate = null)
        {
            var thisWeek = WeekDTO.CreateWithWeekContaining(endDate ?? DateTime.Now);

            beginDate = beginDate ?? thisWeek.Previous().Previous().WeekStart;
            endDate   = endDate ?? thisWeek.WeekEnd;
            var entries = (await timeApprovalService.GetByStatus(beginDate, endDate,
                                                                 TimeApprovalStatus.Approved,
                                                                 TimeApprovalStatus.Rejected,
                                                                 TimeApprovalStatus.Submitted,
                                                                 TimeApprovalStatus.Unkown)).ToList();

            var allEmployees = await employeeService.GetAllEmployees();

            allEmployees = allEmployees.Where(x => x.UserName != "*****@*****.**").ToList();
            var next     = WeekDTO.CreateWithWeekContaining(beginDate.Value);
            var end      = WeekDTO.CreateWithWeekContaining(endDate.Value);
            var allWeeks = new List <WeekDTO>()
            {
                end
            };

            while (next != end)
            {
                allWeeks.Add(next);
                next = next.Next();
            }

            var missing = new List <(EmployeeDTO emp, WeekDTO week)>();

            foreach (var wk in allWeeks)
            {
                foreach (var emp in allEmployees)
                {
                    if (!entries.Any(x => x.EmployeeId == emp.EmployeeId && x.WeekId == wk.WeekId.Value && x.TimeApprovalStatus != TimeApprovalStatus.Unkown))
                    {
                        missing.Add((emp, wk));
                    }
                }
            }
            var allMissing = (from p in missing
                              join c in entries.Where(x => x.TimeApprovalStatus == TimeApprovalStatus.Unkown).ToList()
                              on new { p.emp.EmployeeId, WeekId = p.week.WeekId.Value } equals new { c.EmployeeId, c.WeekId } into ps
                              from x in ps.DefaultIfEmpty()
                              select
                              new TimeApprovalDTO()
            {
                EmployeeId = p.emp.EmployeeId,
                EmployeeName = $"{p.emp.Last}, {p.emp.First}",
                TimeApprovalStatus = TimeApprovalStatus.Unkown,
                WeekId = p.week.WeekId.Value,
                WeekStartDate = p.week.WeekStart,
                TotalOverTimeHours = x == null ? 0.00m : x.TotalOverTimeHours,
                TotalRegularHours = x == null ? 0.00m : x.TotalRegularHours,
                IsHidden = x == null ? false : x.IsHidden
            }).ToList();

            return(new TimeApprovalList()
            {
                PeriodEndDate = endDate.Value,
                PeriodStartData = beginDate.Value,
                ApprovedEntries = entries.Where(x => x.TimeApprovalStatus == TimeApprovalStatus.Approved && !x.IsHidden),
                RejectedEntries = entries.Where(x => x.TimeApprovalStatus == TimeApprovalStatus.Rejected && !x.IsHidden),
                SubmittedEntries = entries.Where(x => x.TimeApprovalStatus == TimeApprovalStatus.Submitted && !x.IsHidden),
                MissingEntries = allMissing.Where(x => !x.IsHidden).OrderBy(x => x.WeekId).ToList(),
                HiddenEntries = entries.Where(x => x.IsHidden).ToList()
            });
        }
Exemplo n.º 5
0
 public bool Equals(WeekDTO obj)
 {
     return(obj != null &&
            obj.WeekStart.Date == WeekStart.Date);
 }