예제 #1
0
        public ActionResult AddInward(Inward entity)
        {
            var res = new InwardBusiness().addInward(entity);

            if (res)
            {
                var cart = (List <CartDTO>)Session["add_inward"];
                foreach (var item in cart)
                {
                    var detail = new Inward_Detail();
                    detail.Inward_ID  = db.Inwards.Max(x => x.ID);
                    detail.Product_ID = item.Product.ID;
                    detail.Quantity   = item.Quantity;

                    if (item.Product.Price != null)
                    {
                        detail.Price  = item.Product.Price;
                        detail.Amount = (int)item.Product.Price * item.Quantity;
                    }
                    else
                    {
                        detail.Price  = item.Product.Promotion_Price;
                        detail.Amount = (int)item.Product.Promotion_Price * item.Quantity;
                    }
                    new InwardBusiness().addInward_Detail(detail);

                    //Cộng tồn kho
                    new ProductBusiness().AddQuantity(item.Product.ID, item.Quantity);
                }
                Session["add_order"]    = null;
                TempData["add_success"] = "Nhập kho thành công.";
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Add"));
            }
        }
 public void addInward_Detail(Inward_Detail entity)
 {
     db.Inward_Detail.Add(entity);
     db.SaveChanges();
 }