public ActionResult PurchasePrice(int id, int? productId,FormCollection collection) { if (!UserInfo.CurUser.HasRight("业务管理-产品采购价格录入")) return Redirect("~/content/AccessDeny.htm"); ProductPurchasePrice price = null; if (id != 0) { price = db.ProductPurchasePrices.Find(id); } else { price = new ProductPurchasePrice { ProductId = (int)productId, ActivateDate = DateTime.Today, State = PriceState.Activate }; db.ProductPurchasePrices.Add(price); } Product p=db.Products.Find(price.ProductId); TryUpdateModel(price, "", new string[] { }, new string[] { }, collection); if (ModelState.IsValid) { if(price.State==PriceState.Activate) p.PurchasePrice = price.PurchasePrice; if(id==0) { (from o in db.ProductPurchasePrices where o.ProductId == price.ProductId && o.State == PriceState.Activate select o).ToList().ForEach(o => o.State = PriceState.Old); } db.SaveChanges(); if (id == 0) { BLL.Utilities.AddLogAndSave(price.ProductId, Product.LogClass, "增加采购报价记录", price.PurchasePrice.ToString()); } else { BLL.Utilities.AddLogAndSave(price.ProductId, Product.LogClass, "修改采购报价记录", price.PurchasePrice.ToString()); } return Redirect("~/content/close.htm"); } ViewBag.Product = p; return View(price); }
public ActionResult PurchasePrice(int id,int? productId) { if (!UserInfo.CurUser.HasRight("业务管理-产品修改")) return Redirect("~/content/AccessDeny.htm"); ProductPurchasePrice price = null; if(id!=0) { price = db.ProductPurchasePrices.Find(id); } else { price = new ProductPurchasePrice {ProductId = (int) productId}; } ViewBag.Product = db.Products.Find(price.ProductId); return View(price); }