/// <inheritdoc /> /// <exception cref="UserNotFoundException">Thrown when the user is not found</exception> /// <exception cref="BankAccountNotFoundException">thrown when the bank account is not found</exception> public async Task RemoveBankAccount(RemoveBankAccountBody removeBankAccountBody) { var user = await ApplicationContext.Users.Include(x => x.BankAccounts) .FirstOrDefaultAsync(x => x.Id == removeBankAccountBody.UserId); if (user == null) { throw new UserNotFoundException(); } var bankAccount = user.BankAccounts.First(); if (bankAccount == null) { throw new BankAccountNotFoundException(); } var service = new AccountService(); // request delete bank account from the Stripe api service.Delete(user.StripeAccountId); try { user.StripeAccountId = null; ApplicationContext.BankAccounts.Remove(bankAccount); await ApplicationContext.SaveChangesAsync(); } catch (Exception e) { Logger.LogWarning(e.Message); throw; } }
public async Task <ActionResult> RemoveBankAccount(RemoveBankAccountBody removeBankAccountBody) { try { Logger.LogInformation("{Id} is removing a bank", removeBankAccountBody.UserId); await BankingService.RemoveBankAccount(removeBankAccountBody); return(Ok()); } catch (Exception e) { Logger.LogWarning(e.ToString()); return(BadRequest(e)); } }