Пример #1
0
        public TransactionCategoriesMeshed GetTransactionCategories()
        {
            var whatToReturn = new TransactionCategoriesMeshed
            {
                IncomeCategories   = _DboContext.TransactionCategories.Where(x => x.CategoryType == 0).ToList(),
                ExpensesCategories = _DboContext.TransactionCategories.Where(x => x.CategoryType == 1).ToList()
            };

            return(whatToReturn);
        }
Пример #2
0
        public void AddNewTransaction(TransactionType transactType, string transactionName, string transactionAmount, DateTime date, int userID, string category = "N/A")
        {
            if (transactionName != "" && transactionAmount != "")
            {
                // Checks whether transaction amount is a number
                float transAmount;

                if (!float.TryParse(transactionAmount, out transAmount))
                {
                    return;
                }

                if (transAmount < 0)
                {
                    throw new ArgumentException("Provided amount can't be negative");
                }

                // Check if category exists

                TransactionCategoriesMeshed categories = _CategoryService.GetTransactionCategories();
                if (!categories.IncomeCategories.Exists(x => x.Name == category) && !categories.ExpensesCategories.Exists(x => x.Name == category))
                {
                    throw new BadCategoryException("Category not found: ", category);
                }

                //Transaction newTransaction = new Transaction(transactType, transAmount, transactionName, category, DateTime.Now);

                //List.Add(newTransaction);
                //OnTransactionAdded(newTransaction);

                DboTransaction dbotransaction = new DboTransaction
                {
                    TransactType = transactType,
                    Title        = transactionName,
                    Category     = category,
                    Date         = (date == null) ? DateTime.Now : date,
                    Amount       = transAmount,
                    UserId       = userID
                };
                _dboContext.Transactions.Add(dbotransaction);
                _dboContext.SaveChanges();

                //SerializeTransactionList();
            }
        }