report 1-4 เำิม่หมายเหตุแนวนอน

This commit is contained in:
Kittapath 2023-10-08 12:41:53 +07:00
parent 5530c2f9e4
commit 2da120f958
32 changed files with 51300 additions and 13 deletions

View file

@ -391,8 +391,23 @@ namespace BMA.EHR.Placement.Service.Controllers
Pass = x.Pass,
IsProperty = x.IsProperty == null ? null : Newtonsoft.Json.JsonConvert.DeserializeObject<List<PersonPropertyRequest>>(x.IsProperty),
BmaOfficer = "",
PlacementProfileDocs = x.PlacementProfileDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
}).FirstOrDefaultAsync(x => x.PersonalId == personalId);
if (data == null)
return Error(GlobalMessages.DataNotFound, 404);
var placementProfileDocs = new List<dynamic>();
foreach (var doc in data.PlacementProfileDocs)
{
var _doc = new
{
doc.FileName,
PathName = await _documentService.ImagesPath(doc.Id),
docId = doc.Id,
};
placementProfileDocs.Add(_doc);
}
var _data = new
{
data.PersonalId,
@ -466,7 +481,8 @@ namespace BMA.EHR.Placement.Service.Controllers
data.ExamRound,
data.Pass,
data.IsProperty,
BmaOfficer = await _documentService.CheckBmaOfficer(data.IdCard),
BmaOfficer = data.IdCard == null ? null : await _documentService.CheckBmaOfficer(data.IdCard),
Docs = placementProfileDocs,
};
return Success(_data);
}
@ -1196,5 +1212,66 @@ namespace BMA.EHR.Placement.Service.Controllers
return Success(path);
}
[HttpPut("doc/{personalId:length(36)}")]
public async Task<ActionResult<ResponseObject>> UpdateDoc([FromBody] PlacementFileRequest req, Guid personalId)
{
var placementProfile = await _context.PlacementProfiles
.Include(x => x.PlacementCertificates)
.FirstOrDefaultAsync(x => x.Id == personalId);
if (placementProfile == null)
return Error(GlobalMessages.DataNotFound, 404);
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
{
foreach (var file in Request.Form.Files)
{
var fileExtension = Path.GetExtension(file.FileName);
var doc = await _documentService.UploadFileAsync(file, file.FileName);
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (_doc != null)
{
var placementProfileDoc = new PlacementProfileDoc
{
PlacementProfile = placementProfile,
Document = _doc,
CreatedUserId = UserId ?? "System Administrator",
CreatedFullName = FullName ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.PlacementProfileDocs.AddAsync(placementProfileDoc);
}
}
}
_context.SaveChanges();
return Success();
}
[HttpDelete("doc/{personalId:length(36)}/{docId:length(36)}")]
public async Task<ActionResult<ResponseObject>> DeleteDoc(Guid personalId, Guid docId)
{
var person = await _context.PlacementProfiles
.Include(x => x.PlacementProfileDocs)
.FirstOrDefaultAsync(x => x.Id == personalId);
if (person == null)
return Error(GlobalMessages.DataNotFound, 404);
var profileDoc = person.PlacementProfileDocs.FirstOrDefault(x => x.Id == docId);
if (profileDoc == null)
return Error(GlobalMessages.CertificateNotFound, 404);
_context.PlacementProfileDocs.RemoveRange(profileDoc);
var _docId = profileDoc.Document.Id;
await _context.SaveChangesAsync();
await _documentService.DeleteFileAsync(_docId);
await _context.SaveChangesAsync();
return Success();
}
}
}