Esempio n. 1
0
        public void BookPackage([FromBody] Booking booking)
        {
            PlanYourTripBusinessEntity.Models.PackageBooking packageBooking = new PlanYourTripBusinessEntity.Models.PackageBooking();
            packageBooking.PackageID = booking.PackageID;

            // Use identity framework to find user ID from username in Booking model
            var userStore   = new UserStore <ApplicationUser>(new ApplicationDbContext());
            var userManager = new UserManager <ApplicationUser>(userStore);

            packageBooking.Id = userManager.FindByName(booking.UserName).Id;

            packageBooking.NumPeople     = booking.NumPeople;
            packageBooking.StartDate     = booking.StartDate.Date;
            packageBooking.EndDate       = booking.EndDate.Date;
            packageBooking.PaymentMethod = booking.PaymentMethod;
            packageBooking.IsCustomized  = booking.IsCustomized;
            packageBooking.TotalCost     = booking.TotalCost;
            packageBooking.BookingStatus = booking.BookingStatus;
            bookingManager.BookPackage(packageBooking);

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

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

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