Beispiel #1
0
 public bool AddTicket(Ticket ticket)
 {
     using (var transaction = _context.Database.BeginTransaction())
     {
         try
         {
             var locations      = ticket.Locations;
             var relatedPeoples = ticket.RelatedPeoples;
             Add(ticket);
             _context.SaveChanges();
             foreach (var relatedPeople in relatedPeoples)
             {
                 relatedPeople.TicketId = ticket.Id;
                 _relatedPeopleServices.Add(relatedPeople);
                 _context.SaveChanges();
             }
             foreach (var location in locations)
             {
                 location.TicketId = ticket.Id;
                 _locationServices.Add(location);
                 _context.SaveChanges();
                 foreach (var participant in location.Participants)
                 {
                     participant.LocationId = location.Id;
                     _participantServices.Add(participant);
                 }
             }
             _context.SaveChanges();
             transaction.Commit();
             return(true);
         }
         catch (Exception error)
         {
             transaction.Rollback();
             Console.WriteLine(error);
             return(false);
         }
     }
 }