|
7 | 7 | using eShopWeb.Models; |
8 | 8 | using eShopWeb.Models.Pagination; |
9 | 9 | using Microsoft.AspNetCore.Mvc.Rendering; |
| 10 | +using Microsoft.AspNetCore.Hosting; |
| 11 | +using System.IO; |
10 | 12 |
|
11 | 13 | // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 |
12 | 14 |
|
13 | 15 | namespace eShopWeb.Controllers |
14 | 16 | { |
15 | 17 | public class CatalogController : Controller |
16 | 18 | { |
| 19 | + private readonly IHostingEnvironment _env; |
| 20 | + |
| 21 | + public CatalogController(IHostingEnvironment env) |
| 22 | + { |
| 23 | + _env = env; |
| 24 | + } |
| 25 | + |
| 26 | + |
17 | 27 | // GET: /<controller>/ |
18 | 28 | public IActionResult Index(int? BrandFilterApplied, int? TypesFilterApplied, int? page) |
19 | 29 | { |
@@ -43,6 +53,18 @@ public IActionResult Index(int? BrandFilterApplied, int? TypesFilterApplied, int |
43 | 53 | return View(vm); |
44 | 54 | } |
45 | 55 |
|
| 56 | + [HttpGet("{id}")] |
| 57 | + [Route("[controller]/pic/{id}")] |
| 58 | + // GET: /<controller>/pic/{id} |
| 59 | + public IActionResult GetImage(int id) |
| 60 | + { |
| 61 | + var contentRoot = _env.ContentRootPath + "//Pics"; |
| 62 | + var path = Path.Combine(contentRoot, id + ".png"); |
| 63 | + Byte[] b = System.IO.File.ReadAllBytes(path); |
| 64 | + return File(b, "image/png"); |
| 65 | + |
| 66 | + } |
| 67 | + |
46 | 68 |
|
47 | 69 | static IEnumerable<SelectListItem> GetPreconfiguredCatalogBrands() |
48 | 70 | { |
@@ -73,18 +95,18 @@ static IEnumerable<CatalogItem> GetPreconfiguredItems() |
73 | 95 | { |
74 | 96 | return new List<CatalogItem>() |
75 | 97 | { |
76 | | - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/1" }, |
77 | | - new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/2" }, |
78 | | - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/3" }, |
79 | | - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/4" }, |
80 | | - new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/5" }, |
81 | | - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/6" }, |
82 | | - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/7" }, |
83 | | - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/8" }, |
84 | | - new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/9" }, |
85 | | - new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/10" }, |
86 | | - new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/11" }, |
87 | | - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/12" } |
| 98 | + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://localhost:5106/catalog/pic/1" }, |
| 99 | + new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://localhost:5106/catalog/pic/2" }, |
| 100 | + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/3" }, |
| 101 | + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/4" }, |
| 102 | + new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://localhost:5106/catalog/pic/5" }, |
| 103 | + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/6" }, |
| 104 | + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/7" }, |
| 105 | + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://localhost:5106/catalog/pic/8" }, |
| 106 | + new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/9" }, |
| 107 | + new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/10" }, |
| 108 | + new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://localhost:5106/catalog/pic/11" }, |
| 109 | + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/12" } |
88 | 110 | }; |
89 | 111 | } |
90 | 112 | } |
|
0 commit comments