public async Task <ActionResult <List <DutyDto> > > GetDuties(int locationId, DateTimeOffset start, DateTimeOffset end) { if (!PermissionDataFiltersExtensions.HasAccessToLocation(User, Db, locationId)) { return(Forbid()); } var duties = await DutyRosterService.GetDutiesForLocation(locationId, start, end); return(Ok(duties.Adapt <List <DutyDto> >())); }
public async Task <ActionResult <List <DutyDto> > > GetDuties(int locationId, DateTimeOffset start, DateTimeOffset end) { if (!PermissionDataFiltersExtensions.HasAccessToLocation(User, Db, locationId)) { return(Forbid()); } var duties = await DutyRosterService.GetDutiesForLocation(locationId, start, end); if (!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(); var restrictionHours = float.Parse(Configuration.GetNonEmptyValue("ViewDutyRosterRestrictionHours")); var endDate = currentDate.TranslateDateForDaylightSavings(timezone, hoursToShift: restrictionHours); duties = duties.WhereToList(d => d.StartDate < endDate); } return(Ok(duties.Adapt <List <DutyDto> >())); }