示例#1
0
        public bool UpdateTicket(Ticket ticket)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var ticketEntity = GetById(ticket.Id);
                    ticketEntity.StartDate        = ticket.StartDate;
                    ticketEntity.EndDate          = ticket.EndDate;
                    ticketEntity.FromLocation     = ticket.FromLocation;
                    ticketEntity.ToLocation       = ticket.ToLocation;
                    ticketEntity.TotalParticipant = ticket.TotalParticipant;
                    ticketEntity.ReasonBooking    = ticket.ReasonBooking;
                    ticketEntity.Status           = ticket.Status;


                    var locationsEntity = _locationServices.GetLocationsByTicketId(ticket.Id);
                    _locationServices.RemoveRange(locationsEntity);
                    foreach (var location in locationsEntity)
                    {
                        var participantsEntity = _participantServices.GetParticipantsByLocationId(location.Id);
                        _participantServices.RemoveRange(participantsEntity);
                    }
                    foreach (var location in ticket.Locations)
                    {
                        location.TicketId = ticket.Id;
                        _locationServices.Add(location);
                        _context.SaveChanges();
                        foreach (var participant in location.Participants)
                        {
                            participant.LocationId = location.Id;
                            _participantServices.Add(participant);
                        }
                    }
                    var relatedPeoplesEntity = _relatedPeopleServices.GetRelatedPeoplesByTicketId(ticket.Id);
                    _relatedPeopleServices.RemoveRange(relatedPeoplesEntity);
                    foreach (var relatedPeople in ticket.RelatedPeoples)
                    {
                        relatedPeople.TicketId = ticket.Id;
                        _relatedPeopleServices.Add(relatedPeople);
                    }
                    _context.SaveChanges();
                    transaction.Commit();
                    return(true);
                }
                catch (Exception error)
                {
                    transaction.Rollback();
                    return(false);
                }
            }
            throw new NotImplementedException();
        }
示例#2
0
        public List <Location> GetLocationsByTicketId(int ticketId)
        {
            var locations = _context.Locations.Where(x => x.TicketId == ticketId).ToList();

            foreach (var location in locations)
            {
                var participants = _participantServices.GetParticipantsByLocationId(location.Id);
                location.Participants = participants;
            }
            return(locations);
        }