Exemple #1
0
        public async Task <IHttpActionResult> Current(string subCruise)
        {
            var cruise = await _cruiseRepository.GetActiveAsync();

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

            var subCruiseCode = SubCruiseCode.FromString(subCruise ?? string.Empty);

            using (var db = DbUtil.Open())
            {
                return(this.OkCacheControl(new
                {
                    AgeDistribution = await _reportingService.GetAgeDistribution(db, cruise, subCruiseCode),
                    // Bookings per subcruise is not supported, so we null this one if a subcruise is provided
                    BookingsByPayment = SubCruiseCode.None != subCruiseCode ? null : await _reportingService.GetNumberOfBookingsByPaymentStatus(db, cruise),
                    Genders = await _reportingService.GetGenders(db, cruise, subCruiseCode),
                    TopContacts = await _reportingService.GetTopContacts(db, cruise, subCruiseCode, 15),
                    TopGroups = await _reportingService.GetTopGroups(db, cruise, subCruiseCode, 15)
                },
                                           WebConfig.DynamicDataMaxAge));
            }
        }
        public async Task <IHttpActionResult> Active()
        {
            Cruise cruise = await _cruiseRepository.GetActiveAsync();

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

            return(this.OkCacheControl(cruise, WebConfig.StaticDataMaxAge));
        }
Exemple #3
0
        public async Task <IHttpActionResult> Active()
        {
            var activeCruise = await _cruiseRepository.GetActiveAsync();

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

            CruiseProductWithType[] products = await _productRepository.GetActiveAsync(activeCruise);

            // Give relative URLs for images to make life easier on frontend
            foreach (CruiseProductWithType product in products)
            {
                if (!String.IsNullOrEmpty(product.Image))
                {
                    product.Image = string.Concat("/gfx/products/", product.Image);
                }
            }

            return(this.OkCacheControl(products, WebConfig.StaticDataMaxAge));
        }
Exemple #4
0
        public async Task <IHttpActionResult> CreateOrUpdate(BookingSource bookingSource)
        {
            try
            {
                Cruise activeCruise = await _cruiseRepository.GetActiveAsync();

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

                BookingResult result;
                if (!String.IsNullOrEmpty(bookingSource.Reference))
                {
                    if (!AuthContext.IsAdmin && !String.Equals(AuthContext.UserName, bookingSource.Reference, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(BadRequest("Request is unauthorized, or not logged in as the booking it's trying to update."));
                    }

                    result = await _bookingRepository.UpdateAsync(activeCruise, bookingSource, allowUpdateDetails : AuthContext.IsAdmin, allowUpdateIfLocked : AuthContext.IsAdmin);

                    _log.Info("Updated booking {0}.", result.Reference);
                }
                else
                {
                    result = await _bookingRepository.CreateAsync(activeCruise, bookingSource, allowCreateIfLocked : AuthContext.IsAdmin);

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

                    await SendBookingCreatedMailAsync(activeCruise, bookingSource, result);
                }

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

                return(Ok(result));
            }
            catch (AvailabilityException ex)
            {
                _log.Info(ex, "Lack of availability prevented a booking from being created.");
                return(Conflict());
            }
            catch (BookingException ex)
            {
                _log.Warn(ex, "A validation error occurred while creating the booking.");
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _log.Error(ex, "An unexpected exception occurred while creating the booking.");
                throw;
            }
        }
Exemple #5
0
        public async Task GivenBookingSource_WhenCruiseIsLocked_ShouldFailToCreate()
        {
            var cruiseRepository = new CruiseRepository();
            var cruise           = await cruiseRepository.GetActiveAsync();

            Assert.IsFalse(cruise.IsLocked);
            cruise.IsLocked = true;
            await cruiseRepository.UpdateMetadataAsync(cruise);

            try
            {
                await GetNewlyCreatedBookingForTestAsync(cruise, GetBookingRepositoryForTest());

                Assert.Fail("Create booking did not throw");
            }
            catch (BookingException)
            {
            }
        }
Exemple #6
0
        public async Task <IHttpActionResult> Excel(bool onlyFullyPaid = false, string updatedSince = null, string subCruise = null)
        {
            var activeCruise = await _cruiseRepository.GetActiveAsync();

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

            SubCruiseCode subCruiseCode    = string.IsNullOrEmpty(subCruise) ? SubCruiseCode.First : SubCruiseCode.FromString(subCruise);
            DateTime?     updatedSinceDate = string.IsNullOrEmpty(updatedSince)
                                ? null
                                : new DateTime?(DateTime.ParseExact(updatedSince, UpdatedSinceFormat, CultureInfo.InvariantCulture));

            var      exportToExcelGenerator = new ExportToExcelGenerator(_cabinRepository, _productRepository);
            Workbook workbook = await exportToExcelGenerator.ExportToWorkbookAsync(activeCruise, onlyFullyPaid, subCruiseCode.ToString(), updatedSinceDate);

            return(CreateHttpResponseMessage(workbook, subCruise));
        }