Add PictureFileName seed and add rename PictureUri column name to PictureFileName
This commit is contained in:
parent
4fe02d9b44
commit
d6e140a49b
@ -22,14 +22,24 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
_catalogContext = catalogContext;
|
||||
}
|
||||
|
||||
[HttpGet("{filename}")]
|
||||
[HttpGet("{id}")]
|
||||
// GET: /<controller>/
|
||||
public IActionResult GetImage(string filename)
|
||||
public async Task<IActionResult> GetImage(int id)
|
||||
{
|
||||
if (id <= 0)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
var item = await _catalogContext.CatalogItems
|
||||
.SingleOrDefaultAsync(ci => ci.Id == id);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
var webRoot = _env.WebRootPath;
|
||||
var path = Path.Combine(webRoot, filename);
|
||||
var path = Path.Combine(webRoot, item.PictureFileName);
|
||||
|
||||
string imageFileExtension = Path.GetExtension(filename);
|
||||
string imageFileExtension = Path.GetExtension(item.PictureFileName);
|
||||
string mimetype = GetImageMimeTypeFromImageFileExtension(imageFileExtension);
|
||||
|
||||
var buffer = System.IO.File.ReadAllBytes(path);
|
||||
@ -37,35 +47,38 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
return File(buffer, mimetype);
|
||||
}
|
||||
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
private string GetImageMimeTypeFromImageFileExtension(string extension)
|
||||
{
|
||||
string mimetype;
|
||||
|
||||
switch (extension)
|
||||
{
|
||||
case "png":
|
||||
case ".png":
|
||||
mimetype = "image/png";
|
||||
break;
|
||||
case "gif":
|
||||
case ".gif":
|
||||
mimetype = "image/gif";
|
||||
break;
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
case ".jpg":
|
||||
case ".jpeg":
|
||||
mimetype = "image/jpeg";
|
||||
break;
|
||||
case "bmp":
|
||||
case ".bmp":
|
||||
mimetype = "image/bmp";
|
||||
break;
|
||||
case "tiff":
|
||||
case ".tiff":
|
||||
mimetype = "image/tiff";
|
||||
break;
|
||||
case "wmf":
|
||||
case ".wmf":
|
||||
mimetype = "image/wmf";
|
||||
break;
|
||||
case "jp2":
|
||||
case ".jp2":
|
||||
mimetype = "image/jp2";
|
||||
break;
|
||||
case "svg":
|
||||
case ".svg":
|
||||
mimetype = "image/svg+xml";
|
||||
break;
|
||||
default:
|
||||
|
@ -189,7 +189,7 @@
|
||||
string[] csvheaders;
|
||||
try
|
||||
{
|
||||
string[] requiredHeaders = { "catalogtypename", "catalogbrandname", "description", "name", "price", "pictureuri" };
|
||||
string[] requiredHeaders = { "catalogtypename", "catalogbrandname", "description", "name", "price", "pictureFileName" };
|
||||
string[] optionalheaders = { "availablestock", "restockthreshold", "maxstockthreshold", "onreorder" };
|
||||
csvheaders = GetHeaders(csvFileCatalogItems, requiredHeaders, optionalheaders );
|
||||
}
|
||||
@ -320,18 +320,18 @@
|
||||
{
|
||||
return new List<CatalogItem>()
|
||||
{
|
||||
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Hoodie", Name = ".NET Bot Black Hoodie", Price = 19.5M, PictureUri = "1.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "2.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "3.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation T-shirt", Name = ".NET Foundation T-shirt", Price = 12, PictureUri = "4.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "5.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Hoodie", Name = ".NET Blue Hoodie", Price = 12, PictureUri = "6.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "7.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Hoodie", Name = "Kudu Purple Hoodie", Price = 8.5M, PictureUri = "8.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "9.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "10.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "11.png", AvailableStock = 100 },
|
||||
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "12.png", AvailableStock = 100 }
|
||||
new CatalogItem { CatalogTypeId = 2, CatalogBrandId = 2, Description = ".NET Bot Black Hoodie", Name = ".NET Bot Black Hoodie", Price = 19.5M, PictureFileName = "1.png" },
|
||||
new CatalogItem { CatalogTypeId = 1, CatalogBrandId = 2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureFileName = "2.png" },
|
||||
new CatalogItem { CatalogTypeId = 2, CatalogBrandId = 5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureFileName = "3.png" },
|
||||
new CatalogItem { CatalogTypeId = 2, CatalogBrandId = 2, Description = ".NET Foundation T-shirt", Name = ".NET Foundation T-shirt", Price = 12, PictureFileName = "4.png" },
|
||||
new CatalogItem { CatalogTypeId = 3, CatalogBrandId = 5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureFileName = "5.png" },
|
||||
new CatalogItem { CatalogTypeId = 2, CatalogBrandId = 2, Description = ".NET Blue Hoodie", Name = ".NET Blue Hoodie", Price = 12, PictureFileName = "6.png" },
|
||||
new CatalogItem { CatalogTypeId = 2, CatalogBrandId = 5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureFileName = "7.png" },
|
||||
new CatalogItem { CatalogTypeId = 2, CatalogBrandId = 5, Description = "Kudu Purple Hoodie", Name = "Kudu Purple Hoodie", Price = 8.5M, PictureFileName = "8.png" },
|
||||
new CatalogItem { CatalogTypeId = 1, CatalogBrandId = 5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureFileName = "9.png" },
|
||||
new CatalogItem { CatalogTypeId = 3, CatalogBrandId = 2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureFileName = "10.png" },
|
||||
new CatalogItem { CatalogTypeId = 3, CatalogBrandId = 2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureFileName = "11.png" },
|
||||
new CatalogItem { CatalogTypeId = 2, CatalogBrandId = 5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureFileName = "12.png" },
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
CatalogTypeName,CatalogBrandName,Description,Name,Price,PictureUri,availablestock,onreorder
|
||||
CatalogTypeName,CatalogBrandName,Description,Name,Price,PictureFileName,availablestock,onreorder
|
||||
T-Shirt,.NET,".NET Bot Black Hoodie, and more",.NET Bot Black Hoodie,19.5,1.png,100,false
|
||||
Mug,.NET,.NET Black & White Mug,.NET Black & White Mug,8.50,2.png,89,true
|
||||
T-Shirt,Other,Prism White T-Shirt,Prism White T-Shirt,12,3.png,56,false
|
||||
|
Can't render this file because it contains an unexpected character in line 8 and column 52.
|
Loading…
x
Reference in New Issue
Block a user