public async Task <IActionResult> Delete(string id) { var loan = await _loanService.GetByIdAsync(id); if (loan == null) { return(NotFound()); } var collections = await _collectionService.GetByLoanIdAsync(loan.Id); if (collections.Any()) { await _collectionService.DeleteAllAsync(loan.Id); } await _loanService.DeleteAsync(id); return(NoContent()); }