Ejemplo n.º 1
0
        public bool ExecuteTransaction(Func <long, bool> condition, Action <RefLong> ifTrue, Action <RefLong> ifFalse = null)
        {
            lock (_balance)
            {
                bool conditionResult = condition(_balance.Value);

                RefLong dummyBalance = new RefLong(_balance.Value);

                if (conditionResult)
                {
                    ifTrue(dummyBalance);
                }
                else
                {
                    ifFalse?.Invoke(dummyBalance);
                }

                if (_balance.Value != dummyBalance.Value)
                {
                    _balance.Value = dummyBalance.Value;
                    _userService.SaveChanges(UserId, _balance.Value);
                }

                return(conditionResult);
            }
        }
Ejemplo n.º 2
0
 public Balance(string userId, long balance, UserService userService)
 {
     UserId       = userId;
     _balance     = new RefLong(balance);
     _userService = userService;
 }