Images implementiert
This commit is contained in:
parent
9f59a64a88
commit
7f6ddac2b8
|
@ -1,5 +1,6 @@
|
|||
using Aps_Single_Page_Anwendung.Models;
|
||||
using Aps_Single_Page_Anwendung.Repositories;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -14,10 +15,12 @@ namespace Aps_Single_Page_Anwendung.Controllers
|
|||
public class SpeisenController : ControllerBase
|
||||
{
|
||||
private readonly ISpeiseRepository _repository;
|
||||
private readonly string _path;
|
||||
|
||||
public SpeisenController(ISpeiseRepository repository)
|
||||
public SpeisenController(ISpeiseRepository repository, IWebHostEnvironment env)
|
||||
{
|
||||
_repository = repository;
|
||||
_path = System.IO.Path.Combine(env.ContentRootPath, "data", "images", "speisen");
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +56,7 @@ namespace Aps_Single_Page_Anwendung.Controllers
|
|||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
// Zum ändern der Daten
|
||||
// Zum ändern der Daten der Speise
|
||||
public IActionResult Put(int id, [FromBody] Speise speise)
|
||||
{
|
||||
if (id != speise.Id)
|
||||
|
@ -85,5 +88,20 @@ namespace Aps_Single_Page_Anwendung.Controllers
|
|||
return NoContent();
|
||||
|
||||
}
|
||||
// Über die Id wird das Image ausgegeben
|
||||
[HttpGet("{id}/image")]
|
||||
|
||||
public IActionResult Image(int id)
|
||||
{
|
||||
var file = System.IO.Path.Combine(_path, $"{id}.jpg");
|
||||
|
||||
if (System.IO.File.Exists(file))
|
||||
{
|
||||
var bytes = System.IO.File.ReadAllBytes(file);
|
||||
return File(bytes, "image/jpeg");
|
||||
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user