예제 #1
0
        public static IList<CategoryView> PrepareCategoryViewModels(this IList<Category> categories, 
            IPictureService pictureService, SystemSetting sysSetting, int? pictureSize = null)
        {
            IList<CategoryView> results = new List<CategoryView>();

            foreach (var item in categories)
            {
                CategoryView view = new CategoryView
                {
                    Id = item.Id,
                    Name = item.Name
                };

                // Prepare the picture model
                if (pictureSize.HasValue && pictureService != null && sysSetting != null)
                {
                    //picture
                    var picture = pictureService.GetPicturesByProductId(item.Id, 1).FirstOrDefault();
                    int imageSize = pictureSize > 0 ? pictureSize.Value : sysSetting.DefaultThumbPicSize;

                    // PictureModel
                    PictureModel pictureModel = new PictureModel
                    {
                        ImageUrl = pictureService.GetPictureUrl(picture, imageSize),
                        FullSizeImageUrl = pictureService.GetPictureUrl(picture),
                        Title = string.Format("Show detail for {0}", item.Name),
                        AlternateText = string.Format("Image of {0}", item.Name)
                    };
                    view.PictureModel = pictureModel;
                }
                results.Add(view);
            }
            return results;
        }
예제 #2
0
 public CategoryController(ICategoryService cateService,  IProductService productService,
     IPictureService pictureService, SystemSetting sysSetting)
 {
     _cateService = cateService;
     _pictureService = pictureService;
     _sysSetting = sysSetting;
     _productService = productService;
 }
예제 #3
0
 public ShoppingCartController(IProductService productService, IPictureService pictureService,
     IShoppingCartService shoppingCartService, SystemSetting sysSetting, IUserContext userContext)
 {
     _productService = productService;
     _shoppingCartService = shoppingCartService;
     _userContext = userContext;
     _pictureService = pictureService;
     _sysSetting = sysSetting;
 }
예제 #4
0
 public ProductController(ICategoryService categoryService ,IProductService productService, 
     SystemSetting sysSetting, IViewedProductService viewdProductService, IPictureService pictureService)
 {
     _categoryService = categoryService;
     _productService = productService;
     _viewdProductService = viewdProductService;
     _pictureService = pictureService;
     _sysSetting = sysSetting;
 }
예제 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="products"></param>
        /// <param name="pictureService"></param>
        /// <param name="sysSetting"></param>
        /// <param name="pictureSize">if null, don't load picture</param>
        /// <returns></returns>
        public static IList<ProductViewModel> PrepareProductViewModels(this IList<Product> products, IPictureService pictureService,
            SystemSetting sysSetting, int? pictureSize = null)
        {
            IList<ProductViewModel> results = new List<ProductViewModel>();

            foreach (var product in products)
            {
                ProductViewModel model = new ProductViewModel
                {
                    Id = product.Id,
                    Name = product.Name,
                    ShortDescription = product.ShortDescription,
                    Description = product.ShortDescription,
                    Price = product.Price,
                    RatingSum = product.RatingSum,
                    TotalReviews = product.TotalReviews
                };

                if (pictureSize.HasValue && pictureService != null && sysSetting != null)
                {
                    //picture
                    var picture = pictureService.GetPicturesByProductId(product.Id, 1).FirstOrDefault();
                    int imageSize = pictureSize > 0 ? pictureSize.Value : sysSetting.DefaultThumbPicSize;

                    // PictureModel
                    PictureModel pictureModel = new PictureModel
                    {
                        ImageUrl = pictureService.GetPictureUrl(picture, imageSize),
                        FullSizeImageUrl = pictureService.GetPictureUrl(picture),
                        Title = string.Format("Show detail for {0}", product.Name),
                        AlternateText = string.Format("Image of {0}", product.Name)
                    };
                    model.PictureModel = pictureModel;
                }
                results.Add(model);
            }
            return results;
        }