public async Task <ActionResult <Account> > Deposit(Transaction transaction) { var state = await _stateClient.GetStateEntryAsync <Account>(StoreName, transaction.Id); state.Value ??= new Account() { Id = transaction.Id, }; state.Value.Balance += transaction.Amount; await state.SaveAsync(); return(state.Value); }
public async Task <ActionResult <Account> > Withdraw(Transaction transaction, [FromServices] StateClient stateClient) { var state = await stateClient.GetStateEntryAsync <Account>(StoreName, transaction.Id); if (state.Value == null) { return(this.NotFound()); } state.Value.Balance -= transaction.Amount; await state.SaveAsync(); return(state.Value); }
public async Task <ActionResult <int> > Transaction(Transaction transaction, [FromServices] StateClient stateClient) { var account = await stateClient.GetStateEntryAsync <int?>(StateStore, transaction.AccountId); switch (transaction.Type) { case "deposit": return(await this.Deposit(account, transaction.Amount)); case "withdraw": return(await this.Withdraw(account, transaction.Amount)); default: return(this.NotFound()); } }
public async Task <User> GetUserWithOrders(Guid userId) { var state = await _stateClient.GetStateEntryAsync <User>(userId.ToString()); return(state.Value); }