public ActionResult Edit(ProductCategoryItem item)
 {
     try
     {
         Service.ProductCategory.Save(item);
         return RedirectToRouteNotify("EditProductCategory", new { id = item.Id });
     }
     catch (ValidationException ex)
     {
         AddModelErrors(ex);
         Service.ProductCategory.AppendData(item);
         return View("~/Views/Admin/ProductCategories/Edit.cshtml", item);
     }
 }
Ejemplo n.º 2
0
        public void Save(ProductCategoryItem item)
        {
            var errors = item.GetValidationErrors();
            errors.ThrowIfHasErrors();

            var category = item.Id == 0 ? Db.CreateAndAdd<tblProductCategory>() : Db.Set<tblProductCategory>().Single(x => x.Id == item.Id);

            category.Name = item.Name;
            category.ParentCategoryId = item.ParentCategoryId;

            Db.SaveChanges();

            item.Id = category.Id;
        }
Ejemplo n.º 3
0
        public ProductCategoryItem Edit(long id)
        {
            var category = new ProductCategoryItem();
            if (id != 0)
            {
                category = Db.Set<tblProductCategory>()
                    .Select(x => new ProductCategoryItem
                    {
                        Id = x.Id,
                        Name = x.Name,
                        ParentCategoryId = x.ParentCategoryId,
                        ParentCategoryName = x.ParentCategoryId != null ? x.tblProductCategory2.Name : ""
                    })
                    .Single(x => x.Id == id);
            }

            AppendData(category);

            return category;
        }
Ejemplo n.º 4
0
 public void AppendData(ProductCategoryItem item)
 {
     item.AvaliableCategories = item.Id == 0
         ? AllRoot()
         : AllRoot().Where(x => x.Id != item.Id).ToList();
 }