public bool UpdateAccountBalance(TradeSharpConnection ctx,
                                         ACCOUNT account, decimal amount, BalanceChangeType changeType,
                                         string description, DateTime valueDate, int?positionId)
        {
            var bc = new BALANCE_CHANGE
            {
                AccountID   = account.ID,
                Amount      = amount,
                ChangeType  = (int)changeType,
                Description = description,
                ValueDate   = valueDate,
                Position    = positionId
            };

            try
            {
                ctx.BALANCE_CHANGE.Add(bc);
                account.Balance += ((changeType == BalanceChangeType.Deposit ||
                                     changeType == BalanceChangeType.Profit) ? amount : -amount);
                ctx.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("Ошибка обновления баланса счета {0} на сумму {1}: {2}",
                                   account.ID, amount, ex);
                return(false);
            }
        }
Exemple #2
0
 public static decimal CorrectSign(decimal sum, BalanceChangeType changeType)
 {
     if (changeType == BalanceChangeType.Swap)
     {
         return(sum);
     }
     return(GetSign(changeType) * Math.Abs(sum));
 }
Exemple #3
0
 public static float CorrectSign(float sum, BalanceChangeType changeType)
 {
     if (changeType == BalanceChangeType.Swap)
     {
         return(sum);
     }
     return(GetSign(changeType) * Math.Abs(sum));
 }
        public RequestStatus ChangeBalance(int accountId, decimal summ, string comment, DateTime date, BalanceChangeType changeType)
        {
            if (summ == 0) return RequestStatus.BadRequest;
            // корректировать знак
            summ = BalanceChange.CorrectSign(summ, changeType);

            try
            {
                using (var ctx = DatabaseContext.Instance.Make())
                {
                    ACCOUNT acc;
                    try
                    {
                        acc = (from a in ctx.ACCOUNT
                               where a.ID == accountId
                               select a).First();
                    }
                    catch (Exception ex)
                    {
                        Logger.ErrorFormat("Ошибка получения счета для редактирования {0}: {1}", accountId, ex);
                        return RequestStatus.ServerError;
                    }

                    var bc = new BALANCE_CHANGE
                    {
                        AccountID = accountId,
                        ValueDate = date,
                        Amount = summ,
                        ChangeType = (int)changeType,
                        Description = comment
                    };
                    try
                    {
                        acc.Balance = acc.Balance + summ;
                        ctx.BALANCE_CHANGE.Add(bc);
                        ctx.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Logger.ErrorFormat("Ошибка изменения баланса счета {0}: {1}", accountId, ex);
                        return RequestStatus.ServerError;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Ошибка в ChangeBalance", ex);
                return RequestStatus.ServerError;
            }
            return RequestStatus.OK;
        }
Exemple #5
0
 public static int GetSign(BalanceChangeType changeType)
 {
     return(changeType == BalanceChangeType.Deposit ||
            changeType == BalanceChangeType.Profit || changeType == BalanceChangeType.Swap
                ? 1 : -1);
 }
Exemple #6
0
        public RequestStatus ChangeBalance(int accountId, decimal summ, string comment, DateTime date, BalanceChangeType changeType)
        {
            if (summ == 0)
            {
                return(RequestStatus.BadRequest);
            }
            // корректировать знак
            summ = BalanceChange.CorrectSign(summ, changeType);

            try
            {
                using (var ctx = DatabaseContext.Instance.Make())
                {
                    ACCOUNT acc;
                    try
                    {
                        acc = (from a in ctx.ACCOUNT
                               where a.ID == accountId
                               select a).First();
                    }
                    catch (Exception ex)
                    {
                        Logger.ErrorFormat("Ошибка получения счета для редактирования {0}: {1}", accountId, ex);
                        return(RequestStatus.ServerError);
                    }

                    var bc = new BALANCE_CHANGE
                    {
                        AccountID   = accountId,
                        ValueDate   = date,
                        Amount      = summ,
                        ChangeType  = (int)changeType,
                        Description = comment
                    };
                    try
                    {
                        acc.Balance = acc.Balance + summ;
                        ctx.BALANCE_CHANGE.Add(bc);
                        ctx.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Logger.ErrorFormat("Ошибка изменения баланса счета {0}: {1}", accountId, ex);
                        return(RequestStatus.ServerError);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Ошибка в ChangeBalance", ex);
                return(RequestStatus.ServerError);
            }
            return(RequestStatus.OK);
        }
 public bool UpdateAccountBalance(TradeSharpConnection ctx,
     ACCOUNT account, decimal amount, BalanceChangeType changeType,
     string description, DateTime valueDate, int? positionId)
 {
     var bc = new BALANCE_CHANGE
     {
         AccountID = account.ID,
         Amount = amount,
         ChangeType = (int)changeType,
         Description = description,
         ValueDate = valueDate,
         Position = positionId
     };
     try
     {
         ctx.BALANCE_CHANGE.Add(bc);
         account.Balance += ((changeType == BalanceChangeType.Deposit ||
             changeType == BalanceChangeType.Profit) ? amount : -amount);
         ctx.SaveChanges();
         return true;
     }
     catch (Exception ex)
     {
         Logger.ErrorFormat("Ошибка обновления баланса счета {0} на сумму {1}: {2}",
             account.ID, amount, ex);
         return false;
     }
 }
 public static int GetSign(BalanceChangeType changeType)
 {
     return changeType == BalanceChangeType.Deposit ||
            changeType == BalanceChangeType.Profit || changeType == BalanceChangeType.Swap
                ? 1 : -1;
 }
 public static decimal CorrectSign(decimal sum, BalanceChangeType changeType)
 {
     if (changeType == BalanceChangeType.Swap) return sum;
     return GetSign(changeType) * Math.Abs(sum);
 }
 public static float CorrectSign(float sum, BalanceChangeType changeType)
 {
     if (changeType == BalanceChangeType.Swap) return sum;
     return GetSign(changeType) * Math.Abs(sum);
 }
Exemple #11
0
 public BalanceChangedEventArg(BalanceChangeType changeType, decimal amount)
 {
     ChangeType = changeType;
     Amount     = amount;
 }