Example #1
0
        public async Task <ActionResult <List <ShiftAvailabilityDto> > > GetAvailability(int locationId, DateTimeOffset start, DateTimeOffset end)
        {
            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());
            }

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

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

                var timezone        = location.Timezone;
                var restrictionDays = int.Parse(Configuration.GetNonEmptyValue("ViewShiftRestrictionDays"));
                var currentDate     = DateTimeOffset.UtcNow.ConvertToTimezone(timezone).DateOnly();
                var endDate         = currentDate.TranslateDateForDaylightSavings(timezone, restrictionDays + 1);
                foreach (var sa in shiftAvailability)
                {
                    sa.Conflicts = sa.Conflicts.WhereToList(c => c.Start < endDate);
                }
            }

            return(Ok(shiftAvailability.Adapt <List <ShiftAvailabilityDto> >()));
        }
Example #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> >()));
        }
        public async Task <ActionResult <List <ShiftAvailabilityDto> > > GetAvailability(int locationId, DateTimeOffset start, DateTimeOffset end)
        {
            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);

            return(Ok(shiftAvailability.Adapt <List <ShiftAvailabilityDto> >()));
        }
Example #4
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));
        }