public ActionResult <RegistrarCreditoResponse> Post(RegistrarCreditoRequest request) { RegistrarCreditoService _service = new RegistrarCreditoService(_unitOfWork); RegistrarCreditoResponse respuestaServicio = _service.EjecutarServicio(request); return(Ok(respuestaServicio)); }
public void RegistrarCreditoInMemoryTest() { var request = new RegistrarCreditoRequest { Cedula = 1065842658, FechaPrestamo = new DateTime(2019, 05, 05), ValorPrestamo = 1200000, PlazoPago = 12 }; RegistrarCreditoService _service = new RegistrarCreditoService(new UnitOfWork(_contextInMemory)); var response = _service.EjecutarServicio(request); Assert.AreEqual($"Crédito registrado correctamente, Cuota mensual de 100000", response.Mensaje); }
public void ValidarCreditoExistenteTest() { var request = new RegistrarCreditoRequest { Cedula = 1065842658, FechaPrestamo = new DateTime(2019, 05, 05), ValorPrestamo = 1200000, PlazoPago = 12 }; RegistrarCreditoService _service = new RegistrarCreditoService(new UnitOfWork(_contextInMemory)); var response = _service.EjecutarServicio(request); var requestDos = new RegistrarCreditoRequest { Cedula = 1065842658, FechaPrestamo = new DateTime(2019, 06, 01), ValorPrestamo = 1300000, PlazoPago = 2 }; RegistrarCreditoService _serviceDos = new RegistrarCreditoService(new UnitOfWork(_contextInMemory)); var responseDos = _service.EjecutarServicio(requestDos); Assert.AreEqual($"El Credito ya existe", responseDos.Mensaje); }
public RegistrarCreditoResponse EjecutarServicio(RegistrarCreditoRequest request) { Credito credito = _unitOfwork.CreditoRepository.FindFirstOrDefault(x => x.Cedula == request.Cedula); if (credito == null) { credito = new Credito( request.Cedula, request.ValorPrestamo, request.FechaPrestamo, request.PlazoPago ); if (credito.IsValidarPlazoPago() == true) { return(new RegistrarCreditoResponse() { Mensaje = "El Plazo de pago debe ser menor o igual a 12" }); } else { _unitOfwork.CreditoRepository.Add(credito); _unitOfwork.Commit(); return(new RegistrarCreditoResponse() { Mensaje = $"Crédito registrado correctamente, Cuota mensual de {credito.CalcularValorCuota()}" }); } } else { return(new RegistrarCreditoResponse() { Mensaje = $"El Credito ya existe" }); } }