private async Task UpdateCachedOpenShiftsAsync(string scheduleId, ShiftModel assignedOpenShift, DateTime weekStartDate) { var schedule = await _scheduleCacheService.LoadScheduleWithLeaseAsync(scheduleId, weekStartDate, new TimeSpan(0, 0, _teamOptions.StorageLeaseTimeSeconds)).ConfigureAwait(false); var shift = schedule.Tracked.FirstOrDefault(s => s.WfmShiftId == assignedOpenShift.WfmShiftId); // update the quantity shift.Quantity = assignedOpenShift.Quantity; if (shift.Quantity <= 0) { schedule.Tracked.Remove(shift); } await _scheduleCacheService.SaveScheduleWithLeaseAsync(scheduleId, weekStartDate, schedule).ConfigureAwait(false); }
private async Task RemoveShiftFromScheduleAsync(ShiftModel shift, string teamId) { var weekStartDate = shift.StartDate.StartOfWeek(_teamOptions.StartDayOfWeek); var cacheModel = await _scheduleCacheService.LoadScheduleWithLeaseAsync(teamId, weekStartDate, new TimeSpan(0, 0, _teamOptions.StorageLeaseTimeSeconds)).ConfigureAwait(false); cacheModel.Tracked.RemoveAll(s => s.TeamsShiftId.Equals(shift.TeamsShiftId, StringComparison.OrdinalIgnoreCase)); await _scheduleCacheService.SaveScheduleWithLeaseAsync(teamId, weekStartDate, cacheModel).ConfigureAwait(false); }
private async Task UpdateScheduleAsync(TeamActivityModel activityModel, DeltaModel <ShiftModel> delta) { // apply the final delta to the current version of the savedShifts ensuring that no // other process can update it while we do so - N.B. the minimum lease time is 15s, the // maximum lease time is 1m var savedShifts = await _scheduleCacheService.LoadScheduleWithLeaseAsync(GetSaveScheduleId(activityModel.TeamId), activityModel.StartDate, new TimeSpan(0, 0, _options.StorageLeaseTimeSeconds)); delta.ApplyChanges(savedShifts.Tracked); delta.ApplySkipped(savedShifts.Skipped); await _scheduleCacheService.SaveScheduleWithLeaseAsync(GetSaveScheduleId(activityModel.TeamId), activityModel.StartDate, savedShifts); }