Ejemplo n.º 1
0
        public ActionResult EditProductCategory(ProductCategory model)
        {
            if (!ModelState.IsValid) {
                return View();
            }
            if (model.Id == 0) {
                try {
                    context.ProductCategory.Add(model);
                    context.SaveChanges();
                }
                catch (Exception ex) {
                    ModelState.AddModelError("DbError", ex.Message);
                    return View();
                }
            }
            else {
                var old = context.ProductCategory.SingleOrDefault(t => t.Id == model.Id);
                old.Name = model.Name;
                old.Series = model.Series;
                old.Cover = model.Cover;
                old.ParentId = model.ParentId;
                context.SaveChanges();

            }
            TempData[StaticDefination.TmpSuccessMsg] = "操作成功!";
            return RedirectToAction("ProductCategory");
        }
Ejemplo n.º 2
0
 public ActionResult EditProductCategory(int? id,int? pid)
 {
     var m = new ProductCategory();
     if (id.HasValue) {
         var old = context.ProductCategory.SingleOrDefault(t => t.Id == id.Value);
         m = old ?? m;
     }
     if (pid.HasValue) {
         m.ParentId = pid.Value;
         m.ParentNode = context.ProductCategory.SingleOrDefault(t => t.Id == pid.Value);
     }
     return View(m);
 }