예제 #1
0
        public async Task <List <SeizedPropertyAvailabilityResultModel> > GetPaidReport(string paidGuid)
        {
            var paymentRequest = await _context.PaymentRequest
                                 .Include(x => x.EservicePaymentRequest).ThenInclude(x => x.SeizedPropertyReportRequest).ThenInclude(x => x.CheckedCompany)
                                 .Include(x => x.EservicePaymentRequest).ThenInclude(x => x.SeizedPropertyReportRequest).ThenInclude(x => x.CheckedPerson)
                                 .Where(x => x.PaymentReferenceNumber.Equals(paidGuid))
                                 .FirstOrDefaultAsync();

            if (paymentRequest == null)
            {
                throw new Exception($"There is no payment for guid: {paidGuid}");
                // TODO: Log
            }

            var eServicePayment = paymentRequest.EservicePaymentRequest.FirstOrDefault();

            if (eServicePayment == null)
            {
                throw new Exception($"There is no EservicePaymentRequest for guid: {paidGuid}");
                // TODO: Log
            }

            if (eServicePayment.SeizedPropertyReportRequestId.HasValue)
            {
                var request = eServicePayment.SeizedPropertyReportRequest;
                var model   = new SeizedPropertyAvailabilityRequestModel
                {
                    IsCheckedPerson = request.IsCheckedPerson
                };
                if (request.IsCheckedPerson)
                {
                    model.CheckedPerson = new Models.Person.PersonModel
                    {
                        FirstName            = request.CheckedPerson.FirstName,
                        MiddleName           = request.CheckedPerson.MiddleName,
                        LastName             = request.CheckedPerson.LastName,
                        Email                = request.CheckedPerson.Email,
                        IdentificationType   = request.CheckedPerson.IdentificationNumberType,
                        IdentificationNumber = request.CheckedPerson.IdentificationNumber
                    };
                }
                else
                {
                    model.CheckedCompany = new Models.Company.CompanyModel
                    {
                        Name = request.CheckedCompany.Name,
                        EIK  = request.CheckedCompany.Eik,
                        CompanyCaseNumber = request.CheckedCompany.CompanyCaseNumber
                    };
                }

                var result = await CreateSearchResultAsync(model);

                return(result);
            }
            else
            {
                throw new Exception($"There is no SeizedPropertyReportRequest for guid: {paidGuid}");
            }
        }
예제 #2
0
        private bool HasToPay(SeizedPropertyAvailabilityRequestModel model, string currentUserId)
        {
            if (string.IsNullOrWhiteSpace(currentUserId))
            {
                return(true);
            }

            // Todo: Да се прецезира кога трябва да се плаща
            return(false);
        }
        public async Task <IActionResult> Search(SeizedPropertyAvailabilityRequestModel model)
        {
            try
            {
                // TODO: UserId
                (bool hasToPay, PaymentRequestSendResultModel paymentRequestModel, IEnumerable <SeizedPropertyAvailabilityResultModel> searchModels) = await _service.Search(model, CurrentUserId);

                string message = "";
                if (paymentRequestModel != null)
                {
                    string email = model?.Requester?.Email;
                    if (string.IsNullOrWhiteSpace(email) == false)
                    {
                        string subject = "Регистрация на заявка в системата за електронно плащане";
                        string body    = message = paymentRequestModel.IsSuccessStatusCode == false
                            ? $"Неуспешна регистрация на заявка в системата за електронно плащане. За детайли посетете платформата за електронно плащане на адрес: {(_settings.UseTestEnv ? "https://pay-test.egov.bg/" : "https://pay.egov.bg/")}"
                            : (paymentRequestModel.UnacceptedReceipt != null
                                ? $"Регистрация на заявка в системата за електронно плащане е отхвърлена. За детайли посетете платформата за електронно плащане на адрес: {(_settings.UseTestEnv ? "https://pay-test.egov.bg/" : "https://pay.egov.bg/")}"
                                : $"Успешна регистрация на заявка с ИД №: {paymentRequestModel.AcceptedReceipt?.Id} в системата за електронно плащане. За детайли и плащане посетете платформата за електронно плащане на адрес: {(_settings.UseTestEnv ? "https://pay-test.egov.bg/" : "https://pay.egov.bg/")}"
                               );
                        _emailService.SendEmail(email, null, null, subject, body);
                    }
                }

                bool isSuccessful = false;
                if (paymentRequestModel != null && paymentRequestModel.IsSuccessStatusCode)
                {
                    isSuccessful = true;
                }

                return(Ok(new { items = searchModels, message, isSuccessfull = isSuccessful }));
            }
            catch (System.Exception ex)
            {
                Log.Error(ex, $"ERROR searching for seized property availability report");
                return(BadRequest("Error searching for seized property availability report"));
            }
        }
예제 #4
0
        private Task <List <SeizedPropertyAvailabilityResultModel> > CreateSearchResultAsync(SeizedPropertyAvailabilityRequestModel model)
        {
            var result = _context.Distraint
                         .Include(x => x.DebtorPerson)
                         .Include(x => x.DebtorCompany)
                         .AsQueryable();

            if (model.IsCheckedPerson)
            {
                return(result.Where(x => x.DebtorPerson.Identifier == model.CheckedPerson.IdentificationNumber.Trim() &&
                                    (x.DebtorPerson.FirstName.ToLower().Contains(model.CheckedPerson.FirstName.Trim().ToLower()) ||
                                     (!string.IsNullOrEmpty(model.CheckedPerson.MiddleName) && x.DebtorPerson.MiddleName.Contains(model.CheckedPerson.MiddleName.Trim().ToLower())) ||
                                     x.DebtorPerson.LastName.Contains(model.CheckedPerson.LastName.Trim().ToLower())))
                       .Select(x => new SeizedPropertyAvailabilityResultModel
                {
                    DistraintId = x.Id,
                    Name = $"{x.DebtorPerson.FirstName} {x.DebtorPerson.MiddleName} {x.DebtorPerson.LastName}",
                    PropertyTypeName = x.PropertyTypeCodeNavigation.Name,
                    PropertyTypeNameEn = x.PropertyTypeCodeNavigation.NameEn,
                    StatusName = x.StatusCodeNavigation.Name,
                    StatusNameEn = x.StatusCodeNavigation.NameEn
                })
                       .ToListAsync());
            }
            else
            {
                return(result.Where(x => x.DebtorCompany.Uic == model.CheckedCompany.EIK &&
                                    x.DebtorCompany.Name.ToLower().Contains(model.CheckedCompany.Name.Trim().ToLower()))
                       .Select(x => new SeizedPropertyAvailabilityResultModel
                {
                    DistraintId = x.Id,
                    Name = $"{x.DebtorCompany.Name}",
                    PropertyTypeName = x.PropertyTypeCodeNavigation.Name,
                    PropertyTypeNameEn = x.PropertyTypeCodeNavigation.NameEn,
                    StatusName = x.StatusCodeNavigation.Name,
                    StatusNameEn = x.StatusCodeNavigation.NameEn
                })
                       .ToListAsync());
            }
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        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;
                }
            }
        }