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; }
public CategoryDetailModel() { PictureModel = new PictureModel(); FeaturedProducts = new List<ProductViewModel>(); Products = new List<ProductViewModel>(); SubCategories = new List<CategoryView>(); CategoryBreadcrumb = new List<CategoryView>(); }
/// <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; }
public ShoppingCartItemModel() { Picture = new PictureModel(); }
protected virtual void PrepareShoppingCartModel(ShoppingCartModel model, IList<ShoppingCartItem> items) { if (model == null) throw new ArgumentNullException("model"); if (items == null) throw new ArgumentNullException("cart"); if (items.Count == 0) return; foreach (var item in items) { var itemModel = new ShoppingCartModel.ShoppingCartItemModel() { Id = item.Id, ProductId = item.ProductId, ProductName = item.Product.Name, ItemPrice = item.ItemPrice, Quantity = item.Quantity, SubTotal = item.ItemPrice * item.Quantity, }; // picture var picture = _pictureService.GetPicturesByProductId(itemModel.ProductId, 1).FirstOrDefault(); int imageSize = _sysSetting.ProductDetailPicSize; // PictureModel PictureModel pictureModel = new PictureModel { ImageUrl = _pictureService.GetPictureUrl(picture, imageSize), FullSizeImageUrl = _pictureService.GetPictureUrl(picture), Title = string.Format("Show detail for {0}", itemModel.ProductName), AlternateText = string.Format("Image of {0}", itemModel.ProductName) }; itemModel.Picture = pictureModel; model.Items.Add(itemModel); } }
protected virtual IList<CategoryView> PrepareCategoryViewsByPath(int? rootCategoryId, IList<int> loadSubCategoriesInIds, bool isLoadPicture) { var result = new List<CategoryView>(); foreach (var category in _cateService.GetAllCategoriesByParentCategoryId(rootCategoryId)) { var categoryModel = new CategoryView() { Id = category.Id, Name = category.Name }; if (isLoadPicture) { //picture var picture = _pictureService.GetPictureById(category.PictureId); int imageSize = _sysSetting.DefaultGridPicSize; // PictureModel PictureModel pictureModel = new PictureModel { ImageUrl = _pictureService.GetPictureUrl(picture, imageSize), FullSizeImageUrl = _pictureService.GetPictureUrl(picture), Title = string.Format("Show detail for {0}", category.Name), AlternateText = string.Format("Image of {0}", category.Name) }; categoryModel.PictureModel = pictureModel; } //load subcategories? if (loadSubCategoriesInIds != null && loadSubCategoriesInIds.Contains(category.Id)) { var subCategories = PrepareCategoryViewsByPath(category.Id, loadSubCategoriesInIds, isLoadPicture); categoryModel.SubCategories = subCategories; } result.Add(categoryModel); } return result; }
public ProductDetailModel() { DefaultPictureModel = new PictureModel(); PictureModels = new List<PictureModel>(); CategoryBreadcrumb = new List<CategoryView>(); }