private async Task <ApplicantData> GetApplicantDataAsync(Shared.Enums.EServiceType serviceType, int requestId) { Shared.Enums.IdentificationType applicantIdentifierType = Shared.Enums.IdentificationType.EGN; string applicantIdentifier = ""; string applicantName = ""; if (serviceType == Shared.Enums.EServiceType.SEIZEDPROPERTYCERTIFICATE) { RequestForCertificateOfDistraintOfProperty req = await _context.RequestForCertificateOfDistraintOfProperty .Where(x => x.Id == requestId) .FirstOrDefaultAsync(); if (req != null) { bool isCompany = String.IsNullOrWhiteSpace(req.PersonalIdentifier); if (isCompany) { applicantIdentifierType = Shared.Enums.IdentificationType.BULSTAT; applicantIdentifier = req.IdentifierOfLegalEntity; applicantName = req.NameOfLegalEntity; } else { if (req.IsPersonalIdentifierTypeLnch == true) { applicantIdentifierType = Shared.Enums.IdentificationType.LNCH; } applicantIdentifier = req.PersonalIdentifier; applicantName = $"{req.FirstName ?? ""} {req.MiddleName ?? ""} {req.LastName ?? ""}"; } } } else if (serviceType == Shared.Enums.EServiceType.SEIZEDPROPERTYBYOWNERREPORT) { SeizedPropertyAvailabilityRequest req = await _context.SeizedPropertyAvailabilityRequest .Include(x => x.RequestorPerson) .Include(x => x.RequesterCompany) .Where(x => x.Id == requestId) .FirstOrDefaultAsync(); if (req != null) { if (req.RequestorPerson != null) { applicantIdentifier = req.RequestorPerson.IdentificationNumber; applicantName = $"{req.RequestorPerson.FirstName ?? ""} {req.RequestorPerson.MiddleName ?? ""} {req.RequestorPerson.LastName ?? ""}"; } else if (req.RequesterCompany != null) { applicantIdentifierType = Shared.Enums.IdentificationType.BULSTAT; applicantIdentifier = req.RequesterCompany.Eik; applicantName = req.RequesterCompany.Name; } } } ApplicantData data = new ApplicantData(applicantIdentifierType, applicantIdentifier, applicantName); return(data); }
/// <summary> /// Създаваме запис за заявлението за справка за наличие на запорирано имущество на лица в таблица SeizedPropertyAvailabilityRequest. /// </summary> /// <param name="model"></param> /// <param name="currentUserId"></param> /// <returns></returns> private async Task <SeizedPropertyAvailabilityRequest> SaveSeizedPropertyAvailabilityRequestAsync(SeizedPropertyAvailabilityRequestModel model, string currentUserId) { var requestedPerson = new Person() { FirstName = model.Requester.FirstName, MiddleName = model.Requester.MiddleName, LastName = model.Requester.LastName, IdentificationNumberType = model.Requester.IdentificationType, IdentificationNumber = model.Requester.IdentificationNumber, Phone = model.Requester.Phone, Email = model.Requester.Email }; if (model.Requester.Address != null) { requestedPerson.Address = new Address { CityId = model.Requester.Address.CityId, RegionId = model.Requester.Address.RegionId, MunicipalityId = model.Requester.Address.MunicipalityId, StreetAddress = model.Requester.Address.StreetAddress }; } var checkedPerson = new Person(); if (model.IsCheckedPerson) { checkedPerson.FirstName = model.CheckedPerson.FirstName; checkedPerson.MiddleName = model.CheckedPerson.MiddleName; checkedPerson.LastName = model.CheckedPerson.LastName; checkedPerson.IdentificationNumberType = model.CheckedPerson.IdentificationType; checkedPerson.IdentificationNumber = model.CheckedPerson.IdentificationNumber; checkedPerson.Phone = model.CheckedPerson.Phone; checkedPerson.Email = model.CheckedPerson.Email; if (model.CheckedPerson.Address != null) { checkedPerson.Address = new Address { CityId = model.CheckedPerson.Address.CityId, RegionId = model.CheckedPerson.Address.RegionId, MunicipalityId = model.CheckedPerson.Address.MunicipalityId, StreetAddress = model.CheckedPerson.Address.StreetAddress }; } } var checkedCompany = new Company(); if (!model.IsCheckedPerson) { checkedCompany.Name = model.CheckedCompany.Name; checkedCompany.Eik = model.CheckedCompany.EIK; checkedCompany.CompanyCaseNumber = model.CheckedCompany.CompanyCaseNumber; if (model.CheckedCompany.Address != null) { checkedCompany.Address = new Address { CityId = model.CheckedCompany.Address.CityId, RegionId = model.CheckedCompany.Address.RegionId, MunicipalityId = model.CheckedCompany.Address.MunicipalityId, StreetAddress = model.CheckedCompany.Address.StreetAddress }; } } SeizedPropertyAvailabilityRequest toAdd = new SeizedPropertyAvailabilityRequest { RequestorPerson = string.IsNullOrEmpty(currentUserId) ? requestedPerson : null, RequestorUserId = currentUserId, InTheQualityOfPersonTypeCode = model.InTheQualityOfPersonTypeCode, RequesterCompanyRepresentative = model.RequesterCompanyRepresentative, RequesterCompanyEik = model.RequesterCompanyEik, RequesterCompanyCaseNumber = model.RequesterCompanyCaseNumber, Date = DateTime.UtcNow, // TODO: Да се взема от... някакъв сървис... IsCheckedPerson = model.IsCheckedPerson, CheckedPerson = model.IsCheckedPerson ? checkedPerson : null, CheckedCompany = model.IsCheckedPerson ? null : checkedCompany }; _context.SeizedPropertyAvailabilityRequest.Add(toAdd); await _context.SaveChangesAsync(); return(toAdd); }
public async Task <(bool hasToPay, PaymentRequestSendResultModel paymentRequestModel, IEnumerable <SeizedPropertyAvailabilityResultModel> searchModels)> Search(SeizedPropertyAvailabilityRequestModel model, string currentUserId) { SeizedPropertyAvailabilityRequest entry = await SaveSeizedPropertyAvailabilityRequestAsync(model, currentUserId); bool hasToPay = HasToPay(model, currentUserId); if (!HasToPay(model, currentUserId)) { // Не се изисква плащане. Връщаме резултат List <SeizedPropertyAvailabilityResultModel> searchModels = await CreateSearchResultAsync(model); return(hasToPay, paymentRequestModel : null, searchModels); } using (var tran = await _context.Database.BeginTransactionAsync()) { try { PaymentRequestSendResultModel paymentRequestModel = await CreateTaxMeRequest(entry.Id); if (paymentRequestModel == null) { // Неуспешен запис на заявка за ел.плащане в системата за ел.плащане await tran.RollbackAsync(); return(hasToPay, paymentRequestModel, null); } var eservicePaymentRequest = await _context.EservicePaymentRequest.Where(x => x.SeizedPropertyReportRequestId == entry.Id).FirstOrDefaultAsync(); if (eservicePaymentRequest != null) { // Запис на резултат от изпращането на заявка за ел.плащане. DateTime utcNow = DateTime.UtcNow; EservicePaymentRequestStatusHistory historyRecord = new EservicePaymentRequestStatusHistory { RequestId = eservicePaymentRequest.Id, UpdatedAt = utcNow }; eservicePaymentRequest.UpdatedAt = utcNow; if (!paymentRequestModel.IsSuccessStatusCode) { eservicePaymentRequest.StatusCode = Shared.Enums.PaymentRequestStatus.ERROR.ToString(); historyRecord.StatusCode = Shared.Enums.PaymentRequestStatus.ERROR.ToString(); historyRecord.Errors = paymentRequestModel.ErrorMessage; } else { if (paymentRequestModel.UnacceptedReceipt != null) { eservicePaymentRequest.StatusCode = Shared.Enums.PaymentRequestStatus.REJECTED.ToString(); historyRecord.StatusCode = Shared.Enums.PaymentRequestStatus.REJECTED.ToString(); historyRecord.EserviceTime = paymentRequestModel.UnacceptedReceipt.ValidationTime; } else { eservicePaymentRequest.StatusCode = Shared.Enums.PaymentRequestStatus.PENDING.ToString(); eservicePaymentRequest.AisPaymentId = paymentRequestModel.AcceptedReceipt.Id; historyRecord.StatusCode = Shared.Enums.PaymentRequestStatus.PENDING.ToString(); historyRecord.EserviceTime = paymentRequestModel.AcceptedReceipt.RegistrationTime; } } _context.EservicePaymentRequestStatusHistory.Add(historyRecord); await _context.SaveChangesAsync(); } await tran.CommitAsync(); return(hasToPay, paymentRequestModel, null); } catch (Exception) { await tran.RollbackAsync(); throw; } } }