feat: enhance extension inquiry with detailed response and validation improvements

This commit is contained in:
2025-10-11 11:08:31 +03:30
parent 4707c389ae
commit ccd99c5184
3 changed files with 48 additions and 21 deletions

View File

@@ -222,20 +222,24 @@ public interface IInstitutionContractApplication
Task<OperationResult> ExtensionComplete(InstitutionContractExtensionCompleteRequest request);
Task<OperationResult> ExtensionInquiry(InstitutionContractExtensionInquiryRequest command);
}
public class InstitutionContractExtensionInquiryRequest
{
public long ContractingPartyId { get; set; }
public string NationalCode { get; set; }
public string BirthDate { get; set; }
public string Mobile { get; set; }
Task<InstitutionContractExtensionInquiryResponse> ExtensionInquiry(InstitutionContractExtensionInquiryRequest command);
}
public class InstitutionContractExtensionInquiryResponse
{
public long Id { get; set; }
public string FName { get; set; }
public string LName { get; set; }
public string DateOfBirthFa { get; set; }
public string FatherName { get; set; }
public string IdNumberSerial { get; set; }
public string IdNumber { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string City { get; set; }
public string State { get; set; }
public long RepresentativeId { get; set; }
public string NationalCode { get; set; }
}
public class InstitutionContractExtensionCompleteRequest

View File

@@ -0,0 +1,9 @@
namespace CompanyManagment.App.Contracts.InstitutionContract;
public class InstitutionContractExtensionInquiryRequest
{
public long ContractingPartyId { get; set; }
public string NationalCode { get; set; }
public string BirthDate { get; set; }
public string Mobile { get; set; }
}

View File

@@ -1302,33 +1302,33 @@ public class InstitutionContractApplication : IInstitutionContractApplication
return await _institutionContractRepository.ExtensionComplete(request);
}
public async Task<OperationResult> ExtensionInquiry(InstitutionContractExtensionInquiryRequest command)
public async Task<InstitutionContractExtensionInquiryResponse> ExtensionInquiry(InstitutionContractExtensionInquiryRequest command)
{
var op = new OperationResult();
#region Validations
if (string.IsNullOrWhiteSpace(command.NationalCode) || string.IsNullOrWhiteSpace(command.BirthDate) ||
string.IsNullOrWhiteSpace(command.Mobile))
return op.Failed("هیچ یک از فیلد ها نمیتواند خالی باشد");
throw new BadRequestException("هیچ یک از فیلد ها نمیتواند خالی باشد");
if (command.NationalCode.NationalCodeValid() != "valid")
return op.Failed("کد ملی نا معتبر است");
throw new BadRequestException("کد ملی نا معتبر است");
if (!command.BirthDate.TryToGeorgianDateTime(out var dateOfBirthGr))
return op.Failed("تاریخ تولد نا معتبر است");
throw new BadRequestException("تاریخ تولد نا معتبر است");
if (!command.Mobile.IsMobileValid())
return op.Failed("شماره همراه نا معتبر است");
throw new BadRequestException("شماره همراه نا معتبر است");
#endregion
var contractingParty = _contractingPartyRepository.Get(command.ContractingPartyId);
if (contractingParty == null)
return op.Failed("طرف حسابی یافت نشد");
throw new BadRequestException("طرف حسابی یافت نشد");
// بررسی اینکه آیا طرف حساب قبلا احراز هویت شده یا نه
if (contractingParty.IsAuthenticated)
return op.Failed("طرف حساب قبلا احراز هویت شده است");
throw new BadRequestException("طرف حساب قبلا احراز هویت شده است");
@@ -1343,9 +1343,9 @@ public class InstitutionContractApplication : IInstitutionContractApplication
// چک کردن مطابقت شماره همراه و کد ملی
var isMachMobilAndNationalCode = await _uidService.IsMachPhoneWithNationalCode(command.NationalCode, command.Mobile);
if (isMachMobilAndNationalCode == null)
return op.Failed("خطا در سرویس احراز هویت");
throw new BadRequestException("خطا در سرویس احراز هویت");
if (!isMachMobilAndNationalCode.IsMatched)
return op.Failed("شماره همراه وارد شده با کد ملی مطابقت ندارد");
throw new BadRequestException("شماره همراه وارد شده با کد ملی مطابقت ندارد");
// دریافت اطلاعات احراز هویت
var apiResponse = await _uidService.GetPersonalInfo(command.NationalCode, command.BirthDate);
@@ -1357,7 +1357,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
throw new InternalServerException("سیستم احراز هویت در دسترس نمی باشد");
if (apiResponse.ResponseContext.Status.Code != 0)
return op.Failed($"{apiResponse.ResponseContext.Status.Message}");
throw new BadRequestException($"{apiResponse.ResponseContext.Status.Message}");
var idNumber = apiResponse.IdentificationInformation.ShenasnamehNumber == "0"
? apiResponse.IdentificationInformation.NationalId
@@ -1389,7 +1389,21 @@ public class InstitutionContractApplication : IInstitutionContractApplication
// ذخیره تغییرات
await _contractingPartyRepository.SaveChangesAsync();
return op.Succcedded();
var result = new InstitutionContractExtensionInquiryResponse();
result.Id = contractingParty.id;
result.FName = contractingParty.FName;
result.LName = contractingParty.LName;
result.DateOfBirthFa = command.BirthDate;
result.FatherName = contractingParty.FatherName;
result.IdNumberSerial = contractingParty.IdNumberSerial;
result.IdNumber = idNumber;
result.Address = contractingParty.Address;
result.Phone = contractingParty.Phone;
result.City = contractingParty.City;
result.State = contractingParty.State;
result.RepresentativeId = contractingParty.RepresentativeId;
result.NationalCode = contractingParty.Nationalcode;
return result;
}
private async Task<OperationResult<PersonalContractingParty>> CreateLegalContractingPartyEntity(