Files
Backend-Api/CompanyManagment.EFCore/Repository/ContractingPartyTempRepository.cs

103 lines
3.9 KiB
C#

using System.Linq;
using System.Threading.Tasks;
using _0_Framework.Application;
using _0_Framework.Application.UID;
using _0_Framework.InfraStructure;
using AccountMangement.Infrastructure.EFCore.Migrations;
using Company.Domain.TemporaryClientRegistrationAgg;
using CompanyManagment.App.Contracts.PersonalContractingParty;
using CompanyManagment.App.Contracts.TemporaryClientRegistration;
using Microsoft.EntityFrameworkCore;
namespace CompanyManagment.EFCore.Repository;
public class ContractingPartyTempRepository : RepositoryBase<long, ContractingPartyTemp>, IContractingPartyTempRepository
{
private readonly CompanyContext _context;
private readonly IUidService _uidService;
public ContractingPartyTempRepository(CompanyContext context, IUidService uidService) : base(context)
{
_context = context;
_uidService = uidService;
}
public async Task<bool> CheckExistOrAuthenticated(string nationalCode, string dateOfBirth)
{
var contractingParty = _context.PersonalContractingParties.FirstOrDefault(x=>x.Nationalcode == nationalCode && x.IsLegal == "false");
if (contractingParty == null)
return false;
if (!contractingParty.IsAuthenticated && !string.IsNullOrWhiteSpace(contractingParty.Nationalcode))
{
var dateOfbirth = contractingParty.DateOfBirth.ToFarsi();
var apiRespons = await _uidService.GetPersonalInfo(contractingParty.Nationalcode, dateOfbirth);
if (apiRespons != null && apiRespons.ResponseContext.Status.Code == 0)
{
var idNumber = apiRespons.IdentificationInformation.ShenasnamehNumber == "0"
? apiRespons.IdentificationInformation.NationalId
: apiRespons.IdentificationInformation.ShenasnamehNumber;
contractingParty
.Authentication(apiRespons.BasicInformation.FirstName, apiRespons.BasicInformation.LastName,
apiRespons.BasicInformation.FatherName,idNumber,apiRespons.IdentificationInformation.ShenasnameSeri,
apiRespons.IdentificationInformation.ShenasnameSerial,
apiRespons.IdentificationInformation.BirthDate,apiRespons.BasicInformation.GenderEnum,contractingParty.Phone);
await _context.SaveChangesAsync();
}
}
return true;
}
public ContractingPartyTempViewModel GetByNationalCode(string nationalCode)
{
return _context.ContractingPartyTemps.Select(x => new ContractingPartyTempViewModel
{
Id = x.id,
DateOfBirth = x.DateOfBirth,
DateOfBirthFa = x.DateOfBirth.ToFarsi(),
IdNumberSeri = x.IdNumberSeri,
IdNumberSerial = x.IdNumberSerial,
Address = x.Address,
City = x.City,
FatherName = x.FatherName,
FName = x.FName,
LName = x.LName,
Gender = x.Gender,
NationalCode = x.NationalCode,
IdNumber = x.IdNumber,
Phone = x.Phone,
State = x.State,
}).FirstOrDefault(x => x.NationalCode == nationalCode);
}
public ContractingPartyTempViewModel GetByContractingPartyTempId(long contractingPartyTempId)
{
return _context.ContractingPartyTemps.Select(x => new ContractingPartyTempViewModel
{
Id = x.id,
DateOfBirth = x.DateOfBirth,
DateOfBirthFa = x.DateOfBirth.ToFarsi(),
IdNumberSeri = x.IdNumberSeri,
IdNumberSerial = x.IdNumberSerial,
Address = x.Address,
City = x.City,
FatherName = x.FatherName,
FName = x.FName,
LName = x.LName,
Gender = x.Gender,
NationalCode = x.NationalCode,
IdNumber = x.IdNumber,
Phone = x.Phone,
State = x.State,
}).FirstOrDefault(x => x.Id == contractingPartyTempId);
}
}