示例#1
0
        public IActionResult GetById(int id, [FromServices] LoanDb db)
        {
            Loan loan = _loanDao.GetById(id, db);

            if (loan == null)
            {
                return(StatusCode((int)HttpStatusCode.NotFound, new { error = $"no entity found by id: {id}" }));
            }
            return(Ok(loan));
        }
        public IActionResult GetById(int id, [FromServices] LoanDb db)
        {
            Loan loan;

            try { loan = _loanDao.GetById(id, db); }
            catch (InvalidOperationException) { return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = "more than one loan found for the given id" })); }

            if (loan == null)
            {
                return(NotFound(new { error = $"no loan found by id: {id}" }));
            }
            return(Ok(loan));
        }