check add person photo finish
This commit is contained in:
@@ -3,8 +3,9 @@ using FamilyTreeAPI.Repository;
|
||||
|
||||
namespace FamilyTreeAPI.Controllers;
|
||||
|
||||
|
||||
using FamilyTreeAPI.Interface;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -15,11 +16,15 @@ public class FileUploadController : ControllerBase
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly ImportPersonRepository _importPersonRepository;
|
||||
private readonly IConfiguration _config;
|
||||
public FileUploadController(IWebHostEnvironment hostingEnvironment, ImportPersonRepository importPersonRepository, IConfiguration config)
|
||||
private readonly IPersonPhoto _personPhoto;
|
||||
public FileUploadController(IWebHostEnvironment hostingEnvironment,
|
||||
IPersonPhoto personPhoto,
|
||||
ImportPersonRepository importPersonRepository, IConfiguration config)
|
||||
{
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_importPersonRepository = importPersonRepository;
|
||||
_config = config;
|
||||
_personPhoto = personPhoto;
|
||||
}
|
||||
|
||||
[HttpPost("[action]")]
|
||||
@@ -79,4 +84,51 @@ public class FileUploadController : ControllerBase
|
||||
var rev = await _importPersonRepository.DownloadFile(criteria);
|
||||
return Ok(rev);
|
||||
}
|
||||
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> SavePersonPhoto(List<IFormFile> files)
|
||||
{
|
||||
var keys = Request.Form;
|
||||
var ffiles = Request.Form.Files;
|
||||
ResultModel<int> ret = new();
|
||||
if (files.Count > 0)
|
||||
{
|
||||
StringValues sdocCId = "";
|
||||
keys.TryGetValue("personId", out sdocCId);
|
||||
for (int i = 0; i < files.Count; i++)
|
||||
{
|
||||
var file = files[i];
|
||||
UploadCriteria criteria = new();
|
||||
criteria.File = file;
|
||||
criteria.PersonId = int.Parse(sdocCId);
|
||||
criteria.FileName = file.FileName;
|
||||
|
||||
ret = await _personPhoto.SaveAsync(criteria);
|
||||
}
|
||||
|
||||
}
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> DownloadPersonPhoto(DownloadFileCriteria criteria)
|
||||
{
|
||||
|
||||
var result = await _personPhoto.DownloadPersonPhoto(criteria.Id, criteria.FileName);
|
||||
|
||||
return File(result.Data.Content, result.Data.ContentType, result.Data.FileName);
|
||||
}
|
||||
[HttpPost("[action]")]
|
||||
public async Task<ActionResult> DeletePersonPhoto(DeleteFileCriteria criteria)
|
||||
{
|
||||
|
||||
ResultModel<int> ret = new();
|
||||
if ( criteria.Id > 0)
|
||||
{
|
||||
|
||||
ret = await _personPhoto.DeletePersonPhoto(criteria.Id);
|
||||
}
|
||||
return Ok(ret);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user