Esempio n. 1
0
        public WalletError GetTransferExtendedInfo(ProtectedOperationContext secCtx,
                                                   int transferId, out BalanceChange balanceChange, out PlatformUser user)
        {
            balanceChange = null;
            user          = null;

            if (!UserSessionStorage.Instance.PermitUserOperation(secCtx, false, false))
            {
                return(WalletError.InsufficientRights);
            }

            var error = WalletError.ServerError;

            try
            {
                using (var ctx = DatabaseContext.Instance.Make())
                {
                    var trans = ctx.TRANSFER.FirstOrDefault(t => t.ID == transferId);
                    if (trans == null)
                    {
                        return(WalletError.InvalidData);
                    }
                    if (trans.BalanceChange.HasValue)
                    {
                        balanceChange = LinqToEntity.DecorateBalanceChange(trans.BALANCE_CHANGE);
                        return(WalletError.OK);
                    }
                    if (trans.RefWallet.HasValue)
                    {
                        var us = ctx.PLATFORM_USER.FirstOrDefault(u => u.ID == trans.RefWallet.Value);
                        if (us != null)
                        {
                            user          = LinqToEntity.DecoratePlatformUser(us);
                            user.Password = string.Empty;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("GetTransferExtendedInfo({0}) error: {1}", transferId, ex);
                error = WalletError.ServerError;
            }
            return(error);
        }
Esempio n. 2
0
        private ACCOUNT GetAccountData(int accountId, out List <BalanceChange> transfers)
        {
            if (testOnly)
            {
                transfers = new List <BalanceChange>
                {
                    new BalanceChange
                    {
                        AccountID  = accountId,
                        Amount     = startDepo,
                        ChangeType = BalanceChangeType.Deposit,
                        Currency   = "USD",
                        ValueDate  = startTime
                    }
                };

                return(new ACCOUNT
                {
                    ID = accountId,
                    Balance = startDepo,
                    Currency = "USD",
                    AccountGroup = "Demo",
                    TimeCreated = startTime
                });
            }

            ACCOUNT accountData;

            try
            {
                using (var conn = DatabaseContext.Instance.Make())
                {
                    accountData = conn.ACCOUNT.First(a => a.ID == accountId);
                    transfers   = conn.BALANCE_CHANGE.Where(bc =>
                                                            bc.AccountID == accountId).ToList().Select(LinqToEntity.DecorateBalanceChange).ToList();
                    if (transfers.Count == 0)
                    {
                        // добавить начальное пополнение счета
                        var firstBc = new BALANCE_CHANGE
                        {
                            AccountID   = accountId,
                            ValueDate   = accountData.TimeCreated,
                            ChangeType  = (int)BalanceChangeType.Deposit,
                            Description = "initial depo",
                            Amount      = startDepo
                        };
                        conn.BALANCE_CHANGE.Add(firstBc);
                        conn.SaveChanges();

                        var pa = conn.PLATFORM_USER_ACCOUNT.First(p => p.Account == accountId);

                        var trans = new TRANSFER
                        {
                            Amount        = firstBc.Amount,
                            ValueDate     = firstBc.ValueDate,
                            BalanceChange = firstBc.ID,
                            Comment       = "initial depo",
                            TargetAmount  = firstBc.Amount,
                            User          = pa.PlatformUser
                        };
                        conn.TRANSFER.Add(trans);
                        conn.SaveChanges();
                        transfers.Add(LinqToEntity.DecorateBalanceChange(firstBc));
                    }
                }
                return(accountData);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("Error in GetAccountData({0}): {1}", accountId, ex);
                throw;
            }
        }