public IActionResult List(ProductPictureModifierSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets)) { return(AccessDeniedView()); } ProductAttribute productAttribute = _productPictureModifierService. GetProductAttributeByName(ProductPictureModifierDefault.ProductAttributeName).First(); IPagedList <Product> products = _productService. GetProductsByProductAtributeId(productAttribute.Id, searchModel.Page - 1, searchModel.PageSize); var model = new ProductPictureModifierListModel() { Data = products.Select(product => new ProductPictureModifierModel { EntityId = product.ProductAttributeMappings .First(x => x.ProductAttributeId == productAttribute.Id).Id, ProductName = product.Name, ProductId = product.Id, ColorCode = product.ProductAttributeMappings .First(x => x.ProductAttributeId == productAttribute.Id).DefaultValue }), Total = products.TotalCount }; return(Json(model)); }
public IActionResult Configure() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets)) { return(AccessDeniedView()); } var searchModel = new ProductPictureModifierSearchModel(); //prepare page parameters searchModel.SetGridPageSize(); return(View("~/Plugins/Widgets.ProductPictureModifier/Views/Admin/List.cshtml", searchModel)); }
public virtual IActionResult CustomLogoList(ProductPictureModifierSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) { return(AccessDeniedKendoGridJson()); } //try to get a product with the specified id Product product = _productService.GetProductById(searchModel.ProductId) ?? throw new ArgumentException("No product found with the specified id"); ProductAttribute predefinedLogoAttribute = _productPictureModifierService .GetProductAttributeByName(ProductPictureModifierDefault.ProductAttributeNameForLogo) .FirstOrDefault() ?? throw new ArgumentException("Product Attribute not found"); ProductAttributeMapping predefinedLogoAttributeMapping = _productAttributeService .GetProductAttributeMappingsByProductId(searchModel.ProductId) .FirstOrDefault(x => x.ProductAttributeId == predefinedLogoAttribute.Id); if (predefinedLogoAttributeMapping == null) { return(Json(new ProductAttributeValueListModel())); } //get product attribute values IList <ProductAttributeValue> productAttributeValues = _productAttributeService .GetProductAttributeValues(predefinedLogoAttributeMapping.Id); //prepare list model var model = new ProductAttributeValueListModel { Data = productAttributeValues.PaginationByRequestModel(searchModel).Select(value => { //fill in model values from the entity var productAttributeValueModel = new ProductAttributeValueModelForLogo() { Id = value.Id, ProductAttributeMappingId = value.ProductAttributeMappingId, ImageSquaresPictureId = value.ImageSquaresPictureId, PictureId = value.PictureId, Name = value.Name }; var pictureThumbnailUrl = _pictureService.GetPictureUrl(value.PictureId, 150, false); //little hack here. Grid is rendered wrong way with <img> without "src" attribute if (string.IsNullOrEmpty(pictureThumbnailUrl)) { pictureThumbnailUrl = _pictureService.GetPictureUrl(null, 1); } productAttributeValueModel.PictureThumbnailUrl = pictureThumbnailUrl; var logoThumbnailUrl = _pictureService.GetPictureUrl(value.ImageSquaresPictureId, 50, false); if (string.IsNullOrEmpty(logoThumbnailUrl)) { logoThumbnailUrl = _pictureService.GetPictureUrl(null, 1); } productAttributeValueModel.LogoThumbnailUrl = logoThumbnailUrl; return(productAttributeValueModel); }), Total = productAttributeValues.Count }; return(Json(model)); }