public ActionResult Details(ProductsDetailVM pdvm, int id) { pdvm.Prod = _bus.GetProducts(id); bool res = false; if (ModelState.IsValid) { res = _bus.AddToCart(pdvm); if (res == true) { ViewBag.msg = "Product added to cart"; bool result = false; result = _bus.UpdateOrder(); if (result == true) { return(RedirectToAction("ShowProducts")); } else { ViewBag.msg = "Unable to update order"; } } else { ViewBag.msg = "Unable to add to cart"; } } return(View(pdvm)); }
public bool AddToCart(ProductsDetailVM pdvm) { if (Repository.ProductInStock(pdvm.Quantity, pdvm.Prod.ProductId) == false) { throw new Exception("Product Out of Stock"); } return(Repository.AddToCart(pdvm)); }
public ActionResult Details(int id) { //bring in product details using id ProductsDetailVM pdvm = new ProductsDetailVM(); pdvm.Prod = _bus.GetProducts(id); Repository.AddOrder(); return(View(pdvm)); }
public static bool AddToCart(ProductsDetailVM pr) { bool res = false; int orderNo = 0; try { orderNo = GetOrderNo(); string sql = "insert into OrderDetails(OrderNo,ItemNo,ItemDesc,Qty,Price) select @OrderNo, @ItemNo, @ItemDesc, @qty,@Price"; List <SqlParameter> pList = new List <SqlParameter>(); SqlParameter p1 = new SqlParameter("@OrderNo", SqlDbType.Int); SqlParameter p2 = new SqlParameter("@ItemNo", SqlDbType.Int); SqlParameter p3 = new SqlParameter("@ItemDesc", SqlDbType.VarChar); SqlParameter p4 = new SqlParameter("@Qty", SqlDbType.Int); SqlParameter p5 = new SqlParameter("@Price", SqlDbType.Money); p1.Value = orderNo; p2.Value = pr.Prod.CatID; p3.Value = pr.Prod.ProductSDesc; p4.Value = pr.Quantity; p5.Value = pr.Prod.Price; pList.Add(p1); pList.Add(p2); pList.Add(p3); pList.Add(p4); pList.Add(p5); int rows = DataAccess.InsertUpdateDelete(sql, pList); if (rows > 0) { res = true; } } catch (Exception) { throw; } return(res); }