public async Task <IActionResult> ProductCard() { try { ViewBag.FileRefPath = base.JsReportFileRefPath; ViewBag.ItemCount = 10; var header = await _jsReport.RenderViewToStringAsync(HttpContext, RouteData, "HeaderReport", new { }); var footer = await _jsReport.RenderViewToStringAsync(HttpContext, RouteData, "FooterReport", new { }); HttpContext.JsReportFeature().Recipe(jsreport.Types.Recipe.ChromePdf) .Configure((r) => r.Template.Chrome = new Chrome { DisplayHeaderFooter = true, HeaderTemplate = header, FooterTemplate = footer, Format = _config["ReportSetting:Format"], MarginTop = "0.7cm", MarginLeft = _config["ReportSetting:MarginLeft"], MarginBottom = _config["ReportSetting:MarginBottom"], MarginRight = _config["ReportSetting:MarginRight"] }); return(await Task.Run(() => View(ProductCardModel.Example()))); } catch (Exception ex) { string excLog = ex.Message; return(BadRequest()); } }
public async Task <IActionResult> ProductCard_Label() { ViewBag.FileRefPath = base.JsReportFileRefPath; HttpContext.JsReportFeature().Recipe(jsreport.Types.Recipe.ChromePdf) .Configure((r) => r.Template.Chrome = new Chrome { DisplayHeaderFooter = false, HeaderTemplate = null, FooterTemplate = null, Width = "8cm", Height = "5.5cm", MarginTop = "0.5cm", MarginLeft = "0.5cm", MarginBottom = "0.5cm", MarginRight = "0.5cm" }); return(await Task.Run(() => View(ProductCardModel.Example()))); }
public List <ProductCardModel> Get(List <Product> products) { var galleryIds = products.Select(product => product.Gallery.Id).ToList(); var productIds = products.Select(product => product.Id).ToList(); List <MediaFile> mediaFiles = _session.QueryOver <MediaFile>() .Where(file => file.MediaCategory.Id.IsIn(galleryIds)) .OrderBy(file => file.DisplayOrder) .Asc.Cacheable() .List().ToList(); List <ProductVariant> variants = _session.QueryOver <ProductVariant>() .Where(productVariant => productVariant.Product.Id.IsIn(productIds)) .Cacheable() .List().ToList(); var productCardModels = new List <ProductCardModel>(); foreach (var product in products) { MediaFile image = mediaFiles.FirstOrDefault(file => file.IsImage() && file.MediaCategory.Id == product.Gallery.Id); var productVariants = variants.FindAll(productVariant => productVariant.Product.Id == product.Id); if (!productVariants.Any()) { continue; } var productCardModel = new ProductCardModel { Name = product.Name, Url = product.LiveUrlSegment, Abstract = product.ProductAbstract, Image = image == null ? null : image.FileUrl, PreviousPriceText = _ecommerceSettings.PreviousPriceText, ProductReviewsEnabled = _productReviewSettings.EnableProductReviews, IsMultiVariant = productVariants.Count > 1 }; if (productVariants.Count == 1) { var variant = productVariants.FirstOrDefault(); productCardModel.PreviousPrice = product.ShowPreviousPrice ? variant.PreviousPrice : null; productCardModel.Price = variant.Price; productCardModel.VariantId = variant.Id; CanBuyStatus canBuyStatus = _productVariantAvailabilityService.CanBuy(variant, 1); productCardModel.CanBuyStatus = canBuyStatus; productCardModel.StockMessage = canBuyStatus.OK ? (!string.IsNullOrEmpty(variant.CustomStockInStockMessage) ? variant.CustomStockInStockMessage : _stringResourceProvider.GetValue("In Stock")) : (!string.IsNullOrEmpty(variant.CustomStockOutOfStockMessage) ? variant.CustomStockOutOfStockMessage : _stringResourceProvider.GetValue("Out of Stock")); productCardModel.Rating = variant.Rating; productCardModel.NumberOfReviews = variant.NumberOfReviews; if (variant.ETag != null) { productCardModel.ETag = variant.ETag; } } else { ProductVariant variant = productVariants.OrderBy(x => x.Price).FirstOrDefault(); productCardModel.Price = variant != null ? variant.Price : (decimal?)null; productCardModel.Rating = variant.Rating; productCardModel.NumberOfReviews = variant.NumberOfReviews; if (variant.ETag != null) { productCardModel.ETag = variant.ETag; } } productCardModels.Add(productCardModel); } return(productCardModels); }