コード例 #1
0
        //TODO : unit test
        public ScheduleBTO AddSchedule(ScheduleBTO scheduleBto)
        {
            ScheduleDTO schedule = new ScheduleDTO();

            if (scheduleBto != null)
            {
                var schedules = scheduleRepository.GetSchedulesByDayOfWeekAndRestoId(scheduleBto.Resto.Id, (DayOfWeek)scheduleBto.WeekDay);

                if (ScheduleIsValid(scheduleBto, schedules))
                {
                    schedule = scheduleRepository.Create(scheduleBto.BTOToScheduleDomain().ScheduleDomainToDTO());
                    return(schedule.DTOToScheduleDomain().ScheduleToBTO());
                }
                return(null);
            }
            return(null);
        }
コード例 #2
0
        public ScheduleBTO UpdateSchedule(ScheduleBTO scheduleBto)
        {
            ScheduleDTO schedule = new ScheduleDTO();

            if (scheduleBto != null)
            {
                var schedules = scheduleRepository.GetSchedulesByDayOfWeekAndRestoId(scheduleBto.RestoId, (DayOfWeek)scheduleBto.WeekDay);

                //Remove the scheduleBto of the schedules because ScheduleIsValid() will check the scheduleBto in the list
                var scheduleToRemove = schedules.Find(x => x.Id == scheduleBto.Id);

                schedules.Remove(scheduleToRemove);

                if (ScheduleIsValid(scheduleBto, schedules))
                {
                    schedule = scheduleRepository.Update(scheduleBto.BTOToScheduleDomain().ScheduleDomainToDTO());
                    return(schedule?.DTOToScheduleDomain().ScheduleToBTO() ?? null);
                }
            }
            return(null);
        }