private async Task <Booking> CreateBookingAsync(Lodgment lodgment, BookingConfirmationModel bookingConfirmationModel)
        {
            var bookingStatus = await repository.GetBookingStatusByNameAsync(BookingStatusName.Created);

            if (bookingStatus == null)
            {
                throw new KeyNotFoundException($"Cannot find the booking status with name {BookingStatusName.Created}");
            }

            var amountGuest = (byte)bookingConfirmationModel.LodgmentOptions.TotalGuests;
            var price       = await lodgmentCalculator.CalculateTotalStayAsync(
                bookingConfirmationModel.LodgmentOptions, lodgment
                );

            var booking = new Booking()
            {
                CheckIn           = bookingConfirmationModel.LodgmentOptions.CheckIn,
                CheckOut          = bookingConfirmationModel.LodgmentOptions.CheckOut,
                AmountGuest       = amountGuest,
                Name              = bookingConfirmationModel.Name,
                LastName          = bookingConfirmationModel.LastName,
                Email             = bookingConfirmationModel.Email,
                ConfirmationCode  = Guid.NewGuid().ToString(),
                Price             = price,
                BookingStatusId   = bookingStatus.Id,
                LodgmentId        = lodgment.Id,
                StatusDescription = BookingStatusName.Created
            };

            return(booking);
        }
 public void BeforeEach()
 {
     fixture = new Fixture().Customize(new AutoMoqCustomization());
     fixture.Customize <BookingStatus>(c => c
                                       .Without(x => x.Bookings));
     fixture.Customize <Lodgment>(c =>
                                  c.Without(s => s.Spot)
                                  .Without(y => y.Bookings)
                                  .Without(y => y.Reviews));
     moqRepository         = new Mock <IBookingsRepository>(MockBehavior.Strict);
     moqLodgmentCalculator = new Mock <ILodgmentCalculator>(MockBehavior.Strict);
     service          = new BookingsService(moqRepository.Object, moqLodgmentCalculator.Object);
     expectedLodgment = fixture.Create <Lodgment>();
     lodgment         = fixture.Create <Lodgment>();
     expectedBooking  = fixture.Create <Booking>();
     expectedBooking.Lodgment.IsActive = true;
     bookingConfirmationModel          = fixture.Create <BookingConfirmationModel>();
     bookingId = fixture.Create <int>();
     bookingConfirmationCode = fixture.Create <string>();
     bookingStatus           = fixture.Create <BookingStatus>();
     expectedBookingStatus   = fixture.Create <BookingStatus>();
     expectedPrice           = fixture.Create <double>();
     expectedBookings        = fixture.CreateMany <Booking>();
     paging            = fixture.Create <PagingModel>();
     paginatedBookings = fixture.Create <PaginatedModel <Booking> >();
 }
        public ActionResult Book(int?id, string sender)
        {
            Bookings booking = new Bookings();

            booking.TripID = (int)id;
            booking.UserId = sender;
            booking.SeatId = findNextAvailableSeat((int)id);
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Trip trip = db.Trips.Find(id);

            if (trip == null)
            {
                return(HttpNotFound());
            }

            BookingConfirmationModel mymodel = new BookingConfirmationModel();

            mymodel.Trips    = trip;
            mymodel.Bookings = booking;



            return(View(mymodel));
        }
        public async Task <Booking> AddBookingAtLodgmentAsync(Lodgment lodgment, BookingConfirmationModel bookingConfirmationModel)
        {
            var bookingModel = await CreateBookingAsync(lodgment, bookingConfirmationModel);

            var booking = await repository.AddBookingAsync(bookingModel);

            return(booking);
        }
Beispiel #5
0
        public async Task <Booking> AddLodgmentBookingAsync(int id, BookingConfirmationModel bookingConfirmationModel)
        {
            var lodgment = await repository.GetLodgmentByIdAsync(id);

            if (lodgment == null)
            {
                throw new ArgumentException("The lodgment is out of capacity");
            }

            var booking = await bookingsService.AddBookingAtLodgmentAsync(lodgment, bookingConfirmationModel);

            return(booking);
        }
Beispiel #6
0
        public ActionResult Confirmation()
        {
            var booking = Session[BOOKING] as Booking;
            var model   = new BookingConfirmationModel();

            if (booking == null)
            {
                return(RedirectToAction(nameof(Form)));
            }

            model.InitializeFor(booking);

            return(View(model));
        }
Beispiel #7
0
        public async Task <IActionResult> AddLodgmentBookingAsync(int id, [FromBody] BookingConfirmationModel bookingConfirmationModel)
        {
            try
            {
                var booking = await service.AddLodgmentBookingAsync(id, bookingConfirmationModel);

                return(Ok(booking));
            }
            catch (Exception ex)
            {
                var exceptionResponse = GetExceptionResponse(ex, Request);
                return(exceptionResponse);
            }
        }
Beispiel #8
0
        public ActionResult BookingConfirmationPage(BookingConfirmationModel model)
        {
            Service             service        = repository.Services.Where(p => p.ServiceId == model.ServiceId).FirstOrDefault();
            RequestedService    requested      = repository.RequestedServices.Where(p => p.RequestedServiceId == model.RequestedServiceId).FirstOrDefault();
            Payment             payment        = repository.Payments.Where(p => p.PaymentId == model.PaymentId).LastOrDefault();
            ServiceRequestModel serviceRequest = new ServiceRequestModel();

            //Logic for authorized user
            if (User.Identity.IsAuthenticated)
            {
                serviceRequest = new ServiceRequestModel {
                    Service = service, RequestedService = requested, Payment = payment, Discount = model.Discount
                };
            }
            //Logic for a unregistered user
            else
            {
                serviceRequest = new ServiceRequestModel {
                    Service = service, RequestedService = requested, Payment = payment
                };
            }
            return(View(serviceRequest));
        }
Beispiel #9
0
 public void BeforeEach()
 {
     InitializeComponents();
     fixture.Customize <Lodgment>(c => c
                                  .Without(x => x.Spot)
                                  .Without((y => y.Reviews)));
     fixture.Customize <BookingStatus>(c => c
                                       .Without(x => x.Bookings));
     fixture.Customize <Booking>(c => c
                                 .Without(b => b.Lodgment));
     moqService = new Mock <ILodgmentsService>(MockBehavior.Strict);
     controller = new LodgmentsController(moqService.Object);
     controller.ControllerContext = controllerContext;
     expectedLodgment             = fixture.Create <Lodgment>();
     lodgmentOptions          = fixture.Create <LodgmentOptionsModel>();
     lodgmentId               = fixture.Create <int>();
     bookingConfirmationModel = fixture.Create <BookingConfirmationModel>();
     expectedBooking          = fixture.Create <Booking>();
     expectedLodgments        = fixture.CreateMany <Lodgment>();
     paginatedLodgments       = fixture.Create <PaginatedModel <Lodgment> >();
     paging       = fixture.Create <PagingModel>();
     fileModel    = fixture.Create <FileModel>();
     expectedUrls = fixture.CreateMany <string>().ToList();
 }