コード例 #1
0
        public ActionResult Edit(int id)
        {
            var product = AgriculturalProductSvc.LoadById(id);

            var model = new AgriculturalProductEditModel(product);

            return View(model);
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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");
        }
コード例 #4
0
 public ActionResult Create()
 {
     var model = new AgriculturalProductEditModel();
     return View(model);
 }