Exemple #1
0
        public virtual async Task <ActionResult> EditAttribute(EditAttributeViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            var attribute = _attributeService.GetAttributeById(viewModel.Id);
            var oldName   = attribute.Name;

            attribute.Name = viewModel.Name;
            var status = _attributeService.Edit(attribute);

            if (!status)
            {
                ModelState.AddModelError("Name", "این ویژگی قبلا برای این گروه ثبت شده است");
                return(View(viewModel));
            }
            if (viewModel.CascadeAddForChildren)
            {
                var category = _categoryService.GetById(viewModel.CategoryId);
                EditAttributeForChildrenCacade(oldName, viewModel.Name, category);
            }
            await _unitOfWork.SaveChangesAsync();

            return(RedirectToAction(MVC.Admin.Category.ActionNames.AttributeList, MVC.Admin.Category.Name,
                                    new { categoryId = viewModel.CategoryId }));
        }