public void Create()
 {
     #region MockValues
     List <QuotaDataDto> quotasMock = new List <QuotaDataDto>();
     for (int i = 1; i <= 4; i++)
     {
         quotasMock.Add(new QuotaDataDto
         {
             IdQuota      = i,
             IdCredit     = 1,
             CapitalValue = 22500,
             TotalValue   = 23625,
             PaymentDate  = DateTime.Now
         });
     }
     CreditDataDto creditMock = new CreditDataDto
     {
         IdClient     = 1,
         CapitalValue = 90000,
         Frequency    = 15,
         TermMonths   = 2,
         TotalValue   = 94500,
         Quotas       = quotasMock
     };
     #endregion
     var actionResult = _controller.Create(creditMock).Result as ObjectResult;
     var result       = actionResult.Value as HttpResponseDto <bool>;
     Assert.NotNull(result);
     Assert.Equal(200, result.Code);
     var response = result.Object;
     Assert.IsType <bool>(response);
     Assert.True(response);
 }
Exemple #2
0
        QuotasValidations(CreditDataDto credit)
        {
            int quotaQuantity = credit.TermMonths * ((credit.Frequency == 15) ? 2 : 1);

            if (quotaQuantity != credit.Quotas.Count)
            {
                return(false, HttpStatusCode.BadRequest, FrequencyErrorMsg);
            }
            return(true, HttpStatusCode.OK, string.Empty);
        }
        public async Task <IActionResult> Create([FromBody] CreditDataDto credit)
        {
            (HttpStatusCode statusCode, string message, bool response) =
                await _creditBusiness.Create(credit);

            if (statusCode != HttpStatusCode.NoContent && Response != null)
            {
                Response.StatusCode = (int)statusCode;
            }
            return(ServiceAnswer <bool> .Response(statusCode, message, response));
        }
Exemple #4
0
        private bool ValidateTermMonths(CreditDataDto credit)
        {
            List <TermDto> termsDto     = _config.GetSection("CommonValues:Terms").Get <List <TermDto> >();
            List <int>     allowedTerms = new List <int>();

            foreach (TermDto term in termsDto)
            {
                if ((credit.CapitalValue >= term.From &&
                     credit.CapitalValue <= term.To) ||
                    credit.CapitalValue > term.To)
                {
                    allowedTerms.Add(term.Months);
                }
            }
            return(allowedTerms.Contains(credit.TermMonths));
        }
Exemple #5
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);
        }
Exemple #6
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);
 }
Exemple #7
0
        GetById(long idCredit)
        {
            CreditEntity credit = _creditRepository.GetById(idCredit).Result;

            if (credit == null)
            {
                return(HttpStatusCode.NoContent, CreditNoExistMsg, null);
            }
            CreditDataDto prb = new CreditDataDto();

            prb = _mapper.Map(credit, prb);
            return(HttpStatusCode.OK, SuccessMsg, new CreditDataDto
            {
                IdClient = credit.IdCliente,
                IdCredit = credit.IdCredito,
                TermMonths = credit.Plazo,
                Frequency = credit.Frecuencia,
                CapitalValue = credit.ValorCapital,
                TotalValue = credit.ValorTotal,
                CreationDate = credit.FechaCreacion
            });
        }