diff --git a/24Hour/Controllers/Common/LawyerArchivesController.cs b/24Hour/Controllers/Common/LawyerArchivesController.cs index f0bd98f..76360b1 100644 --- a/24Hour/Controllers/Common/LawyerArchivesController.cs +++ b/24Hour/Controllers/Common/LawyerArchivesController.cs @@ -1782,6 +1782,25 @@ namespace _24Hour.Controllers.Common lawyerservices = default(List), users = default(List) }); + //替换数据前先删除之前保存的图片 + var deleteOldData = (string? jsonpath) => + { + if (string.IsNullOrEmpty(jsonpath)) + { + return; + } + var photos = jsonpath.ConvertToModel>() ?? new List(); + foreach (var photo in photos.Where(x => x != null)) + { + var urlpath = photo.Split('/'); + var filepath = Path.Combine(Environment.CurrentDirectory, "wwwroot", Path.Combine(urlpath)); + if (System.IO.File.Exists(filepath)) + { + System.IO.File.Delete(filepath); + } + } + }; + foreach (var userim in importdata.users.Where(x => x != null)) { var user = await _db.Queryable() @@ -1818,6 +1837,9 @@ namespace _24Hour.Controllers.Common } else { + deleteOldData(user.cardIdphoto); + deleteOldData(user.identityphoto); + user.cardIdphoto = cardids; user.identityphoto = files; user.unitCode = _userdata.unitCode; @@ -1842,46 +1864,23 @@ namespace _24Hour.Controllers.Common { var svc = await _db.Queryable() .Where(x => x.Id == lawyersvc.Id).FirstAsync(); + var loadphoto = (string dirname) => + { + var dirpath = Path.Combine(ziplawyersvcs, lawyersvc.Id, dirname); + var photos = new DirectoryInfo(dirpath) + .GetFiles() + .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) + .Replace(@"\", @"/")) + .ToList() + .ConvertToJsonStr(); + return photos; + }; - var annexphoto = Path.Combine(ziplawyersvcs, lawyersvc.Id, "annexs"); - var annexs = new DirectoryInfo(annexphoto) - .GetFiles() - .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) - .Replace(@"\", @"/")) - .ToList() - .ConvertToJsonStr(); - - var legalAidPhoto = Path.Combine(ziplawyersvcs, lawyersvc.Id, "legalAidPhoto"); - var legalAidPhotos = new DirectoryInfo(legalAidPhoto) - .GetFiles() - .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) - .Replace(@"\", @"/")) - .ToList() - .ConvertToJsonStr(); - - var relationshipProofPhoto = Path.Combine(ziplawyersvcs, lawyersvc.Id, "relationshipProofPhoto"); - var relationshipProofPhotos = new DirectoryInfo(relationshipProofPhoto) - .GetFiles() - .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) - .Replace(@"\", @"/")) - .ToList() - .ConvertToJsonStr(); - - var otherPhoto = Path.Combine(ziplawyersvcs, lawyersvc.Id, "otherPhoto"); - var otherPhotos = new DirectoryInfo(otherPhoto) - .GetFiles() - .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) - .Replace(@"\", @"/")) - .ToList() - .ConvertToJsonStr(); - - var departmentPhoto = Path.Combine(ziplawyersvcs, lawyersvc.Id, "departmentPhoto"); - var departmentPhotos = new DirectoryInfo(departmentPhoto) - .GetFiles() - .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) - .Replace(@"\", @"/")) - .ToList() - .ConvertToJsonStr(); + var annexs = loadphoto("annexs"); + var legalAidPhotos = loadphoto("legalAidPhoto"); + var relationshipProofPhotos = loadphoto("relationshipProofPhoto"); + var otherPhotos = loadphoto("otherPhoto"); + var departmentPhotos = loadphoto("departmentPhoto"); if (svc == null) { @@ -1912,6 +1911,14 @@ namespace _24Hour.Controllers.Common .Where(x => x.identity == "律师") .FirstAsync(); + + deleteOldData(svc?.annex); + deleteOldData(svc?.legalAidPhoto); + deleteOldData(svc?.relationshipProofPhoto); + deleteOldData(svc?.otherPhoto); + deleteOldData(svc?.departmentPhoto); + + svc.createuserId = lawyer.Id; svc.annex = annexs; svc.legalAidPhoto = legalAidPhotos;