public IActionResult Checkout() { var cart = HttpContext.Session.GetObjectFromJson("Cart"); var totalAmount = cart.GetTotalAmount(); return View(new CheckoutViewModel { TotalAmount = totalAmount }); }
public IActionResult PlaceOrder(OrderViewModel viewModel) { if (!ModelState.IsValid) { return View("Checkout", viewModel); } var cart = HttpContext.Session.GetObjectFromJsonIn this example, the PlaceOrder method is called when the customer submits their payment information. The method validates the input using the 'ModelState.IsValid' property and returns the 'Checkout' View if the input is invalid. Otherwise, it retrieves the cart object from session state and calculates the total amount owed. After that, it stores the order details in the database and clears the cart. Finally, it displays the 'OrderConfirmation' View to the customer. Package library: Microsoft.AspNetCore.Mvc.("Cart"); var totalAmount = cart.GetTotalAmount(); // store order details in database and clear cart return View("OrderConfirmation"); }