Ejemplo n.º 1
0
        public async Task <IActionResult> GetLoanRepayments([FromBody] List <LoanCalculatorViewModel> repaymentsToCalculate)
        {
            try
            {
                if (!ModelState.IsValid || repaymentsToCalculate.Count < 0)
                {
                    //if (!ModelState.IsValid)
                    //{
                    //    //Is able to produces unwanted error messages
                    //    var errors = ModelState.Select(x => x.Value.Errors).ToList();
                    //    return Json(new { Success = false, Message = errors });
                    //}
                    //else
                    //{
                    return(Json(new { Success = false, Message = "Invalid input formatting" }));
                    //}
                }

                List <LoanRepaymentsModel> repaymentsCalculated = await _loanService.CalculateLoanRepayments(repaymentsToCalculate);

                return(Json(new { Success = true, repaymentsCalculated }));
            }
            catch (Exception e)
            {
                return(Json(new { Success = false, Message = "Internal Server Error" }));
            }
        }