Exemplo n.º 1
0
 protected void SaveSelectedCategoryProductAttributeGroup(Category category, CategoryModel model)
 {
     if (model.CategoryProductAttributeGroupId > 0)
     {
         var ctcpavg = _categoryProductAttributeService.GetCategoryToCategoryProductAttributeGroupByCategoryIdAndGroupId(category.Id, model.CategoryProductAttributeGroupId);
         if (ctcpavg == null)
         {
             //new item
             var map = new CategoryToCategoryProductAttributeGroup()
             {
                 CategoryId = category.Id,
                 CategoryProductAttributeGroupId = model.CategoryProductAttributeGroupId
             };
             _categoryProductAttributeService.InsertCategoryToCategoryProductAttributeGroup(map);
         }
         else
         {
             //updated item
             if (ctcpavg.CategoryProductAttributeGroupId != model.CategoryProductAttributeGroupId)
             {
                 ctcpavg.CategoryProductAttributeGroupId = model.CategoryProductAttributeGroupId;
                 _categoryProductAttributeService.UpdateCategoryToCategoryProductAttributeGroup(ctcpavg);
             }
         }
     }
 }
Exemplo n.º 2
0
        public ActionResult CategoryProductAttributeGroupAdd(string categoryGroupId, string categoryId)
        {
            int  intCategoryGroupId = 0;
            int  intCategoryId      = 0;
            bool resCategoryGroupId = Int32.TryParse(categoryGroupId, out intCategoryGroupId);
            bool resCategoryId      = Int32.TryParse(categoryId, out intCategoryId);

            if (resCategoryGroupId && resCategoryId)
            {
                CategoryToCategoryProductAttributeGroup ctc = new CategoryToCategoryProductAttributeGroup()
                {
                    CategoryId = intCategoryId,
                    CategoryProductAttributeGroupId = intCategoryGroupId
                };
                var catAttrGr = _categoryProductAttributeService.GetCategoryToCategoryProductAttributeGroupByCategoryIdAndGroupId(intCategoryId, intCategoryGroupId);
                if (catAttrGr == null)
                {
                    var  groups = _categoryService.GetCategoryById(intCategoryId).CategoryToCategoryProductAttributeGroups.Select(x => x.CategoryProductAttributeGroup);
                    var  grp    = _categoryProductAttributeService.GetCategoryProductAttributeGroupById(intCategoryGroupId);
                    bool result = false;
                    foreach (var group in groups)
                    {
                        foreach (var attr in group.CategoryProductAttributes)
                        {
                            var attr_exist = grp.CategoryProductAttributes.Where(x => x.ProductAttributeId == attr.ProductAttributeId).FirstOrDefault();
                            if (attr_exist != null)
                            {
                                result = true;
                            }
                        }
                    }
                    if (!result)
                    {
                        _categoryProductAttributeService.InsertCategoryToCategoryProductAttributeGroup(ctc);
                    }
                    else
                    {
                        return(Content("Group has attribute that was already defined in other attribute group attached to this category!"));
                    }
                }

                return(Content("Success"));
            }
            return(RedirectToAction("List"));
        }
Exemplo n.º 3
0
        private void InsertCategory(ExportCategory category, List <ExportCategory> categoryList, List <ExportProductAttributeValueList> productAttributeValueLists)
        {
            int parentCategoryId = 0;

            if (category.ParentCategoryId != 0)
            {
                parentCategoryId = categoryList.Where(x => x.CategoryId == category.ParentCategoryId).FirstOrDefault().RecievedId;
            }
            int groupId = 0;

            if (category.AttributeValueListId != 0 && category.AttributeValueListId != int.MaxValue)
            {
                groupId = productAttributeValueLists.Where(x => x.Id == category.AttributeValueListId).First().RecievedId;
            }
            var newCategory = new Category()
            {
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow,
                Published        = true,
                DisplayOrder     = 0,
                Name             = category.Title,
                ParentCategoryId = parentCategoryId,
            };

            _categoryService.InsertCategory(newCategory);
            _localizedEntityService.SaveLocalizedValue(newCategory, x => x.Name, category.Title, 1);
            _localizedEntityService.SaveLocalizedValue(newCategory, x => x.Name, category.TitleRu, 2);
            _localizedEntityService.SaveLocalizedValue(newCategory, x => x.Name, category.TitleDe, 3);
            _localizedEntityService.SaveLocalizedValue(newCategory, x => x.Name, category.TitleEs, 4);

            category.RecievedId = newCategory.Id;

            if (groupId != 0)
            {
                var categoryToCategoryAttributeGroup = new CategoryToCategoryProductAttributeGroup()
                {
                    CategoryId = category.RecievedId,
                    CategoryProductAttributeGroupId = groupId,
                    DisplayOrder = 0
                };
                _categoryProductAttributeService.InsertCategoryToCategoryProductAttributeGroup(categoryToCategoryAttributeGroup);
            }
        }