示例#1
0
        public ActionResult CategoryProductAttributeInsert(GridCommand command, CategoryProductAttributeModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var pva = new CategoryProductAttribute()
            {
                CategoryProductGroupId = model.CategoryProductGroupId,
                ProductAttributeId     = Int32.Parse(model.ProductAttribute), //use ProductAttribute property (not ProductAttributeId) because appropriate property is stored in it
                TextPrompt             = model.TextPrompt,
                IsRequired             = model.IsRequired,
                MainAttribute          = model.MainAttribute,
                ProductBoxAttribute    = model.ProductBoxAttribute,
                AdditionalAttribute    = model.AdditionalAttribute,
                AttributeControlTypeId = Int32.Parse(model.AttributeControlType), //use AttributeControlType property (not AttributeControlTypeId) because appropriate property is stored in it
                SearchControlTypeId    = Int32.Parse(model.SearchAttributeControlType),
                DisplayOrder           = model.DisplayOrder1
            };

            bool flag       = false;
            var  categories = _categoryService.GetAllCategories().Where(x => x.CategoryToCategoryProductAttributeGroups.Where(g => g.CategoryProductAttributeGroupId == model.CategoryProductGroupId).FirstOrDefault() != null);

            foreach (var category in categories)
            {
                foreach (var group in category.CategoryToCategoryProductAttributeGroups.Where(x => x.CategoryProductAttributeGroupId != model.CategoryProductGroupId)
                         .Select(x => x.CategoryProductAttributeGroup))
                {
                    var attr = group.CategoryProductAttributes.Where(x => x.ProductAttributeId == pva.ProductAttributeId).FirstOrDefault();
                    if (attr != null)
                    {
                        flag = true;
                    }
                }
            }

            string conflictMessage = "";

            conflictMessage = ValidateForConflict(pva);
            //productAttribute.
            if (!flag)
            {
                if (!String.IsNullOrEmpty(conflictMessage))
                {
                    ModelState.AddModelError("ProductAttribute", conflictMessage);
                    var modelStateErrors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                    return(Content(modelStateErrors.FirstOrDefault()));
                }
                _categoryProductAttributeService.InsertCategoryProductAttribute(pva);
            }
            else
            {
                ModelState.AddModelError("ProductAttribute", "Category attribute group conflict");
                var modelStateErrors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            return(CategoryProductAttributeList(command, model.CategoryProductGroupId));
        }
示例#2
0
        public ActionResult CategoryProductAttributeList(GridCommand command, int categoryProductGroupId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var categoryProductAttributes      = _categoryProductAttributeService.GetCategoryProductAttributesByCategoryProductGroupId(categoryProductGroupId);
            var categoryProductAttributesModel = categoryProductAttributes
                                                 .Select(x =>
            {
                var pvaModel = new CategoryProductAttributeModel()
                {
                    Id = x.Id,
                    CategoryProductGroupId       = x.CategoryProductGroupId,
                    ProductAttribute             = _productAttributeService.GetProductAttributeById(x.ProductAttributeId).Name,
                    ProductAttributeId           = x.ProductAttributeId,
                    SearchAttributeControlTypeId = x.SearchControlTypeId,
                    SearchAttributeControlType   = x.SearchControlType.GetLocalizedEnum(_localizationService, _workContext),
                    TextPrompt             = x.TextPrompt,
                    IsRequired             = x.IsRequired,
                    AdditionalAttribute    = x.AdditionalAttribute,
                    MainAttribute          = x.MainAttribute,
                    AttributeControlType   = x.AttributeControlType.GetLocalizedEnum(_localizationService, _workContext),
                    AttributeControlTypeId = x.AttributeControlTypeId,
                    DisplayOrder1          = x.DisplayOrder,
                    ProductBoxAttribute    = x.ProductBoxAttribute
                };

                if (x.ShouldHaveValues())
                {
                    pvaModel.ViewEditUrl  = Url.Action("EditCategoryProductAttributeValues", "CategoryAttributes", new { categoryProductAttributeId = x.Id });
                    pvaModel.ViewEditText = string.Format(_localizationService.GetResource("Admin.Catalog.CategoryProductAttributes.Attributes.Values.ViewLink"), x.CategoryProductAttributeValues != null ? x.CategoryProductAttributeValues.Count : 0);
                }
                return(pvaModel);
            })
                                                 .ToList();

            var model = new GridModel <CategoryProductAttributeModel>
            {
                Data  = categoryProductAttributesModel,
                Total = categoryProductAttributesModel.Count
            };

            return(new JsonResult
            {
                Data = model
            });
        }
示例#3
0
 public static CategoryProductAttribute ToEntity(this CategoryProductAttributeModel model, CategoryProductAttribute destination)
 {
     return(Mapper.Map(model, destination));
 }
示例#4
0
 public static CategoryProductAttribute ToEntity(this CategoryProductAttributeModel model)
 {
     return(Mapper.Map <CategoryProductAttributeModel, CategoryProductAttribute>(model));
 }
示例#5
0
        public ActionResult CategoryProductAttributeUpdate(GridCommand command, CategoryProductAttributeModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var pva = _categoryProductAttributeService.GetCategoryProductAttributeById(model.Id);

            if (pva == null)
            {
                throw new ArgumentException("No product variant attribute found with the specified id");
            }

            //use ProductAttribute property (not ProductAttributeId) because appropriate property is stored in it
            pva.ProductAttributeId  = Int32.Parse(model.ProductAttribute);
            pva.TextPrompt          = model.TextPrompt;
            pva.IsRequired          = model.IsRequired;
            pva.MainAttribute       = model.MainAttribute;
            pva.ProductBoxAttribute = model.ProductBoxAttribute;
            pva.AdditionalAttribute = model.AdditionalAttribute;
            //use AttributeControlType property (not AttributeControlTypeId) because appropriate property is stored in it
            if (pva.AttributeControlTypeId != Int32.Parse(model.AttributeControlType))
            {
                foreach (var val in pva.CategoryProductAttributeValues.ToList())
                {
                    _categoryProductAttributeService.DeleteCategoryProductAttributeValue(val);
                }
            }
            pva.AttributeControlTypeId = Int32.Parse(model.AttributeControlType);

            pva.SearchControlTypeId = Int32.Parse(model.SearchAttributeControlType);
            pva.DisplayOrder        = model.DisplayOrder1;

            bool flag       = false;
            var  categories = _categoryService.GetAllCategories().Where(x => x.CategoryToCategoryProductAttributeGroups.Where(g => g.CategoryProductAttributeGroupId == pva.CategoryProductGroupId).FirstOrDefault() != null);

            foreach (var category in categories)
            {
                foreach (var group in category.CategoryToCategoryProductAttributeGroups.Where(x => x.CategoryProductAttributeGroupId != pva.CategoryProductGroupId)
                         .Select(x => x.CategoryProductAttributeGroup))
                {
                    var attr = group.CategoryProductAttributes.Where(x => x.ProductAttributeId == pva.ProductAttributeId).FirstOrDefault();
                    if (attr != null)
                    {
                        flag = true;
                    }
                }
            }
            //productAttribute.
            string conflictMessage = "";

            conflictMessage = ValidateForConflict(pva);
            if (!flag)
            {
                if (!String.IsNullOrEmpty(conflictMessage))
                {
                    ModelState.AddModelError("ProductAttribute", conflictMessage);
                    var modelStateErrors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                    return(Content(modelStateErrors.FirstOrDefault()));
                }
                _categoryProductAttributeService.UpdateCategoryProductAttribute(pva);
            }
            else
            {
                ModelState.AddModelError("ProductAttribute", "Category attribute group conflict");
                var modelStateErrors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }
            return(CategoryProductAttributeList(command, pva.CategoryProductGroupId));
        }