Ejemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "OrderDetailID,OrderID,ProductID,ProductName,ProductCode,UnitPrice,Quantity,PromotionPrice,CreateDate,CreateUser,ModifiedDate,ModifiedUser,IsActive")] OrderDetail orderDetail)
        {
            var UserSession = (UserLogin)Session[TechDeviShopVs002.Common.CommonConstants.USER_SESSION];

            if (ModelState.IsValid)
            {
                var _dal = new OrderDetailsDAL();

                orderDetail.ModifiedUser = UserSession.UserID;
                var pd = new ProductDAL().ViewDetail(orderDetail.ProductID);
                orderDetail.ProductName    = pd.ProductName;
                orderDetail.ProductCode    = pd.ProductCode;
                orderDetail.UnitPrice      = pd.Price;
                orderDetail.PromotionPrice = pd.PromotionPrice;

                var _result = _dal.Update(orderDetail);
                if (_result)
                {
                    return(RedirectToAction("Index", "orderDetails"));
                }
                else
                {
                    ModelState.AddModelError("", "Cập nhật chi tiết hóa đơn ko thành công");
                }
            }
            ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "OrderID", orderDetail.OrderID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", orderDetail.ProductID);
            //ViewBag.ProductName = new SelectList(db.Products, "ProductName", "ProductName", orderDetail.ProductName);
            //ViewBag.ProductCode = new SelectList(db.Products, "ProductCode", "ProductCode", orderDetail.ProductCode);
            //ViewBag.UnitPrice = new SelectList(db.Products, "UnitPrice", "Price", orderDetail.UnitPrice);
            //ViewBag.PromotionPrice = new SelectList(db.Products, "PromotionPrice", "PromotionPrice", orderDetail.PromotionPrice);
            return(View(orderDetail));
        }