コード例 #1
0
        public IHttpActionResult CreateProductCategory(ProductCategoryModel categoryModel)
        {
            var category = categoryModel.ToEntity();

            _categoryService.InsertProductCategory(category);

            //activity log
            _customerActivityService.InsertActivity("AddNewProductCategory", "增加 名为 {0} 的商品类别", category.Name);

            //SuccessNotification(_localizationService.GetResource("Admin.Catalog.Categories.Added"));

            return(Ok(category.ToModel()));
        }
コード例 #2
0
        public ActionResult Edit(ProductCategoryModel model, FormCollection frm, bool continueEditing)
        {
            if (!_permissionService.Authorize("ManageProducts"))
            {
                return(AccessDeniedView());
            }

            // Check for duplicate classroom, if any
            var checkCategory = _smsService.CheckProductCategoryExists(model.Name, model.Id);

            if (checkCategory)
            {
                ModelState.AddModelError("Name", "A Category with the same name already exists. Please choose a different name.");
            }

            if (ModelState.IsValid)
            {
                var objCategory = _smsService.GetProductCategoryById(model.Id);
                if (objCategory != null)
                {
                    objCategory            = model.ToEntity(objCategory);
                    objCategory.ModifiedOn = DateTime.Now;
                    _smsService.UpdateProductCategory(objCategory);

                    // Save URL Record
                    model.SystemName = objCategory.ValidateSystemName(model.SystemName, model.Name, true);
                    _urlService.SaveSlug(objCategory, model.SystemName);
                }
            }
            else
            {
                var allProductCategories = _smsService.GetAllProductCategories().Where(x => x.Id != model.Id && x.ParentCategoryId != x.Id).OrderBy(x => x.DisplayOrder).ToList();
                model.AvailableProductCategories = allProductCategories.Select(x => new SelectListItem()
                {
                    Text     = x.Name.Trim(),
                    Value    = x.Id.ToString(),
                    Selected = model.ParentCategoryId == x.Id
                }).ToList();
                return(View(model));
            }

            SuccessNotification("Category updated successfully.");
            if (continueEditing)
            {
                return(RedirectToAction("Edit", new { id = model.Id }));
            }
            return(RedirectToAction("List"));
        }
コード例 #3
0
        public IHttpActionResult UpdateProductCategory(int productCategoryId, ProductCategoryModel categoryModel)
        {
            var category = _categoryService.GetProductCategoryById(productCategoryId);

            if (category == null || category.Deleted)
            {
                return(NotFound());
            }

            category = categoryModel.ToEntity(category);

            _categoryService.UpdateProductCategory(category);

            //activity log
            _customerActivityService.InsertActivity("UpdateProductCategory", "更新 名为 {0} 的商品类别", category.Name);

            return(Ok(category.ToModel()));
        }