Exemplo n.º 1
0
        public ActionResult CopyAttributePopUp(CategoryAttributeCopyModel model, string btnId, string formId)
        {
            var    categoryProductAttributeGroup = _categoryProductAttributeService.GetCategoryProductAttributeGroupById(model.CategoryProductAttributeGroupId);
            var    categoryProductAttribute      = _categoryProductAttributeService.GetCategoryProductAttributeById(model.CategoryProductAttributeId);
            string attributeName = categoryProductAttribute.ProductAttribute.Name;
            var    sourceCategoryProductAttribute = categoryProductAttributeGroup.CategoryProductAttributes.Where(x => x.ProductAttribute.Name == attributeName).FirstOrDefault();

            if (sourceCategoryProductAttribute == null)
            {
                ModelState.AddModelError("CategoryProductAttributeGroupId", _localizationService.GetResource(""));
            }

            foreach (var val in categoryProductAttribute.CategoryProductAttributeValues.ToList())
            {
                _categoryProductAttributeService.DeleteCategoryProductAttributeValue(val);
            }

            var values = categoryProductAttributeGroup.CategoryProductAttributes.Where(x => x.ProductAttribute.Name == attributeName).FirstOrDefault().CategoryProductAttributeValues;

            foreach (var val in values)
            {
                var newAttributeValue = new CategoryProductAttributeValue()
                {
                    CategoryProductAttributeId = categoryProductAttribute.Id,
                    DisplayOrder    = val.DisplayOrder,
                    IsPreSelected   = val.IsPreSelected,
                    Name            = val.Name,
                    ColorSquaresRgb = val.ColorSquaresRgb,
                    CurrencyId      = val.CurrencyId,
                    PopularValue    = val.PopularValue,
                    RealValue       = val.RealValue,
                    RealValueMax    = val.RealValueMax,
                };
                _categoryProductAttributeService.InsertCategoryProductAttributeValue(newAttributeValue);
            }

            var categoryProductAttributeGroups = _categoryProductAttributeService.GetAllCategoryProductAttributeGroups();

            model.AviableGroups = categoryProductAttributeGroups.Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(), Text = x.GetLocalized(c => c.Name, _workContext.WorkingLanguage.Id)
            }).ToList();
            ViewBag.RefreshPage = true;
            ViewBag.btnId       = btnId;
            ViewBag.formId      = formId;
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult CopyAttributePopUp(int categoryProductAttributeId)
        {
            var    categoryProductAttribute       = _categoryProductAttributeService.GetCategoryProductAttributeById(categoryProductAttributeId);
            string attributeName                  = categoryProductAttribute.ProductAttribute.Name;
            var    categoryProductAttributeGroups = _categoryProductAttributeService.GetAllCategoryProductAttributeGroups()
                                                    .Where(x => x.CategoryProductAttributes.Where(a => a.ProductAttribute.Name == attributeName).FirstOrDefault() != null &&
                                                           x.Id != categoryProductAttribute.CategoryProductGroupId);
            var model = new CategoryAttributeCopyModel()
            {
                CategoryProductAttributeId = categoryProductAttributeId
            };

            model.AviableGroups = categoryProductAttributeGroups.Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(), Text = x.GetLocalized(c => c.Name, _workContext.WorkingLanguage.Id)
            }).ToList();

            return(View(model));
        }