示例#1
0
        public void UpdateManualSchedule(ManualScheduleModel scheduleModel, out List <Appointment> pendingAppoints)
        {
            pendingAppoints = new List <Appointment>();

            var schedule = _scheduleService.GetScheduleById(scheduleModel.Id ?? 0);

            if (schedule == null)
            {
                throw new EntityNotFoundException();
            }

            if (scheduleModel.IsAvailable && !schedule.IsAvailable && schedule.Start_DateTime.ToShortTimeString() == "06:00" && schedule.End_DateTime.ToShortTimeString() == "23:59")
            {
                RemoveSchedule(schedule.Id, out List <Appointment> pendingList);
                pendingAppoints = pendingList;
            }
            else
            {
                schedule.IsAvailable          = scheduleModel.IsAvailable;
                schedule.Start_DateTime       = scheduleModel.StartDateTime;
                schedule.End_DateTime         = scheduleModel.EndDateTime;
                schedule.ShiftCenterServiceId = scheduleModel.HealthServiceId;
                schedule.MaxCount             = scheduleModel.MaxCount;
                schedule.Prerequisite         = scheduleModel.Prerequisite;

                _scheduleService.UpdateSchedule(schedule);
            }
        }
示例#2
0
        public void SetManualSchedule(ServiceSupply serviceSupply, ManualScheduleModel scheduleModel, out List <Appointment> pendingAppoints)
        {
            if (scheduleModel.StartDateTime == null || scheduleModel.EndDateTime == null)
            {
                throw new Exception(Messages.PlsEnterStartEndDateTime);
            }

            pendingAppoints = new List <Appointment>();

            if (!scheduleModel.IsAvailable && scheduleModel.AllDay)
            {
                var pendingList = _appointmentService.GetPendingAppointmentsForServiceSupplyInManualSchedule(serviceSupply.Id, scheduleModel.StartDateTime, scheduleModel.EndDateTime);
                pendingAppoints.AddRange(pendingList);
            }

            if (!pendingAppoints.Any())
            {
                if (scheduleModel.AllDay)
                {
                    var schedules = _scheduleService.GetManualSchedulesForServiceSupplyInDate(serviceSupply.Id, scheduleModel.StartDateTime);
                    if (schedules.Count <= 0)
                    {
                        if (!scheduleModel.IsAvailable)
                        {
                            _scheduleService.InsertSchedule(new Schedule
                            {
                                Start_DateTime       = scheduleModel.StartDateTime,
                                End_DateTime         = scheduleModel.EndDateTime,
                                IsAvailable          = scheduleModel.IsAvailable,
                                DayOfWeek            = scheduleModel.StartDateTime.DayOfWeek.ToString(),
                                ServiceSupplyId      = serviceSupply.Id,
                                Description_Ku       = scheduleModel.StartDateTime.DayOfWeek + scheduleModel.StartDateTime.ToShortDateString(),
                                CreatedAt            = DateTime.Now,
                                ShiftCenterServiceId = 1
                            });
                        }
                    }
                    else
                    {
                        if (schedules.Count == 1)
                        {
                            var _schedule = schedules.FirstOrDefault();
                            if (_schedule.Start_DateTime.Hour == 06 && _schedule.End_DateTime.Hour == 23)
                            {
                                if (scheduleModel.IsAvailable)
                                {
                                    _scheduleService.DeleteSchedule(_schedule);
                                }
                            }
                            else
                            {
                                _schedule.IsAvailable = scheduleModel.IsAvailable;
                                _scheduleService.UpdateSchedule(_schedule);
                            }
                        }
                        else
                        {
                            foreach (var item in schedules)
                            {
                                item.IsAvailable = scheduleModel.IsAvailable;
                                _scheduleService.UpdateSchedule(item);
                            }
                        }
                    }
                }
                else
                {
                    var preSchedule = _scheduleService.GetSingleManualScheduleForServiceSupply(serviceSupply.Id, scheduleModel.StartDateTime, scheduleModel.HealthServiceId);

                    var isValidSchedule = IsValidScheduleTimes(out string message, scheduleModel.StartDateTime, scheduleModel.EndDateTime, serviceSupply, preSchedule);
                    if (!isValidSchedule)
                    {
                        throw new AwroNoreException(message);
                    }

                    var schedule = new Schedule
                    {
                        Start_DateTime       = scheduleModel.StartDateTime,
                        End_DateTime         = scheduleModel.EndDateTime,
                        ShiftCenterServiceId = scheduleModel.HealthServiceId,
                        Prerequisite         = scheduleModel.Prerequisite,
                        IsAvailable          = scheduleModel.IsAvailable,
                        MaxCount             = scheduleModel.MaxCount,
                        Shift           = getScheduleShift(scheduleModel.StartDateTime, scheduleModel.EndDateTime),
                        DayOfWeek       = scheduleModel.StartDateTime.DayOfWeek.ToString(),
                        ServiceSupplyId = serviceSupply.Id,
                        Description_Ku  = scheduleModel.StartDateTime.DayOfWeek + scheduleModel.StartDateTime.ToShortDateString(),
                        CreatedAt       = DateTime.Now
                    };

                    _scheduleService.InsertSchedule(schedule);
                }
            }
        }