public async Task <ActionResult <CreditModel> > Put(int InvoiceId, int Id, CreditModel updatedModel) { try { var currentCredit = await _repository.GetCreditAsync(InvoiceId, Id); if (currentCredit == null) { return(NotFound($"Could not find Credit with Id of {Id}")); } _mapper.Map(updatedModel, currentCredit); if (await _repository.UpdateCreditAsync(InvoiceId, currentCredit)) { return(_mapper.Map <CreditModel>(currentCredit)); } } catch (Exception e) { _logger.LogError(e, e.Message); return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }
public async Task <bool> SaveAndProcessCredit(ICreditRepository creditRepositery, int invoiceId, Credit credit) { try { await creditRepositery.StoreNewCreditAsync(invoiceId, credit); credit = await ProcessCreditWithBankAsync(credit); await creditRepositery.UpdateCreditAsync(invoiceId, credit); } catch (Exception e) { _logger.LogError(e, e.Message); return(false); } return(true); }