public static bool SaveAccountFinancialTarget(int accountId, decimal depositPerYear, DateTime targetEndDate, decimal targetValue)
        {
            int baseCurrencyId;
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                baseCurrencyId = SecurityLayerAdapter.GetBaseCurrency(session).Key;
            }

            AccountFinancialTargetHelper helper = new AccountFinancialTargetHelper();
            helper.ParentAccountID = accountId;
            helper.CurrencyID = baseCurrencyId;
            helper.TargetAmountSize = targetValue;
            helper.DepositPerYearSize = depositPerYear;
            helper.TargetEndDate = targetEndDate;

            return AccountEditAdapter.AddAccountFinanicalTarget(helper);
        }
Exemple #2
0
        public static bool AddAccountFinanicalTarget(AccountFinancialTargetHelper accountFinancialTarget)
        {
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                if (accountFinancialTarget.ParentAccountID != 0)
                {
                    ICustomerAccount account = (ICustomerAccount)AccountMapper.GetAccount(session, accountFinancialTarget.ParentAccountID);

                    ICurrency currency = InstrumentMapper.GetCurrency(session, accountFinancialTarget.CurrencyID);
                    ILogin createdBy = LoginMapper.GetCurrentLogin(session);

                    if (account.CurrentFinancialTarget != null &&
                        account.CurrentFinancialTarget.TargetAmount.Quantity == accountFinancialTarget.TargetAmountSize &&
                        account.CurrentFinancialTarget.TargetAmount.Underlying.Key == currency.Key &&
                        account.CurrentFinancialTarget.DepositPerYear.Quantity == accountFinancialTarget.DepositPerYearSize &&
                        account.CurrentFinancialTarget.DepositPerYear.Underlying.Key == currency.Key &&
                        account.CurrentFinancialTarget.TargetEndDate == accountFinancialTarget.TargetEndDate)
                        return false;

                    AccountFinancialTarget newTarget = new AccountFinancialTarget();
                    newTarget.ParentAccount = account;
                    newTarget.TargetAmount = new Money(accountFinancialTarget.TargetAmountSize, currency);
                    newTarget.DepositPerYear = new Money(accountFinancialTarget.DepositPerYearSize, currency);
                    newTarget.TargetEndDate = accountFinancialTarget.TargetEndDate;
                    newTarget.CreatedBy = createdBy;
                    newTarget.CreationDate = DateTime.Now;

                    account.CurrentFinancialTarget = newTarget;
                    session.Update(account);
                }
                else
                    throw new ApplicationException("Could not identify Account");

                return true;
            }
        }