fixed download if no image return empty

This commit is contained in:
2026-09-20 15:30:22 +10:00
parent 3d83e95613
commit 5292b99af6
5 changed files with 60 additions and 14 deletions
@@ -93,8 +93,42 @@ namespace FamilyTreeAPI.Repository
Message = error
};
}
public async Task<ResultModel<FileContent>> DownloadPersonPhotoById(int Id)
{
public async Task<ResultModel<FileContent>> DownloadPersonPhoto(int personId, int photoType, string filename)
int statusCode = -1;
string error = "";
string extension = "";
PersonPhoto? model = null;
FileContent fileContent = new();
try {
model = await _context.PersonPhotos.FindAsync(Id);
if (model != null)
{
extension = Helpers.GetFileExtension(model.Photo);
fileContent.ContentType = Helpers.GetFileContent(extension);
fileContent.Content = (byte[])model.ImagePhoto;
fileContent.FileName = model.Photo;
statusCode = 1;
}
}
catch (Exception e)
{
error = e.ToString();
statusCode = -1;
}
return new ResultModel<FileContent>()
{
Data = fileContent,
StatusCode = statusCode,
Message = error
};
}
public async Task<ResultModel<FileContent>> DownloadPersonPhotoPerson(int personId, int photoType, string filename)
{
int statusCode = -1;