Пример #1
0
 public DistributeScheduleController(DistributeScheduleService distributeSchedule, ShiftService shiftService, SheriffDbContext db, IConfiguration configuration)
 {
     DistributeScheduleService = distributeSchedule;
     ShiftService  = shiftService;
     Db            = db;
     Configuration = configuration;
 }
Пример #2
0
        public async Task <ActionResult <List <ShiftAvailabilityDto> > > GetDistributeScheduleForLocation(int locationId, DateTimeOffset start, DateTimeOffset end, bool includeWorkSection)
        {
            if (start >= end)
            {
                return(BadRequest("Start date was on or after end date."));
            }
            if (end.Subtract(start).TotalDays > 30)
            {
                return(BadRequest("End date and start date are more than 30 days apart."));
            }
            if (!PermissionDataFiltersExtensions.HasAccessToLocation(User, Db, locationId))
            {
                return(Forbid());
            }
            if (!User.HasPermission(Permission.ViewDutyRoster))
            {
                includeWorkSection = false;
            }

            var shiftAvailability = await ShiftService.GetShiftAvailability(start, end, locationId : locationId);

            var shiftsWithDuties = await DistributeScheduleService.GetDistributeSchedule(shiftAvailability, includeWorkSection, start, end, locationId);

            if (!User.HasPermission(Permission.ViewAllFutureShifts) ||
                !User.HasPermission(Permission.ViewDutyRosterInFuture))
            {
                var location = await Db.Location.AsNoTracking().FirstOrDefaultAsync(l => l.Id == locationId);

                var timezone    = location.Timezone;
                var currentDate = DateTimeOffset.UtcNow.ConvertToTimezone(timezone).DateOnly();

                if (!User.HasPermission(Permission.ViewAllFutureShifts))
                {
                    var shiftRestrictionDays = int.Parse(Configuration.GetNonEmptyValue("ViewShiftRestrictionDays"));
                    var endDateShift         = currentDate.TranslateDateForDaylightSavings(timezone, shiftRestrictionDays + 1);
                    foreach (var sa in shiftsWithDuties)
                    {
                        sa.Conflicts = sa.Conflicts.WhereToList(c => c.Start < endDateShift);
                    }
                }

                if (!User.HasPermission(Permission.ViewDutyRosterInFuture))
                {
                    var dutyRestrictionHours =
                        float.Parse(Configuration.GetNonEmptyValue("ViewDutyRosterRestrictionHours"));
                    var endDateDuties =
                        currentDate.TranslateDateForDaylightSavings(timezone, hoursToShift: dutyRestrictionHours);
                    foreach (var sa in shiftsWithDuties)
                    {
                        sa.Conflicts.WhereToList(c => c.Start > endDateDuties)
                        .ForEach(c => c.WorkSection = null);
                    }
                }
            }

            return(Ok(shiftsWithDuties.Adapt <List <ShiftAvailabilityDto> >()));
        }
Пример #3
0
        public async Task <ActionResult <ShiftDto> > GetDistributeSchedule(DateTimeOffset start, DateTimeOffset end, int locationId, bool includeWorkSection)
        {
            if (start >= end)
            {
                throw new BusinessLayerException("Start date was on or after end date.");
            }
            if (end.Subtract(start).TotalDays > 30)
            {
                throw new BusinessLayerException("End date and start date are more than 30 days apart.");
            }

            if (!PermissionDataFiltersExtensions.HasAccessToLocation(User, Db, locationId))
            {
                return(Forbid());
            }

            var shiftAvailability = await ShiftService.GetShiftAvailability(locationId, start, end);

            var shiftsWithDuties = await DistributeScheduleService.GetDistributeSchedule(shiftAvailability, includeWorkSection);

            return(Ok(shiftsWithDuties));
        }
Пример #4
0
 public DistributeScheduleController(DistributeScheduleService distributeSchedule, ShiftService shiftService, SheriffDbContext db)
 {
     DistributeScheduleService = distributeSchedule;
     ShiftService = shiftService;
     Db           = db;
 }