public async Task <CreditResult> Apply(CreditApplyRequest request) { var score = await _creditScoreService.GetScore(request.IdentificationNumber); var creditParameters = new CreditParameters { Salary = request.Salary, Score = score }; var limit = _limitCalculator.Calculate(creditParameters); if (limit <= 0) { return(CreditResult.Fail()); } var credit = new Credit { IdentificationNumber = request.IdentificationNumber, Name = request.Name, Surname = request.Surname, Salary = request.Salary, TelephoneNumber = request.TelephoneNumber, CreditLimit = limit }; await _creditRepository.InsertAsync(credit); return(CreditResult.Success(limit)); }
public async Task <IActionResult> Apply([FromBody] CreditApplyRequest request) { var creditResult = await _creditService.Apply(request); if (creditResult.Status == CreditStatus.NotApplied) { return(BadRequest(creditResult)); } return(Ok(creditResult)); }