public ActionResult Edit(int id) { var product = AgriculturalProductSvc.LoadById(id); var model = new AgriculturalProductEditModel(product); return View(model); }
public ActionResult Create(AgriculturalProductEditModel model) { if (!ModelState.IsValid) { ModelState.AddModelError(string.Empty, "请输入正确的信息"); return View(model); } IIdentity identity = HttpContext.User.Identity; model.InsertByUserName = identity.Name; model.ProductStatus = ProductStatus.Procreative; AgriculturalProductSvc.Insert(model.ToAgriculturalProduct()); return RedirectToAction("Index"); }
public ActionResult Edit(AgriculturalProductEditModel model) { if (!ModelState.IsValid) { ModelState.AddModelError(string.Empty, "请输入正确的信息!"); return View(model); } var product = AgriculturalProductSvc.LoadById(model.Id); if (product.ProductStatus != ProductStatus.Procreative || product.SecurityStatus != SecurityStatus.Safe) { ModelState.AddModelError(string.Empty, "此产品无法被修改!"); return View(model); } IIdentity identity = HttpContext.User.Identity; var user = UserSvc.LoadByUserName(identity.Name); if (user.Company.Id != product.ProductOwner.Id) { ModelState.AddModelError(string.Empty, "你无权限修改此产品!"); return View(model); } model.ProductStatus = ProductStatus.Procreative; AgriculturalProductSvc.Update(model.ToAgriculturalProduct()); return RedirectToAction("Index"); }
public ActionResult Create() { var model = new AgriculturalProductEditModel(); return View(model); }