예제 #1
0
 //creating new Hall needs to be accompanied by a list containing OpeningHours
 public bool CreateHall(Hall hall)
 {
     if (hall.HallOpeningHours.Count < 1)
     {
         return(false);
     }
     else
     {
         //check if OpeningHours already exists in database
         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)
             {
                 hall.HallOpeningHours.RemoveAt(i);
                 hall.HallOpeningHours.Add(new HallOpeningHours()
                 {
                     HallId         = hall.HallId,
                     OpeningHoursId = repoOpeningHours.OpeningHoursId
                 });
             }
         }
         return(_hallRepository.CreateHall(hall));
     }
 }