Beispiel #1
0
        public IActionResult EditSchedule(ScheduleBTO scheduleBto)
        {
            int idToReturn = scheduleBto.RestoId;

            if (!ModelState.IsValid)
            {
                return(View(scheduleBto));
            }

            if (scheduleBto.TimeClosed.TimeOfDay <= scheduleBto.TimeOpen.TimeOfDay)
            {
                ViewData["Error"] = "You can't do that : TimeClosed must be superior to TimeOpen";
                return(View(scheduleBto));
            }


            var result = scheduleUC.UpdateSchedule(scheduleBto);



            if (result == null)
            {
                return(RedirectToAction("Error", new { errorMessage = "We can't update this schedule, please contact support" }));
            }
            if (User.IsInRole("Administrators"))
            {
                return(RedirectToAction("GetAllSchedules"));
            }
            else
            {
                return(RedirectToAction("GetAllSchedulesByRestoId", new { Id = idToReturn }));
            }
        }
Beispiel #2
0
        public IActionResult CreateSchedule(int Id)
        {
            ScheduleBTO result = new ScheduleBTO();

            result.Resto = new RestoBTO {
                Id = Id
            };
            return(View(result));
        }
Beispiel #3
0
 //Check if the created or updated schedule has proper hours before insert or update in DB
 private bool ScheduleIsValid(ScheduleBTO scheduleBTO, List <ScheduleDTO> schedules)
 {
     foreach (var item in schedules)
     {
         if (!((scheduleBTO.TimeOpen.TimeOfDay <= item.TimeOpen.TimeOfDay && scheduleBTO.TimeClosed.TimeOfDay <= item.TimeOpen.TimeOfDay) ||
               (scheduleBTO.TimeOpen.TimeOfDay >= item.TimeClosed.TimeOfDay && scheduleBTO.TimeClosed.TimeOfDay >= item.TimeClosed.TimeOfDay)))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #4
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);
        }
 public static ScheduleDomain BTOToScheduleDomain(this ScheduleBTO scheduleBto)
 {
     if (scheduleBto != null)
     {
         return new ScheduleDomain
                {
                    Id         = scheduleBto.Id,
                    RestoId    = scheduleBto.RestoId,
                    DayOfWeek  = (int)scheduleBto.WeekDay,
                    TimeOpen   = scheduleBto.TimeOpen,
                    TimeClosed = scheduleBto.TimeClosed,
                    Resto      = scheduleBto.Resto.BTOToDomain()
                }
     }
     ;
     else
     {
         return(null);
     }
 }
Beispiel #6
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);
        }
Beispiel #7
0
        public IActionResult CreateSchedule(ScheduleBTO scheduleBTO)
        {
            int idToReturn = scheduleBTO.Resto.Id;


            if (!ModelState.IsValid)
            {
                return(View(scheduleBTO));
            }

            if (scheduleBTO.TimeClosed.TimeOfDay <= scheduleBTO.TimeOpen.TimeOfDay)
            {
                ViewData["Error"] = "You can't do that : TimeClosed must be superior to TimeOpen";
                return(View(scheduleBTO));
            }

            var result = scheduleUC.AddSchedule(scheduleBTO);

            if (result == null)
            {
                return(RedirectToAction("Error", new { errorMessage = "We can't add this schedule, please contact support" }));
            }
            return(RedirectToAction("GetAllSchedulesByRestoId", new { Id = idToReturn }));
        }