private void LoadIncomes()
        {
            int minYear = Incomes.Select(income => income.Date.Year).Min();
            int maxYear = Incomes.Select(income => income.Date.Year).Max();

            for (int i = minYear; i <= maxYear; i++)
            {
                decimal yearIncome = 0;
                monthIncomes[i] = new List <IncomeModel>();
                for (int j = 1; j <= 12; j++)
                {
                    var month = Incomes
                                .Where(income => income.Date.Year == i && income.Date.Month == j)
                                .Select(income => income.Money)
                                .Sum();

                    monthIncomes[i].Add(new IncomeModel
                    {
                        Date   = j,
                        Income = month
                    });

                    yearIncome += month;
                }

                yearIncomes.Add(new IncomeModel
                {
                    Date   = i,
                    Income = yearIncome
                });
            }
        }
Beispiel #2
0
        public void RegisterExpense(decimal value, string description)
        {
            var expensesTotal  = Expenses.Select(a => a.Value).Sum() + value;
            var currentBalance = Incomes.Select(a => a.Value).Sum() - expensesTotal;

            RaiseEvent(new ExpenseRegistered(Id, value, description, currentBalance));
        }
        public void RegisterIncome(decimal value, string description)
        {
            var incomesTotal   = Incomes.Select(a => a.Value).Sum() + value;
            var currentBalance = incomesTotal - Expenses.Select(a => a.Value).Sum();

            RaiseEvent(new IncomeRegistered(value, description, currentBalance));
        }
Beispiel #4
0
        public EntityIdSet CreateDefaultEntities()
        {
            SalaryIncome = CreateIncomeType("Зарплата");
            GiftsIncome  = CreateIncomeType("Подарки");

            FoodCategory = CreateCategory("Продукты");
            TechCategory = CreateCategory("Техника");

            Bread = CreateProduct(FoodCategory.Id, "Хлеб");
            Meat  = CreateProduct(FoodCategory.Id, "Мясо");
            Tv    = CreateProduct(TechCategory.Id, "Телевизор");

            FoodExpenseFlow = CreateExpenseFlow("Продукты питания", 1000, DateTime.Today, 1);
            TechExpenseFlow = CreateExpenseFlow("Техника", 30000, DateTime.Today, 2);

            DebitCardAccount  = CreateAccount("Дебетовая карта", 15000, DateTime.Today, AccountType.DebitCard, true);
            CashAccount       = CreateAccount("Наличные", 30000, DateTime.Today, AccountType.Cash);
            CreditCardAccount = CreateAccount("Кредитка", 10000, DateTime.Today, AccountType.CreditCard);

            Incomes = new[]
            {
                CreateIncome(SalaryIncome.Id, new DateTime(2018, 01, 31), 100000, DebitCardAccount.Id),
                CreateIncome(GiftsIncome.Id, new DateTime(2018, 03, 08), 8000, CashAccount.Id)
            }
            .OrderBy(x => x.DateTime).ToList();

            _unitOfWork.SaveChanges();

            return(new EntityIdSet
            {
                SalaryIncomeId = SalaryIncome.Id,
                GiftsIncomeId = GiftsIncome.Id,
                FoodCategoryId = FoodCategory.Id,
                TechCategoryId = TechCategory.Id,
                BreadId = Bread.Id,
                MeatId = Meat.Id,
                TvId = Tv.Id,
                FoodExpenseFlowId = FoodExpenseFlow.Id,
                TechExpenseFlowId = TechExpenseFlow.Id,
                DebitCardAccountId = DebitCardAccount.Id,
                CashAccountId = CashAccount.Id,
                CreditCardAccountId = CreditCardAccount.Id,
                IncomeIds = Incomes.Select(x => x.Id).ToList(),
            });
        }