I have a method that is responsible for uploading files when trying to add a product. The problem is that I don't use Interface Segregation Because in the method I only use one property that belongs to the product and not all of it as an example:
Model Product:
public class Product : BaseEntity
{
public string? Description { get; set; }
public int CategoryId { get; set; }
public string PhotoUrl { get; set; } = string.Empty;
[ForeignKey("CategoryId")]
public virtual Category Category { get; set; } = null!;
}
Service:
public class PhotoService : IPhotoService
{
private readonly IWebHostEnvironment _environment;
public PhotoService(IWebHostEnvironment environment)
{
_environment = environment;
}
public async Task<string> UploadPhotos(IFormFile file, Product product)
{
string wwwPath = _environment.WebRootPath;
var path = Path.Combine(wwwPath, "images", file.FileName);
if (file.Length > 0)
{
using var stream = new FileStream(path, FileMode.Create);
await file.CopyToAsync(stream);
}
return product!.PhotoUrl = file.FileName;
}
}
Here I use the Product parameter but use only one property which is the PhotoUrl
I tried to do it using DTO or string but it didn't help me at least how I tried