public async Task <IActionResult> Edit(Guid id, [Bind("id,email,streetaddress")] VacationOrder vacationOrder) { if (id != vacationOrder.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(vacationOrder); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VacationOrderExists(vacationOrder.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(vacationOrder)); }
public async Task <IActionResult> Index(CheckoutModel model) { //Here is how it works: Javascript sends the information TO Braintree and Braintree sends the "nonce" back. if (ModelState.IsValid) { VacationOrder order = new VacationOrder { email = model.email }; VacationCart cart = null; if (User.Identity.IsAuthenticated) { var currentUser = _userManager.GetUserAsync(User).Result; cart = _context.VacationCarts.Include(x => x.VacationModelVacationCarts).ThenInclude(x => x.vacationModel).Single(x => x.Applicationuserid == currentUser.Id); } else if (Request.Cookies.ContainsKey("cart_id")) { int existingCartID = int.Parse(Request.Cookies["cart_id"]); cart = _context.VacationCarts.Include(x => x.VacationModelVacationCarts).ThenInclude(x => x.vacationModel).FirstOrDefault(x => x.id == existingCartID); //So, if there is a cookie attached to the cart, then set cart to = the cart, the product AND the existing ID? } foreach (var item in cart.VacationModelVacationCarts) { order.VacationOrderDestinationDetails.Add(new VacationOrderDestinationDetails { DateCreated = DateTime.Now, DateLastModified = DateTime.Now, Quantity = item.Quantity, destinationdescription = item.vacationModel.DestinationDescription, destination = item.vacationModel.DreamDestination }); } _context.VacationModelCarts.RemoveRange(cart.VacationModelVacationCarts); _context.VacationCarts.Remove(cart); //So, after we listed the items in the foreach, we don't need the cart anymore. We empty they products and disengage the model from the cart (???). var result = await _braintreeGateway.Transaction.SaleAsync(new TransactionRequest { Amount = order.VacationOrderDestinationDetails.Sum(x => x.Quantity *x.Budget), /* ERROR -- FIX. * PaymentMethodNonce = model.Nonce, * LineItems = order.VacationOrderDestinationDetails.Select(x => new TransactionLineItemRequest * { * Description = x.destinationdescription, * Name = x.destination, * Quantity = x.Quantity, * UnitAmount = x.Budget, * TotalAmount = x.Budget * x.Quantity * }) * * await _emailSender.SendEmailAsync(model.email, " your order " + order.id + " Thank you for ordering!");*/ }); } return(View()); }
public async Task <IActionResult> Create([Bind("id,email,streetaddress")] VacationOrder vacationOrder) { if (ModelState.IsValid) { vacationOrder.id = Guid.NewGuid(); _context.Add(vacationOrder); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vacationOrder)); }