Esempio n. 1
0
 public async Task <JsonResult> GroupSchedule(GroupScheduleVM vm)
 {
     try {
         var list = _attendanceService.GetAll().Result.ToList();
         list = AttendanceUtility.FilterByCompanyID(CurrentUser.CompanyID, list);
         list = AttendanceUtility.FilterByDateFromTo(vm.from, vm.to, list);
         for (var date = vm.from; date.Date <= vm.to.Date; date = date.AddDays(1))
         {
             if (DayUtility.IsSelected((int)date.DayOfWeek, vm.Week))
             {
                 foreach (UsersViewModel user in vm.Users)
                 {
                     if (!AttendanceUtility.IsScheduleAlreadyExist(AttendanceUtility.FilterByUserID(user.ID, list, false), date))
                     {
                         var model = new Attendance()
                         {
                             ID                 = Guid.NewGuid().ToString(),
                             UserID             = user.ID,
                             AttendanceStatusID = "10",
                             AttendanceDate     = date,
                             TimeIn             = null,
                             TimeOut            = null,
                             ShiftID            = vm.shiftID,
                             AddOnID            = null,
                             CreatedAt          = GetCurrentTime(),
                             CreatedBy          = CurrentUser.ID
                         };
                         _attendanceService.Insert(model);
                     }
                 }
             }
         }
         return(Json(new { success = true }));
     } catch { return(Json(new { success = false })); }
 }
Esempio n. 2
0
        public async Task <long> CalcBusinessDaysAsync(DateTime startDate, DateTime endDate)
        {
            var holidays = await _holidayRepository.ListAsync();

            // var workingDays = DayUtility.CalcWorkingDaysBetween(startDate, endDate);
            var workingDays = DayUtility.CalcWorkingDaysBetweenLinear(startDate, endDate);

            for (var year = startDate.Year; year <= endDate.Year; year++)
            {
                workingDays = holidays.Aggregate(workingDays, (current, holiday) => current - DayUtility.HolidayOverlapsWorkingDay(holiday, startDate, endDate, year));
            }

            return(workingDays);
        }
Esempio n. 3
0
        public void CalcWorkingDaysBetweenLinearTests(DateTime startDate, DateTime endDate, long workingDays)
        {
            var result = DayUtility.CalcWorkingDaysBetweenLinear(startDate, endDate);

            Assert.AreEqual(workingDays, result);
        }