Exemple #1
0
        public ActionResult Save(ProductCategoryArticleEditViewModel model)
        {
            ProductCategory productCategory = _productCategoriesBL.GetById(model.Id.Value);

            productCategory.Article = model.Text;
            _productCategoriesBL.Update(productCategory);

            return(RedirectToAction("Index", new
            {
                parentCategoryId = model.Id.Value
            }));
        }
Exemple #2
0
        public ActionResult Save(ProductCategoryCreateOrEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (_productCategoriesBL.GetCategories(model.ParentId).Any(productCategory => productCategory.Name == model.Name && productCategory.Id != model.Id))
                {
                    ModelState.AddModelError("Name", "Така категорія вже існує");
                }

                if (ModelState.IsValid)
                {
                    ProductCategory productCategory;

                    if (model.Id.HasValue)
                    {
                        productCategory             = _productCategoriesBL.GetById(model.Id.Value);
                        productCategory.Name        = model.Name;
                        productCategory.Description = model.Description;

                        if (model.PostedPhoto != null)
                        {
                            productCategory.Photo = _photosBL.UpdateOrAdd(productCategory.Photo, model.PostedPhoto);
                        }

                        _productCategoriesBL.Update(productCategory);

                        if (productCategory.Publish != model.Publish)
                        {
                            _productCategoriesBL.SetPublish(productCategory.Id, model.Publish);
                        }
                    }
                    else
                    {
                        productCategory = new ProductCategory
                        {
                            ParentId    = model.ParentId,
                            Name        = model.Name,
                            Description = model.Description,
                            Publish     = model.Publish,
                        };

                        if (model.PostedPhoto != null)
                        {
                            productCategory.Photo = _photosBL.UpdateOrAdd(null, model.PostedPhoto);
                        }

                        _productCategoriesBL.Create(productCategory);
                    }

                    ProductCategoriesFilterViewModel filterViewModel = new ProductCategoriesFilterViewModel();
                    filterViewModel.ParentCategory.Id = model.ParentId;

                    if (model.ParentId.HasValue)
                    {
                        filterViewModel.ParentCategory.Name = _productCategoriesBL.GetById(model.ParentId.Value).Name;
                    }

                    TempData[Constants.TempDataKeys.PRODUCT_CATEGORIES_PARENT_ID] = model.ParentId;
                    return(RedirectToAction("Index"));
                }
            }

            return(View("Edit", model));
        }