diff --git a/YD_Event.Application/AppUser/AppUserService.cs b/YD_Event.Application/AppUser/AppUserService.cs index b207deb..e40254f 100644 --- a/YD_Event.Application/AppUser/AppUserService.cs +++ b/YD_Event.Application/AppUser/AppUserService.cs @@ -184,12 +184,15 @@ public class AppUserService : BaseService, ITransient // 身份证/户口本认证时检查身份证号是否重复 if ((input.AuthType == 1 || input.AuthType == 3) && !string.IsNullOrWhiteSpace(input.IdCardNumber)) { - var duplicateIdCard = await _appUserRep.AsQueryable() + var q1 = _appUserRep.AsQueryable() .Where(x => x.IdCardNumber == input.IdCardNumber && x.PersonType == input.PersonType - && !x.DeleteMark - && (!input.Id.HasValue || x.Id != input.Id.Value)) - .FirstAsync(); + && !x.DeleteMark); + if (input.Id.HasValue) + { + q1 = q1.Where(x => x.Id != input.Id.Value); + } + var duplicateIdCard = await q1.FirstAsync(); if (duplicateIdCard != null) { @@ -200,12 +203,15 @@ public class AppUserService : BaseService, ITransient // 护照认证时检查护照号是否重复 if (input.AuthType == 2 && !string.IsNullOrWhiteSpace(input.PassportNumber)) { - var duplicatePassport = await _appUserRep.AsQueryable() + var q2 = _appUserRep.AsQueryable() .Where(x => x.PassportNumber == input.PassportNumber && x.PersonType == input.PersonType - && !x.DeleteMark - && (!input.Id.HasValue || x.Id != input.Id.Value)) - .FirstAsync(); + && !x.DeleteMark); + if (input.Id.HasValue) + { + q2 = q2.Where(x => x.Id != input.Id.Value); + } + var duplicatePassport = await q2.FirstAsync(); if (duplicatePassport != null) { diff --git a/YD_Event.Application/Client/MyController.cs b/YD_Event.Application/Client/MyController.cs index 053b000..5856587 100644 --- a/YD_Event.Application/Client/MyController.cs +++ b/YD_Event.Application/Client/MyController.cs @@ -175,8 +175,9 @@ public class MyController : IDynamicApiController if (string.IsNullOrEmpty(input.IdCardBackImageUrl)) throw Oops.Bah("身份证背面图片不能为空"); // 身份证号查重 - var duplicateIdCard = await _appUserRepository.GetFirstAsync(u => - u.IdCardNumber == input.IdCardNumber && u.Id != userId && !u.DeleteMark); + var duplicateIdCard = await _appUserRepository.AsQueryable() + .Where(u => u.IdCardNumber == input.IdCardNumber && u.Id != userId && !u.DeleteMark) + .FirstAsync(); if (duplicateIdCard != null) throw Oops.Bah("该身份证号已被其他用户使用"); } else if (input.AuthType == 2) @@ -187,8 +188,9 @@ public class MyController : IDynamicApiController if (!input.BirthDate.HasValue) throw Oops.Bah("出生日期不能为空"); // 护照号查重 - var duplicatePassport = await _appUserRepository.GetFirstAsync(u => - u.PassportNumber == input.PassportNumber && u.Id != userId && !u.DeleteMark); + var duplicatePassport = await _appUserRepository.AsQueryable() + .Where(u => u.PassportNumber == input.PassportNumber && u.Id != userId && !u.DeleteMark) + .FirstAsync(); if (duplicatePassport != null) throw Oops.Bah("该护照号码已被其他用户使用"); } else if (input.AuthType == 3) @@ -197,8 +199,9 @@ public class MyController : IDynamicApiController if (string.IsNullOrEmpty(input.IdCardNumber)) throw Oops.Bah("身份证号不能为空"); // 身份证号查重 - var duplicateIdCard = await _appUserRepository.GetFirstAsync(u => - u.IdCardNumber == input.IdCardNumber && u.Id != userId && !u.DeleteMark); + var duplicateIdCard = await _appUserRepository.AsQueryable() + .Where(u => u.IdCardNumber == input.IdCardNumber && u.Id != userId && !u.DeleteMark) + .FirstAsync(); if (duplicateIdCard != null) throw Oops.Bah("该身份证号已被其他用户使用"); } else