public ActionResult AddressAndPayment(OrdersViewModel vm, FormCollection values) { var order = new Order(); var cart = ShoppingCart.GetCart(HttpContext); TryUpdateModel(order); try { order.Username = User.Identity.Name; order.OrderDate = DateTime.Now; order.IsProcessed = false; order.Total = cart.GetTotal(); //Save Order UoW.Orders.Add(order); UoW.SaveChanges(); //Process the order cart.CreateOrder(order); TempData["toast"] = "<script> $(document).ready(function () {" + "toastr.options = { 'positionClass': 'toast-bottom-right' };" + "toastr.success('Order has been sent for processing!');});</script>"; return RedirectToAction("Complete", new { id = order.OrderId }); } catch (Exception e) { //Invalid - redisplay with errors return View(vm); } }
/// <summary> /// /// </summary> /// <returns></returns> public ActionResult AddressAndPayment() { var member = UoW.Members.GetAll().FirstOrDefault(m => m.DisplayName == User.Identity.Name); var membersDetails = member.MemberDetails; var memberName = membersDetails.FirstName + " " + membersDetails.LastName; var shippingAdress = membersDetails.ShippingAddress; var defaultCreditCard = membersDetails.CreditCards.FirstOrDefault(); var creditCards = membersDetails.CreditCards.ToList(); var cart = ShoppingCart.GetCart(HttpContext); var cartTotal = cart.GetTotal(); ViewBag.creditCards = new SelectList(membersDetails.CreditCards.ToList(), "CreditCardId", "LastFour"); var model = new OrdersViewModel() { Name = memberName, DefaultCreditCard = defaultCreditCard, CreditCards = creditCards, ShippingAddress = shippingAdress, Total = cartTotal }; ViewBag.toast = TempData["toast"]; return View(model); }