public ActionResult AddItem(Guid id) { var repository = new ProductRepository(); var productDictionary = repository.GetProducts().OrderBy(product => product.ProductName) .Select(p => new {ProductId = p.ProductId, ProductName = p.ProductName}) .ToDictionary(x => x.ProductId, x => x.ProductName); var quantityDictionary = new Dictionary<int, int>(); for (int i = 1; i <= 10; i++) { quantityDictionary.Add(i, i); } var model = new OrderItemModel { OrderItemId = Guid.NewGuid(), OrderId = id, OrderItemTotal = 0.ToString("c"), ProductDictionary = productDictionary, QuantityDictionary = quantityDictionary }; return View(model); }
public JsonResult GetOrderItemTotal(Guid productId, int quantity) { var repository = new ProductRepository(); var unitCost = repository.GetProduct(productId).Price; var orderItemTotal = unitCost*quantity; return Json(new {orderItemTotal = orderItemTotal}, JsonRequestBehavior.AllowGet); }