Пример #1
0
        public ActionResult Edit(int id, int?categoryId)
        {
            Product product = _productsBL.GetById(id);

            if (!categoryId.HasValue)
            {
                categoryId = product.Categories.First().Id;
            }

            ProductCreateOrEditViewModel model = new ProductCreateOrEditViewModel
            {
                Name             = product.Name,
                ShortDescription = product.ShortDescription,
                Description      = product.Description,
                Id                     = product.Id,
                BrandName              = product.Brand.Name,
                CountryName            = product.CountryProducer.Name,
                Price                  = product.Price.ToString(),
                Publish                = product.Publish,
                Code                   = product.Code,
                Currencies             = _currenciesBL.GetAll(),
                CurrencyIdOfThePrice   = product.CurrencyIdOfThePrice,
                PriceInTheMainCurrency = product.PriceInTheMainCurrency
            };

            if (product.MetaData != null)
            {
                model.MetaDataViewModel.Author      = product.MetaData.Author;
                model.MetaDataViewModel.Copyright   = product.MetaData.Copyright;
                model.MetaDataViewModel.Description = product.MetaData.Description;
                model.MetaDataViewModel.Keywords    = product.MetaData.Keywords;
            }

            model.CategorySelectorViewModel.Id = categoryId;
            if (categoryId.HasValue)
            {
                model.CategorySelectorViewModel.Name             = _productCategoriesBL.GetById(categoryId.Value).Name;
                model.CategorySelectorViewModel.ParentCategories = _productCategoriesBL.GetParentCategories(categoryId.Value).Select(parentCategory => parentCategory.Name).ToArray();
            }

            model.ProductPhotoViewModels.AddRange(product.Photos.Where(photo => !photo.IsDeleted).Select(photo => new ProductPhotoViewModel
            {
                Id       = photo.Id,
                FileName = photo.FileName,
                IsMain   = photo.IsMain
            }));

            return(View(model));
        }
Пример #2
0
        public void SetPublish([FromUri] int id, [FromUri] bool value)
        {
            Product product = _productsBL.GetById(id);

            product.Publish = value;
            _productsBL.Update(product);
        }
Пример #3
0
        public ActionResult Details(int productId, int categoryId)
        {
            ViewData["category"] = categoryId;
            ProductDetailsViewModel viewModel = new ProductDetailsViewModel
            {
                CategoryId = categoryId,
                Product    = _productsBL.GetById(productId, Request.IsAuthenticated ? User.Identity.Name : null, Request.UserHostAddress)
            };

            viewModel.ParentCategories = _productCategoriesBL.GetParentCategories(categoryId);
            viewModel.ParentCategories.Add(_productCategoriesBL.GetById(categoryId));

            return(View("Details", viewModel));
        }
Пример #4
0
        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);
        }