예제 #1
0
        public void BookCustom([FromBody] CustomPackageBooking packageBooking)
        {
            var userStore   = new UserStore <ApplicationUser>(new ApplicationDbContext());
            var userManager = new UserManager <ApplicationUser>(userStore);

            CustomPackage customPackage = new CustomPackage();

            customPackage.Id = userManager.FindByName(packageBooking.Booking.UserName).Id;
            int packageID = packageManager.AddCustomPackage(customPackage, packageBooking.UserCustomizations);

            PackageBooking booking = new PackageBooking();

            booking.PackageID     = packageID;
            booking.Id            = customPackage.Id;
            booking.NumPeople     = packageBooking.Booking.NumPeople;
            booking.StartDate     = packageBooking.Booking.StartDate.Date;
            booking.EndDate       = packageBooking.Booking.EndDate.Date;
            booking.PaymentMethod = packageBooking.Booking.PaymentMethod;
            booking.IsCustomized  = packageBooking.Booking.IsCustomized;
            booking.TotalCost     = packageBooking.Booking.TotalCost;
            booking.BookingStatus = packageBooking.Booking.BookingStatus;
            bookingManager.BookPackage(booking);

            // Increment number of trips taken by the user
            var user = userManager.FindById(booking.Id);

            user.NumberOfTrips++;
            userManager.Update(user);
            userStore.Context.SaveChanges();

            // Decrement number available for package
            packageManager.DecrementNumAvailable(packageBooking.Booking.PackageID, booking.NumPeople);
        }