Esempio n. 1
0
 //creating new OpeningHours needs to be accompanied by an existing Hall
 public bool CreateOpeningHours(Hall hall)
 {
     for (int i = hall.HallOpeningHours.Count - 1; i >= 0; i--)
     {
         var repoOpeningHours = Enumerable.FirstOrDefault <OpeningHours>(_hallRepository.OpeningHours(), repOh =>
                                                                         repOh.Day == hall.HallOpeningHours[i].OpeningHours.Day &&
                                                                         repOh.OpeningTime == hall.HallOpeningHours[i].OpeningHours.OpeningTime &&
                                                                         repOh.ClosingTime == hall.HallOpeningHours[i].OpeningHours.ClosingTime);
         //if not null dont make a new entry
         if (repoOpeningHours != null)
         {
             //Combination between Hall and OpeningHours already exist
             if (Enumerable.Any <HallOpeningHours>(_hallRepository.HallOpeningHours(), hoh =>
                                                   hoh.HallId == hall.HallId && hoh.OpeningHoursId == hall.HallOpeningHours[i].OpeningHoursId))
             {
                 hall.HallOpeningHours.RemoveAt(i);
                 continue;
             }
             hall.HallOpeningHours.RemoveAt(i);
             hall.HallOpeningHours.Add(new HallOpeningHours()
             {
                 HallId         = hall.HallId,
                 OpeningHoursId = repoOpeningHours.OpeningHoursId
             });
         }
     }
     //no OpeningHours left to add
     if (!hall.HallOpeningHours.Any())
     {
         return(false);
     }
     return(_hallRepository.CreateOpeningHours(hall));
 }