示例#1
0
        public void BookWithPayment([FromBody] BookWithPayment bwp)
        {
            PlanYourTripBusinessEntity.Models.PackageBooking packageBooking = new PlanYourTripBusinessEntity.Models.PackageBooking();
            packageBooking.PackageID = bwp.booking.PackageID;
            var userStore   = new UserStore <ApplicationUser>(new ApplicationDbContext());
            var userManager = new UserManager <ApplicationUser>(userStore);

            packageBooking.Id            = userManager.FindByName(bwp.booking.UserName).Id;
            packageBooking.NumPeople     = bwp.booking.NumPeople;
            packageBooking.StartDate     = bwp.booking.StartDate.Date;
            packageBooking.EndDate       = bwp.booking.EndDate.Date;
            packageBooking.PaymentMethod = bwp.booking.PaymentMethod;
            packageBooking.IsCustomized  = bwp.booking.IsCustomized;
            packageBooking.TotalCost     = bwp.booking.TotalCost;
            packageBooking.BookingStatus = bwp.booking.BookingStatus;
            Payment pay = new Payment();

            pay.CreditCardNumber = bwp.payment.CreditCardNumber;
            pay.NameOnCard       = bwp.payment.NameOnCard;
            pay.Amount           = bwp.payment.Amount;
            bookingManager.BookWithPayment(packageBooking, pay);

            var user = userManager.FindById(packageBooking.Id);

            user.NumberOfTrips = user.NumberOfTrips++;
            userManager.Update(user);
            userStore.Context.SaveChanges();
        }
示例#2
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);
        }