public void SetPublish() { //Arrange ResetDataBase(); ProductCategoriesBL target = DI.Resolve <ProductCategoriesBL>(); ProductsBL productsBl = DI.Resolve <ProductsBL>(); //Act target.SetPublish(65, false); //Asserts Assert.That(!target.GetById(65).Publish); Assert.That(!productsBl.GetById(86).Publish); Assert.That(!productsBl.GetById(87).Publish); Assert.That(!productsBl.GetById(88).Publish); Assert.That(!productsBl.GetById(89).Publish); Assert.That(!productsBl.GetById(90).Publish); Assert.That(!productsBl.GetById(91).Publish); Assert.That(!productsBl.GetById(92).Publish); Assert.That(!productsBl.GetById(93).Publish); Assert.That(!productsBl.GetById(95).Publish); }
public ActionResult Save(ProductCategoryCreateOrEditViewModel model) { if (ModelState.IsValid) { if (_productCategoriesBL.GetCategories(model.ParentId).Any(productCategory => productCategory.Name == model.Name && productCategory.Id != model.Id)) { ModelState.AddModelError("Name", "Така категорія вже існує"); } if (ModelState.IsValid) { ProductCategory productCategory; if (model.Id.HasValue) { productCategory = _productCategoriesBL.GetById(model.Id.Value); productCategory.Name = model.Name; productCategory.Description = model.Description; if (model.PostedPhoto != null) { productCategory.Photo = _photosBL.UpdateOrAdd(productCategory.Photo, model.PostedPhoto); } _productCategoriesBL.Update(productCategory); if (productCategory.Publish != model.Publish) { _productCategoriesBL.SetPublish(productCategory.Id, model.Publish); } } else { productCategory = new ProductCategory { ParentId = model.ParentId, Name = model.Name, Description = model.Description, Publish = model.Publish, }; if (model.PostedPhoto != null) { productCategory.Photo = _photosBL.UpdateOrAdd(null, model.PostedPhoto); } _productCategoriesBL.Create(productCategory); } ProductCategoriesFilterViewModel filterViewModel = new ProductCategoriesFilterViewModel(); filterViewModel.ParentCategory.Id = model.ParentId; if (model.ParentId.HasValue) { filterViewModel.ParentCategory.Name = _productCategoriesBL.GetById(model.ParentId.Value).Name; } TempData[Constants.TempDataKeys.PRODUCT_CATEGORIES_PARENT_ID] = model.ParentId; return(RedirectToAction("Index")); } } return(View("Edit", model)); }
public void TogglePublish(int id) { ProductCategory productCategory = _productCategoriesBL.GetById(id); _productCategoriesBL.SetPublish(id, !productCategory.Publish); }