Exemplo n.º 1
0
        public ViewResult ManageWorkDay(long serviceId, long chosenDateInTicks)
        {
            var context = _serviceProvider.GetRequiredService <AppointmentJournalContext>();

            var chosenDate = new DateTime(chosenDateInTicks);

            var service = context.Services
                          .Include(x => x.WorkDaysTimeSpans)
                          .ThenInclude(x => x.WorkDay)
                          .Include(x => x.WorkDaysTimeSpans)
                          .ThenInclude(x => x.Address)
                          .Include(x => x.Appointments).SingleOrDefault(s => s.Id == serviceId);

            var timeSpansForChosenDay = service.WorkDaysTimeSpans.Where(ts => ts.WorkDay.Date.Date == chosenDate.Date.Date).ToList();

            WorkDay workDay = null;

            if (timeSpansForChosenDay.Count != 0)
            {
                workDay = timeSpansForChosenDay.GroupBy(x => x.WorkDay).SingleOrDefault()?.Key;

                if (workDay == null)
                {
                    throw new Exception("workDay = null");
                }
            }

            var appointmentAvailableTimeList = DateTimePicker.CreateAppointmentAvailableTimeList(service.Duration, timeSpansForChosenDay);

            var chooseTimeViewModel = new ManageWorkDayViewModel()
            {
                AppointmentTimesList = appointmentAvailableTimeList,
                ServiceId            = serviceId,
                ChosenDate           = chosenDate,
                WorkDay = workDay
            };

            return(View(chooseTimeViewModel));
        }
        /// <summary>
        ///  Метод для выбора времени записи
        /// </summary>
        /// <param name="serviceId">ID услуги</param>
        /// <param name="chosenDate">Выбранная дата</param>
        /// <returns></returns>
        public ViewResult ChooseTime(long serviceId, DateTime chosenDate)
        {
            var context = _serviceProvider.GetRequiredService <AppointmentJournalContext>();

            var service = context.Services
                          .Include(x => x.WorkDaysTimeSpans)
                          .ThenInclude(x => x.WorkDay)
                          .Include(x => x.WorkDaysTimeSpans)
                          .ThenInclude(x => x.Address)
                          .Include(x => x.Appointments).SingleOrDefault(s => s.Id == serviceId);

            var timeSpansForChosenDay = service.WorkDaysTimeSpans.Where(ts => ts.WorkDay.Date.Date == chosenDate.Date.Date).ToList();

            var appointmentAvailableTimeList = DateTimePicker.CreateAppointmentAvailableTimeList(service.Duration, timeSpansForChosenDay);

            var chooseTimeViewModel = new ChooseTimeViewModel()
            {
                AppointmentTimesList = appointmentAvailableTimeList,
                ServiceId            = serviceId
            };

            return(View(chooseTimeViewModel));
        }