Пример #1
0
        public void Create(Budget budget)
        {
            if (budget == null)
            {
                throw new ArgumentNullException(nameof(budget));
            }

            if (budget.InitialTransaction == null)
            {
                throw new ArgumentException("InitialTransaction cannot be null", nameof(budget));
            }

            if (budget.SurplusTransaction == null)
            {
                throw new ArgumentException("SurplusTransaction cannot be null", nameof(budget));
            }

            using (var transaction = m_dbContext.Database.BeginTransaction())
            {
                var budgetEntity = new Entities.Budget
                {
                    Name   = budget.Name,
                    Period = budget.Period
                };
                m_dbContext.Budgets.Add(budgetEntity);
                m_dbContext.SaveChanges();

                Entities.BudgetTransaction initialTransactionEntity = ToEntity(budgetEntity, budget.InitialTransaction);
                initialTransactionEntity.IsInitial = true;
                m_dbContext.BudgetTransactions.Add(initialTransactionEntity);

                List <Entities.BudgetTransaction> transactionEntities =
                    budget.Transactions
                    .Select(t => ToEntity(budgetEntity, t))
                    .ToList();
                m_dbContext.BudgetTransactions.AddRange(transactionEntities);

                Entities.BudgetTransaction surplusTransactionEntity = ToEntity(budgetEntity, budget.SurplusTransaction);
                surplusTransactionEntity.IsSurplus = true;
                m_dbContext.BudgetTransactions.Add(surplusTransactionEntity);

                m_dbContext.SaveChanges();

                transaction.Commit();

                // Update IDs
                budget.BudgetId = budgetEntity.BudgetId;
                budget.InitialTransaction.BudgetTransactionId = initialTransactionEntity.BudgetTransactionId;
                for (int transactionIndex = 0; transactionIndex < budget.Transactions.Count(); ++transactionIndex)
                {
                    budget.Transactions.ElementAt(transactionIndex).BudgetTransactionId =
                        transactionEntities[transactionIndex].BudgetTransactionId;
                }
                budget.SurplusTransaction.BudgetTransactionId = surplusTransactionEntity.BudgetTransactionId;
            }
        }
Пример #2
0
        public void Create(Transaction transaction)
        {
            var transactionEntity = new Entities.Transaction
            {
                CreditAccountId = transaction.CreditAccount.AccountId,
                DebitAccountId  = transaction.DebitAccount.AccountId,
                Amount          = transaction.Amount,
                At = transaction.At
            };

            m_dbContext.Transactions.Add(transactionEntity);
            m_dbContext.SaveChanges();

            transaction.TransactionId = transactionEntity.TransactionId;
        }
Пример #3
0
        public void Create(Account account)
        {
            var accountEntity = new Entities.Account
            {
                Name       = account.Name,
                Type       = account.Type,
                SubType    = account.SubType,
                CurrencyId = account.Currency.CurrencyId
            };

            m_dbContext.Accounts.Add(accountEntity);
            m_dbContext.SaveChanges();

            account.AccountId = accountEntity.AccountId;
        }
Пример #4
0
 public void Add(Entities.FinancierDbContext dbContext, Entities.Account accountEntity)
 {
     dbContext.Accounts.Add(accountEntity);
     dbContext.SaveChanges();
 }