Example #1
0
        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));
        }