public async Task <decimal> DepositCurrencyAccountAsync(DepositCurrencyDTO request) { decimal result; var currencyAccount = await DbContext.CurrencyAccounts .Include(nameof(CurrencyAccount.Holder)) .FirstOrDefaultAsync(acc => acc.Number == request.CurrencyAccount && acc.Holder.PINCode == request.PinCode); if (currencyAccount == null) { throw new AccountNotFoundException(); } currencyAccount.Debit += request.Sum; try { DbContext.Update(currencyAccount); await DbContext.SaveChangesAsync(); result = currencyAccount.Debit; } catch (DbUpdateConcurrencyException ex) { throw new ConcurrencyException(); } return(result); }
public async Task <IActionResult> DepositCurrencyAccount(string accountNumber, [FromBody] DepositCurrencyDTO request) { if (string.IsNullOrEmpty(accountNumber) || accountNumber != request.CurrencyAccount ) { ModelState.AddModelError("", AccountNotFoundException.DefaultErrorMessage); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await PocketService.DepositCurrencyAccountAsync(request); return(new JsonResult(result)); } catch (Exception ex) { return(HandleException(ex)); } }