File size: 606 Bytes
6db0915
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using ECommerce.Model.Repositories;
using ECommerce.Model.Entities;
using Microsoft.AspNetCore.Mvc;

namespace Ecommerce_web_project.Controllers;

public class ImageController : Controller
{
    private readonly IRepository<Product> _repo;

    public ImageController(IRepository<Product> repo) => _repo = repo;

    public async Task<IActionResult> Product(Guid id)
    {
        var product = await _repo.GetByIdAsync(id);
        if (product?.ImageData == null || product.ImageContentType == null)
            return NotFound();
        return File(product.ImageData, product.ImageContentType);
    }
}