예제 #1
0
        public async Task ClearUnattachedPersons(IEnumerable <string> removedPersons)
        {
            foreach (var personEmail in removedPersons)
            {
                await using var db = new BookingsDbContext(_dbContextOptions);
                var person = await db.Persons
                             .Include(x => x.Address)
                             .Include(x => x.Organisation)
                             .SingleOrDefaultAsync(x => x.ContactEmail == personEmail);

                if (person == null)
                {
                    return;
                }
                if (person.Address != null)
                {
                    db.Remove(person.Address);
                }
                if (person.Organisation != null)
                {
                    db.Remove(person.Organisation);
                }
                db.Remove(person);

                await db.SaveChangesAsync();
            }
        }
예제 #2
0
        public async Task Handle(RemoveHearingCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include("HearingCases.Case")
                          .Include("Participants.Person")
                          .Include("Participants.Person.Address")
                          .Include("Participants.Person.Organisation")
                          .Include("Participants.Questionnaire")
                          .Include("Participants.Questionnaire.SuitabilityAnswers")
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            _context.RemoveRange(hearing.GetCases());
            _context.Remove(hearing);

            var persons       = hearing.Participants.Select(x => x.Person).ToList();
            var organisations = persons.Where(p => p.Organisation != null).Select(x => x.Organisation).ToList();
            var addresses     = persons.Where(p => p.Address != null).Select(x => x.Address).ToList();

            _context.RemoveRange(organisations);
            _context.RemoveRange(addresses);
            _context.RemoveRange(persons);

            await _context.SaveChangesAsync();
        }
예제 #3
0
        public Hotel Delete(long id)
        {
            var existing = context.Hotels
                           .Include(m => m.Reviews)
                           .FirstOrDefault(hotel => hotel.Id == id);

            if (existing == null)
            {
                return(null);
            }
            context.Remove(existing);
            context.SaveChanges();

            return(existing);
        }
예제 #4
0
        public Reservation Delete(long id)
        {
            var existing = context.Reservations
                           //  .Include(m => m.User)
                           //  .Include(m => m.UserId)
                           .FirstOrDefault(movie => movie.Id == id);

            if (existing == null)
            {
                return(null);
            }
            context.Remove(existing);
            context.SaveChanges();

            return(existing);
        }