Browse Source

编辑证件信息图片前先删除原有图片

develop-FileUpload-test
胡超1 2 years ago
parent
commit
9815b1300c
  1. 39
      24Hour/Controllers/system/SystemControllerController.cs

39
24Hour/Controllers/system/SystemControllerController.cs

@ -783,8 +783,28 @@ namespace _24Hour.Controllers.system
{ {
_db.BeginTran(); _db.BeginTran();
var userlist = await _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.Id ==input.lawyerid).ToListAsync(); var userlist = await _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.Id ==input.lawyerid).ToListAsync();
var deleteOldData = (string? jsonpath) =>
{
if (string.IsNullOrEmpty(jsonpath))
{
return;
}
var photos = jsonpath.ConvertToModel<List<string>>() ?? new List<string>();
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);
}
}
};
userlist.ForEach(q => userlist.ForEach(q =>
{ {
deleteOldData(q.identityphoto);
//头像地址 //头像地址
q.identityphoto =input.photo.ConvertToJsonStr(); q.identityphoto =input.photo.ConvertToJsonStr();
}); });
@ -819,6 +839,25 @@ namespace _24Hour.Controllers.system
{ {
_db.BeginTran(); _db.BeginTran();
var userlist = await _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.Id == _userdata.Id).ToListAsync(); var userlist = await _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.Id == _userdata.Id).ToListAsync();
var deleteOldData = (string? jsonpath) =>
{
if (string.IsNullOrEmpty(jsonpath))
{
return;
}
var photos = jsonpath.ConvertToModel<List<string>>() ?? new List<string>();
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);
}
}
};
userlist.ForEach(q => userlist.ForEach(q =>
{ {
//头像地址 //头像地址

Loading…
Cancel
Save