public ViewResult GetDetail(FormCollection col) { string id = col["id"]; var product = dao.GetProductDetail(id); ViewBag.ID = id; return(View("GetDetail", product)); }
public ActionResult UpdateQuantity(FormCollection col) { string id = col["id"]; string quantity = col["quantity"]; Order cart = Session["CART"] as Order; PhoneDAO dao = new PhoneDAO(); bool isEnough = true; string name = "bủh"; for (int i = 0; i < cart.detailList.Count; i++) { if (cart.detailList[i].IDProduct.Equals(id)) { if (cart.detailList[i].Quantity > dao.GetProductDetail(cart.detailList[i].IDProduct).Quantity) { isEnough = false; name = cart.detailList[i].ProductName; } } } if (!isEnough) { ViewBag.INSUFF = "There is not enough quantity of " + name + " for you! Please choose another products or decrease the amount!"; } else { for (int i = 0; i < cart.detailList.Count; i++) { if (cart.detailList[i].IDProduct.Equals(id)) { cart.detailList[i].Quantity = Convert.ToInt32(quantity); } } int total = 0; for (int i = 0; i < cart.detailList.Count; i++) { total += (cart.detailList[i].Price * cart.detailList[i].Quantity); } cart.Total = total; Session["CART"] = cart; } return(View("ViewCart")); }
public ActionResult ConfirmCart() { Order cart = Session["CART"] as Order; PhoneDAO dao = new PhoneDAO(); bool isEnough = true; string name = "bủh"; CartDAO cartDAO = new CartDAO(); for (int i = 0; i < cart.detailList.Count; i++) { if (cart.detailList[i].Quantity > dao.GetProductDetail(cart.detailList[i].IDProduct).Quantity) { isEnough = false; name = cart.detailList[i].ProductName; } } if (!isEnough) { ViewBag.INSUFF = "There is not enough quantity of " + name + " for you! Please choose another products or decrease the amount!"; return(View("ViewCart")); } else { bool isCartOk = cartDAO.AddCart(cart); PhoneDAO phoneDao = new PhoneDAO(); bool isAllOk = true; if (isCartOk) { bool[] isDetailsOk = new bool[cart.detailList.Count]; bool[] isUpdateOk = new bool[cart.detailList.Count]; for (int i = 0; i < isDetailsOk.Length; i++) { isDetailsOk[i] = cartDAO.AddOrder(cart.detailList[i]); } for (int i = 0; i < isDetailsOk.Length; i++) { Product p = new Product(cart.detailList[i].IDProduct, cart.detailList[i].Store - cart.detailList[i].Quantity); isUpdateOk[i] = phoneDao.UpdateProductAfterAddCart(p); } for (int i = 0; i < isDetailsOk.Length; i++) { if (!isDetailsOk[i]) { isAllOk = false; } } for (int i = 0; i < isUpdateOk.Length; i++) { if (!isUpdateOk[i]) { isAllOk = false; } } if (!isAllOk) { return(Redirect(Url.Action("Error", "Phone"))); } else { Session.Remove("CART"); return(Redirect(Url.Action("LoadList", "Phone"))); } } else { return(Redirect(Url.Action("Error", "Phone"))); } } }