Example #1
0
        public async Task <List <WorkHourDto> > GetReport2(int scheduleId, string userId)
        {
            var schedule = await context.Schedules.Include(x => x.WorkUnits).SingleOrDefaultAsync(x => x.Id == scheduleId);

            var workHours = new List <WorkHourDto>();
            var workUnits = schedule.WorkUnits.Where(x => x.Start >= schedule.StartOfWorkingTime && x.End <= schedule.EndOfWorkingTime).ToList();

            for (int i = schedule.StartOfWorkingTime.Hours; i < schedule.EndOfWorkingTime.Hours; i++)
            {
                var start    = new TimeSpan(i, 0, 0);
                var end      = new TimeSpan(i + 1, 0, 0);
                var workHour = new WorkHourDto {
                    Start = start, End = end
                };
                foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek)))
                {
                    var quantity = workUnits
                                   .Where(x => ((x.Start <start && x.End> start) || x.Start >= start && x.Start < end) && x.DayOfWeek == day)
                                   .GroupBy(x => x.MemberId)
                                   .Select(x => x.First())
                                   .Count();
                    switch (day)
                    {
                    case DayOfWeek.Sunday:
                        workHour.QuantityForSunday = quantity;
                        break;

                    case DayOfWeek.Monday:
                        workHour.QuantityForMonday = quantity;
                        break;

                    case DayOfWeek.Tuesday:
                        workHour.QuantityForTuesday = quantity;
                        break;

                    case DayOfWeek.Wednesday:
                        workHour.QuantityForWednesday = quantity;
                        break;

                    case DayOfWeek.Thursday:
                        workHour.QuantityForThursday = quantity;
                        break;

                    case DayOfWeek.Friday:
                        workHour.QuantityForFriday = quantity;
                        break;

                    case DayOfWeek.Saturday:
                        workHour.QuantityForSaturday = quantity;
                        break;
                    }
                }

                workHours.Add(workHour);
            }

            return(workHours);
        }
Example #2
0
        public int GetWorkHours(WorkHourDto workHourDto)
        {
            var timesheets = this.timesheetRepository.RetrieveTimesheets(workHourDto);

            if (timesheets.Any())
            {
                return(timesheets.Select(t => t.Duration).Sum());
            }

            return(0);
        }
Example #3
0
 public IActionResult GetWorkHours(WorkHourDto workHourDto)
 {
     if (ModelState.IsValid)
     {
         var hours = this.timesheetService.GetWorkHours(workHourDto);
         return(Ok(hours));
     }
     else
     {
         return(BadRequest());
     }
 }
Example #4
0
 public IEnumerable <Timesheet> RetrieveTimesheets(WorkHourDto workHourDto)
 {
     return(base.GetList(p => p.People.Id == workHourDto.PeopleId && p.Date >= workHourDto.StartDate && p.Date <= workHourDto.EndDate));
 }
Example #5
0
 public int GetWorkHours(WorkHourDto workHourDto)
 {
     throw new System.NotImplementedException();
 }