public ActionResult SetMainImage(int fileId, int id, String entityType)
        {
            if (entityType.Equals(StoreConstants.ProductType, StringComparison.InvariantCultureIgnoreCase))
            {
                ProductFileRepository.SetMainImage(id, fileId);
            }
            else if (entityType.Equals(StoreConstants.BlogsType, StringComparison.InvariantCultureIgnoreCase) || entityType.Equals(StoreConstants.NewsType, StringComparison.InvariantCultureIgnoreCase))
            {
                ContentFileRepository.SetMainImage(id, fileId);
            }

            return(Json(new { fileId, id }, JsonRequestBehavior.AllowGet));
        }
        public void CanGetSpecificProduct()
        {
            //ProductManager myPM = ProductManagerFactory.Create();
            ProductFileRepository myPR            = new ProductFileRepository(_dataPath + _productTestFile);
            ProductResponse       productResponse = new ProductResponse();

            productResponse = myPR.GetProductByType("Graphite");
            Assert.IsFalse(productResponse.Success);

            productResponse = myPR.GetProductByType("Granite");
            Assert.IsTrue(productResponse.Success);

            //Granite,72.5,29.25
            Assert.AreEqual("Granite", productResponse.Product.ProductType);
            Assert.AreEqual(72.5, productResponse.Product.CostPerSquareFoot);
            Assert.AreEqual(29.25, productResponse.Product.LaborCostPerSquareFoot);
        }
        public ActionResult GetImagesByLabels(int storeId, String[] labels, String entityType, int id)
        {
            var images = FileManagerRepository.GetFilesByStoreIdAndLabels(storeId, labels);
            var list   = new List <FileManager>();

            if (entityType.Equals(StoreConstants.ProductType, StringComparison.InvariantCultureIgnoreCase))
            {
                var productFiles = ProductFileRepository.GetProductFilesByProductId(id);
                list.AddRange(images.Where(r => !productFiles.Select(r1 => r1.FileManagerId).Contains(r.Id)));
            }
            else if (entityType.Equals(StoreConstants.BlogsType, StringComparison.InvariantCultureIgnoreCase) || entityType.Equals(StoreConstants.NewsType, StringComparison.InvariantCultureIgnoreCase))
            {
                var contentFiles = ContentFileRepository.GetContentFilesByContentId(id);
                list.AddRange(images.Where(r => !contentFiles.Select(r1 => r1.FileManagerId).Contains(r.Id)));
            }

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
 public CatalogService(RequestContext c,
                       CategoryRepository categories,
                       CategoryProductAssociationRepository crosses,
                       ProductRepository products,
                       ProductRelationshipRepository relationships,
                       ProductImageRepository productImages,
                       ProductReviewRepository productReviews,
                       VariantRepository productVariants,
                       OptionRepository productOptions,
                       ProductOptionAssociationRepository productsXOptions,
                       ProductFileRepository productFiles,
                       ProductVolumeDiscountRepository volumeDiscounts,
                       ProductPropertyValueRepository propertyValues,
                       ProductInventoryRepository inventory,
                       ProductTypeRepository types,
                       ProductTypePropertyAssociationRepository typesXProperties,
                       ProductPropertyRepository properties,
                       WishListItemRepository wishItems)
 {
     context = c;
     Categories = categories;
     CategoriesXProducts = crosses;
     ProductRelationships = relationships;
     this.Products = products;
     this.ProductImages = productImages;
     this.ProductReviews = productReviews;
     this.ProductVariants = productVariants;
     this.ProductOptions = productOptions;
     this.ProductsXOptions = productsXOptions;
     this.ProductFiles = productFiles;
     this.VolumeDiscounts = volumeDiscounts;
     this.ProductPropertyValues = propertyValues;
     this.ProductInventories = inventory;
     this.ProductTypes = types;
     this.ProductTypesXProperties = typesXProperties;
     this.ProductProperties = properties;
     this.WishListItems = wishItems;
 }
Beispiel #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            Product product = ProductRepository.GetSingle(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            try
            {
                if (!CheckRequest(product))
                {
                    return(new HttpNotFoundResult("Not Found"));
                }

                ProductRepository.Delete(product);
                ProductRepository.Save();
                ClearCache(product.StoreId);
                LabelLineRepository.DeleteLabelLinesByItem(product.Id, StoreConstants.ProductType);
                ProductFileRepository.DeleteProductFileByProductId(product.Id);

                if (IsSuperAdmin)
                {
                    return(RedirectToAction("Index", new { storeId = product.StoreId, categoryId = product.ProductCategoryId }));
                }
                else
                {
                    return(RedirectToAction("Index", new { categoryId = product.ProductCategoryId }));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to delete product:" + ex.StackTrace, product);
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(product));
        }
        public void CanReadProducts()
        {
            //ProductManager myPM = ProductManagerFactory.Create();
            ProductFileRepository myPR             = new ProductFileRepository(_dataPath + _productTestFile);
            ProductsResponse      productsResponse = new ProductsResponse();

            productsResponse = myPR.GetProducts();

            //Did it retrieve 10 products?
            Assert.AreEqual(10, productsResponse.Products.Count());

            //Laminate,4.5,9.8
            Product productToValidate = productsResponse.Products.Find(p => p.ProductType == "Laminate");

            Assert.AreEqual("Laminate", productToValidate.ProductType);
            Assert.AreEqual(4.5, productToValidate.CostPerSquareFoot);
            Assert.AreEqual(9.8, productToValidate.LaborCostPerSquareFoot);

            //Bamboo,18.5,9.25
            productToValidate = productsResponse.Products.Find(p => p.ProductType == "Bamboo");
            Assert.AreEqual("Bamboo", productToValidate.ProductType);
            Assert.AreEqual(18.5, productToValidate.CostPerSquareFoot);
            Assert.AreEqual(9.25, productToValidate.LaborCostPerSquareFoot);
        }
Beispiel #7
0
        public ActionResult SaveOrEdit(Product product, int[] selectedFileId = null, int[] selectedLabelId = null)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!CheckRequest(product))
                    {
                        return(new HttpNotFoundResult("Not Found"));
                    }


                    if (product.ProductCategoryId == 0)
                    {
                        int mainImageFileManagerId      = 0;
                        List <FileManager> fileManagers = new List <FileManager>();
                        var labelList = new List <LabelLine>();
                        if (product.Id > 0)
                        {
                            var content = ProductRepository.GetSingleIncluding(product.Id, r => r.ProductFiles.Select(r1 => r1.FileManager));
                            fileManagers = content.ProductFiles.Select(r => r.FileManager).ToList();
                            labelList    = LabelLineRepository.GetLabelLinesByItem(product.Id, StoreConstants.ProductType);
                            var mainImage = content.ProductFiles.FirstOrDefault(r => r.IsMainImage);
                            if (mainImage != null)
                            {
                                mainImageFileManagerId = mainImage.FileManagerId;
                            }
                        }
                        ViewBag.FileManagers = fileManagers;
                        ViewBag.LabelLines   = labelList;
                        ViewBag.MainImageId  = mainImageFileManagerId;
                        ModelState.AddModelError("ProductCategoryId", "You should select category from category tree.");
                        return(View(product));
                    }


                    product.Description = GetCleanHtml(product.Description);
                    if (product.Id == 0)
                    {
                        ProductRepository.Add(product);
                        ClearCache(product.StoreId);
                    }
                    else
                    {
                        ProductRepository.Edit(product);
                    }

                    ProductRepository.Save();
                    int contentId = product.Id;
                    if (selectedFileId != null)
                    {
                        ProductFileRepository.SaveProductFiles(selectedFileId, contentId);
                    }


                    LabelLineRepository.SaveLabelLines(selectedLabelId, contentId, StoreConstants.ProductType);


                    if (IsSuperAdmin)
                    {
                        return(RedirectToAction("Index", new { storeId = product.StoreId, categoryId = product.ProductCategoryId }));
                    }
                    else
                    {
                        return(RedirectToAction("Index", new { categoryId = product.ProductCategoryId }));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to save changes:" + ex.StackTrace, product);
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(product));
        }