Ejemplo n.º 1
0
        CreateQuotaValidations(CreateQuotasRequest createQuotasRequest, ref InfoClientDto infoClientDto)
        {
            (bool clientIsValid, HttpStatusCode clientatusCode, string clientMessage) =
                ClientValidations(createQuotasRequest.IdClient, createQuotasRequest.Quotas.Sum(c => c.CapitalValue),
                                  ref infoClientDto);
            if (!clientIsValid)
            {
                return(false, clientatusCode, clientMessage);
            }
            long idCredit = createQuotasRequest.Quotas.FirstOrDefault().IdCredit;

            if (createQuotasRequest.Quotas.Count > 1)
            {
                foreach (QuotaDataDto quota in createQuotasRequest.Quotas)
                {
                    if (quota.IdCredit != idCredit)
                    {
                        return(false, HttpStatusCode.BadRequest, IdCreditError);
                    }
                }
            }
            if (!_quotaRepository.CreditExist(createQuotasRequest.IdClient, idCredit).Result)
            {
                return(false, HttpStatusCode.BadRequest, CreditNoExist);
            }
            return(true, HttpStatusCode.OK, "");
        }
Ejemplo n.º 2
0
        private SimulateQuotasResponse GetResponse(InfoClientDto infoClientDto,
                                                   SimulateQuotasRequest simulateQuotasRequest)
        {
            List <QuotaDataDto> quotas = CalculateQuotas(simulateQuotasRequest);

            return(new SimulateQuotasResponse
            {
                AvailableSpaceSimulated = infoClientDto.AvailableSpace - simulateQuotasRequest.CapitalValue,
                Quotas = quotas,
                TotalCreditValue = quotas.Sum(c => c.TotalValue)
            });
        }
Ejemplo n.º 3
0
        SimulateQuotas(SimulateQuotasRequest simulateQuotasRequest)
        {
            InfoClientDto infoClientDto = null;

            (bool isValid, HttpStatusCode validationStatusCode, string validationMessage) =
                SimulateQuotaValidations(simulateQuotasRequest, ref infoClientDto);
            if (!isValid)
            {
                return(validationStatusCode, validationMessage, null);
            }
            return(HttpStatusCode.OK, SuccessMsg,
                   GetResponse(infoClientDto, simulateQuotasRequest));
        }
Ejemplo n.º 4
0
 ClientValidations(long idClient, decimal capitalValue, ref InfoClientDto infoClientDto)
 {
     infoClientDto = _clientProvider.GetInfoClient(idClient).Result;
     if (infoClientDto == null)
     {
         return(false, HttpStatusCode.BadRequest, ClientNoExistMsg);
     }
     if (infoClientDto.AvailableSpace < capitalValue)
     {
         return(false, HttpStatusCode.PreconditionFailed, NoAvalibleSpaceMsg);
     }
     return(true, HttpStatusCode.OK, "");
 }
Ejemplo n.º 5
0
 ClientValidations(long idClient, decimal capitalValue, ref InfoClientDto infoClientDto)
 {
     infoClientDto = infoClientMock;
     if (infoClientDto == null)
     {
         return(false, HttpStatusCode.BadRequest, ClientNoExistMsg);
     }
     if (infoClientDto.AvailableSpace < capitalValue)
     {
         return(false, HttpStatusCode.PreconditionFailed, NoAvalibleSpaceMsg);
     }
     return(true, HttpStatusCode.OK, string.Empty);
 }
Ejemplo n.º 6
0
        CreateQuotas(CreateQuotasRequest createQuotasRequest)
        {
            InfoClientDto infoClientDto = null;

            (bool isValid, HttpStatusCode validationStatusCode, string validationMessage) =
                CreateQuotaValidations(createQuotasRequest, ref infoClientDto);
            if (!isValid)
            {
                return(validationStatusCode, validationMessage, false);
            }
            List <QuotaEntity> quotas = _mapper.Map <List <QuotaEntity> >(createQuotasRequest.Quotas);

            return(HttpStatusCode.OK, SuccessMsg, _quotaRepository.Create(quotas).Result);
        }
Ejemplo n.º 7
0
 SimulateQuotaValidations(SimulateQuotasRequest simulateQuotasRequest, ref InfoClientDto infoClientDto)
 {
     (bool clientIsValid, HttpStatusCode clientatusCode, string clientMessage) =
         ClientValidations(simulateQuotasRequest.IdClient, simulateQuotasRequest.CapitalValue,
                           ref infoClientDto);
     if (!clientIsValid)
     {
         return(false, clientatusCode, clientMessage);
     }
     if (!ValidateTermMonths(simulateQuotasRequest))
     {
         return(false, HttpStatusCode.BadRequest, TermNoAllowedMsg);
     }
     return(true, HttpStatusCode.OK, "");
 }
Ejemplo n.º 8
0
        Create(CreditDataDto credit)
        {
            InfoClientDto infoClientDto = null;

            (bool valid, HttpStatusCode creditStatus, string creditMsg) =
                CreateCreditValidations(credit, ref infoClientDto);
            if (!valid)
            {
                return(creditStatus, creditMsg, false);
            }
            CreditEntity       creditEntity  = _mapper.Map <CreditEntity>(credit);
            ClientEntity       clientEntity  = _mapper.Map <ClientEntity>(infoClientDto);
            List <QuotaEntity> quotaEntities = _mapper.Map <List <QuotaEntity> >(credit.Quotas);

            clientEntity.CupoDisponible = clientEntity.CupoDisponible - credit.CapitalValue;
            creditEntity.FechaCreacion  = ColombianHour.GetDate();
            _ = _creditRepository.Create(creditEntity, clientEntity, quotaEntities);
            return(HttpStatusCode.OK, SuccessMsg, true);
        }
Ejemplo n.º 9
0
 CreateCreditValidations(CreditDataDto credit, ref InfoClientDto infoClientDto)
 {
     (bool clientValid, HttpStatusCode clientStatus, string clientMessage) =
         ClientValidations(credit.IdClient, credit.CapitalValue, ref infoClientDto);
     if (!clientValid)
     {
         return(false, clientStatus, clientMessage);
     }
     if (!ValidateTermMonths(credit))
     {
         return(false, HttpStatusCode.BadRequest, TermNoAllowedMsg);
     }
     (bool quotasValid, HttpStatusCode quotasStatus, string quotasMessage) =
         QuotasValidations(credit);
     if (!quotasValid)
     {
         return(false, quotasStatus, quotasMessage);
     }
     return(true, HttpStatusCode.OK, string.Empty);
 }