Esempio n. 1
0
        public async Task <IHttpActionResult> Delete(string reference)
        {
            Booking booking = await TryFindBookingInActiveCruiseByReference(reference);

            if (null == booking)
            {
                return(NotFound());
            }

            try
            {
                await _bookingRepository.DeleteAsync(booking);

                _log.Info("Deleted booking {0}.", booking.Reference);

                // Ensure we update reporting after each change
                HostingEnvironment.QueueBackgroundWorkItem(ct => _reportingService.GenerateReportsAsync());

                return(Ok());
            }
            catch (Exception ex)
            {
                _log.Error(ex, "An unexpected exception occurred while deleting the booking.");
                throw;
            }
        }
Esempio n. 2
0
        public async void DeleteAsync_DeleteFromContext()
        {
            var booking = BookingGenerator.Create();

            using (var context = new booking_facilitiesContext(contextOptions))
            {
                var repository = new BookingRepository(context);
                context.Database.EnsureCreated();
                context.Booking.Add(booking);
                context.SaveChanges();
                Assert.Equal(1, await context.Booking.CountAsync());

                await repository.DeleteAsync(booking);

                Assert.Equal(0, await context.Booking.CountAsync());
            }
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> Delete(string reference)
        {
            try
            {
                Booking booking = await _bookingRepository.FindByReferenceAsync(reference);

                if (null == booking)
                {
                    return(NotFound());
                }

                await _bookingRepository.DeleteAsync(booking);

                _log.Info("Deleted booking {0}.", booking.Reference);

                return(Ok());
            }
            catch (Exception ex)
            {
                _log.Error(ex, "An unexpected exception occurred while deleting the booking.");
                throw;
            }
        }