public async Task <IActionResult> GetPerformerDaySchedule(int performerId, DateTime date) { var performerSchedule = await _performerSchedulingService .GetPerformerDateScheduleAsync(performerId, date.Date); var branchSelections = (await _performerSchedulingService .GetPerformerBranchSelectionsAsync(performerId, date)).ToList(); var viewModel = new DayScheduleViewModel { BranchSelections = branchSelections }; var startTime = performerSchedule?.StartTime ?? DefaultPerformerScheduleStartTime; var endTime = performerSchedule?.EndTime ?? DefaultPerformerScheduleEndTime; var earliestSelection = branchSelections .OrderBy(_ => _.ScheduleStartTime) .FirstOrDefault(); var latestSelection = branchSelections .OrderByDescending(_ => _.ScheduleStartTime) .FirstOrDefault(); if (earliestSelection == null || startTime.TimeOfDay < earliestSelection.ScheduleStartTime.TimeOfDay) { viewModel.StartTime = startTime.ToShortTimeString(); } if (latestSelection == null || endTime.TimeOfDay > latestSelection.ScheduleStartTime .AddMinutes(latestSelection.ScheduleDuration).TimeOfDay) { viewModel.EndTime = endTime.ToShortTimeString(); } return(PartialView("_DaySchedulePartial", viewModel)); }
public async Task <IActionResult> SelectProgram(ProgramViewModel model) { var settings = await _performerSchedulingService.GetSettingsAsync(); var schedulingStage = _performerSchedulingService.GetSchedulingStage(settings); if (schedulingStage != PsSchedulingStage.SchedulingOpen) { return(RedirectToAction(nameof(Index))); } PsProgram program; try { program = await _performerSchedulingService.GetProgramByIdAsync( model.BranchSelection.ProgramId.Value, onlyApproved : true); } catch (GraException gex) { ShowAlertDanger("Unable to select program: ", gex); return(RedirectToAction(nameof(Programs))); } var ageAlreadySelected = await _performerSchedulingService .BranchAgeGroupAlreadySelectedAsync(model.BranchSelection.AgeGroupId, model.BranchSelection.BranchId); if (ageAlreadySelected) { ShowAlertDanger("Branch already has a selection for that age group."); return(RedirectToAction(nameof(Program), new { id = program.Id })); } var programAvailableAtBranch = await _performerSchedulingService .ProgramAvailableAtBranchAsync(model.BranchSelection.ProgramId.Value, model.BranchSelection.BranchId); if (!programAvailableAtBranch) { ShowAlertDanger("The performer does not performer at that branch."); return(RedirectToAction(nameof(Program), new { id = program.Id })); } var viewModel = new SelectProgramViewModel { BranchSelection = model.BranchSelection, BlackoutDates = await _performerSchedulingService.GetBlackoutDatesAsync(), ScheduleDates = await _performerSchedulingService.GetPerformerScheduleAsync( program.PerformerId), BookedDates = (await _performerSchedulingService .GetPerformerBranchSelectionsAsync(program.PerformerId)) .Select(_ => _.RequestedStartTime), Settings = settings }; if (await _performerSchedulingService.BranchAgeGroupHasBackToBackAsync( model.BranchSelection.AgeGroupId, model.BranchSelection.BranchId)) { viewModel.BranchSelection.BackToBackProgram = true; } viewModel.BranchSelection.AgeGroup = await _performerSchedulingService .GetAgeGroupByIdAsync(viewModel.BranchSelection.AgeGroupId); viewModel.BranchSelection.Branch = await _performerSchedulingService .GetNonExcludedBranch(model.BranchSelection.BranchId); viewModel.BranchSelection.Program = program; return(View(viewModel)); }