Пример #1
0
 private IEnumerable<ProductImageViewModel> ImagesResolver(Product product)
 {
     return product.ProductImages.Select(image => new ProductImageViewModel()
         {
             Id = image.Id,
             Default = image.Primary,
             Url = image.Path
         });
 }
Пример #2
0
 private IEnumerable<CategoryTagViewModel> CategoryTagResolver(Product product)
 {
     return product.Categories.Select(category => new CategoryTagViewModel()
         {
             CategoryDescription = category.Description,
             CategoryName = category.Name,
             CategoryId = category.Id
         });
 }
Пример #3
0
 private IEnumerable<ReviewViewModel> ReviewResolver(Product product)
 {
     return product.Reviews.Select(review => new ReviewViewModel()
         {
             Id = review.Id,
             AuthorName = review.Customer.Forename,
             Comment = review.Comment,
             DatePosted = review.Created,
             Rating = review.Rating
         });
 }
Пример #4
0
        private void AddImages(IEnumerable<HttpPostedFileBase> httpPostedFileBases, Product product)
        {
            var images = new Collection<ProductImage>();

            foreach (HttpPostedFileBase file in httpPostedFileBases)
            {
                if (file != null && file.FileName != null)
                {
                    if (!Directory.Exists(HttpContext.Current.Server.MapPath(string.Format("~/Uploads/Product_{0}", product.Id))))
                    {
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath(string.Format("~/Uploads/Product_{0}", product.Id)));
                    }

                    string path = Path.Combine(HttpContext.Current.Server.MapPath(string.Format("~/Uploads/Product_{0}", product.Id)), Path.GetFileName(file.FileName));
                    file.SaveAs(path);

                    ProductImage image = new ProductImage();
                    image.Path = path;
                    image.Product = product;
                    image.ProductId = product.Id;
                    image.Primary = false;

                    images.Add(image);
                }
            }

            product.ProductImages = images;
        }