Esempio n. 1
0
        public virtual async Task <ActionResult> Edit(EditProductViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                _productService.Update(viewModel);
                if (viewModel.OldCategoryId != viewModel.CategoryId)
                {
                    _valueService.RemoveByProductId(viewModel.Id);
                    var attributes = _attributeService.GetAttributesByCategoryId(viewModel.CategoryId);
                    _valueService.AddCategoryAttributesToProduct(attributes, viewModel.Id);
                }

                await _unitOfWork.SaveChangesAsync();

                LuceneProducts.UpdateIndex(new ProductLuceneViewModel
                {
                    Name        = viewModel.Name,
                    Id          = viewModel.Id,
                    ImagePath   = viewModel.PrincipleImagePath,
                    Description = viewModel.Description
                });
                CacheManager.InvalidateChildActionsCache();
                return(RedirectToAction(MVC.Admin.Product.ActionNames.Index, MVC.Admin.Product.Name));
            }

            PopulateCategoriesDropDownList(viewModel.CategoryId);
            if (!ModelState.IsValidField("CategoryId"))
            {
                ModelState.AddModelError("", "گروه محصول را مشخص  کنید");
            }
            return(View(viewModel));
        }