public ActionResult ProductUpdate(int order_id, [Bind(Include = "id, product_name, qty, price")] QuestionsSYS.ModelViews.Product model) { var user_id = User.Identity.GetUserId(); var order = db.orders; order.Where(o => o.id == order_id); if (!User.IsInRole("Admin")) { order.Where(o => o.user_id == user_id && o.id == order_id); } ; var order_detail = order.FirstOrDefault(); if (order_detail != null && order_detail.state == "Onay Bekliyor") { var is_exist_product = db.order_products.Where(o => o.orderId == order_id && o.product_name == model.product_name).ToList(); if (is_exist_product != null && is_exist_product.Count > 1) { return(RedirectToAction("Detail", new RouteValueDictionary(new { controller = "Order", action = "Detail", id = order_id, exist_product = "1" }))); } OrderProduct op_ = db.order_products.Where(opp => opp.id == model.id).FirstOrDefault(); if (op_ != null) { op_.price = model.price; op_.qty = model.qty; op_.product_name = model.product_name; db.SaveChanges(); calculateOrderTotal(order_id); } return(RedirectToAction("Detail", new RouteValueDictionary(new { controller = "Order", action = "Detail", id = order_id, success = "ok" }))); } return(new HttpStatusCodeResult(500)); }
public ActionResult ProductsAdd(int id, [Bind(Include = "id, product_name, qty, price")] QuestionsSYS.ModelViews.Product model) { var user_id = User.Identity.GetUserId(); Order order; if (!User.IsInRole("Admin")) { order = db.orders.Where(o => o.user_id == user_id && o.id == id).FirstOrDefault(); } else { order = db.orders.Where(o => o.id == id).FirstOrDefault(); } if (order != null && order.state == "Onay Bekliyor") { var is_exist_product = db.order_products.Where(o => o.orderId == id && o.product_name == model.product_name).FirstOrDefault(); if (is_exist_product != null) { return(RedirectToAction("Detail", new RouteValueDictionary(new { controller = "Order", action = "Detail", id = id, exist_product = "1" }))); } OrderProduct op = new OrderProduct { price = model.price, product_name = model.product_name, qty = model.qty, orderId = id }; db.order_products.Add(op); db.SaveChanges(); calculateOrderTotal(id); return(RedirectToAction("Detail", new RouteValueDictionary(new { controller = "Order", action = "Detail", id = id, success = "ok" }))); } return(new HttpStatusCodeResult(500)); }