コード例 #1
0
ファイル: MainCService.cs プロジェクト: oldzik/ExpenseTracker
        public ListMainCatForListVm GetMainCategoriesForList(string userId)
        {
            var mainCategories = _mainCRepo.GetAllMainCategoriesOfUser(userId).ProjectTo <MainCatForListVm>
                                     (_mapper.ConfigurationProvider).ToList();

            var mainCategoryList = new ListMainCatForListVm()
            {
                MainCategories = mainCategories,
                Count          = mainCategories.Count
            };

            return(mainCategoryList);
        }
コード例 #2
0
        public void CreateDetailedCategoriesForNewUser(string userId)
        {
            var mainCategories = _mainCRepo.GetAllMainCategoriesOfUser(userId).ToList();

            var d1 = new DetailedCategory()
            {
                Name = "Żywność", MainCategoryId = mainCategories[0].Id
            };
            var d2 = new DetailedCategory()
            {
                Name = "Chemia domowa", MainCategoryId = mainCategories[0].Id
            };
            var d3 = new DetailedCategory()
            {
                Name = "Rachunki", MainCategoryId = mainCategories[1].Id
            };
            var d4 = new DetailedCategory()
            {
                Name = "Kredyty", MainCategoryId = mainCategories[1].Id
            };
            var d5 = new DetailedCategory()
            {
                Name = "Transport i komunikacja", MainCategoryId = mainCategories[1].Id
            };
            var d6 = new DetailedCategory()
            {
                Name = "Hobby i rozrywka", MainCategoryId = mainCategories[2].Id
            };
            var d7 = new DetailedCategory()
            {
                Name = "Wystrój mieszkania", MainCategoryId = mainCategories[2].Id
            };
            var d8 = new DetailedCategory()
            {
                Name = "Wyjazdy", MainCategoryId = mainCategories[2].Id
            };

            List <DetailedCategory> detailedCategories = new List <DetailedCategory>()
            {
                d1, d2, d3, d4, d5, d6, d7, d8
            };

            _detailedCRepo.AddDetailedCategories(detailedCategories);
        }
コード例 #3
0
        public PlannedExpensesOfAllMainCatVm GetPlannedExpensesOfAllMainCPerMonth(DateTime date, string userId)
        {
            DateTime monthOfYear = FirstDayOfMonthFromDateTime(date);

            decimal sumOfPlanned = 0;
            PlannedExpensesOfAllMainCatVm model = new PlannedExpensesOfAllMainCatVm();

            model.PlannedExpOfMainCat = new List <PlannedExpensesOfMainCatVm>();
            var mainCategories = _mainCRepo.GetAllMainCategoriesOfUser(userId).ToList();

            if (mainCategories != null)
            {
                foreach (var mainCat in mainCategories)
                {
                    var plannedExpMainCatVm = _mapper.Map <PlannedExpensesOfMainCatVm>(mainCat);
                    var listPlannedDetailed = GetPlannedExpensesFromDetailedCategories(mainCat.Id, monthOfYear);
                    //listPlannedDetailed == null, if Main Category dont have any Detailed Categories.
                    if (listPlannedDetailed == null)
                    {
                        plannedExpMainCatVm.PlannedAmount = 0;
                        plannedExpMainCatVm.SpentAmount   = 0;
                    }
                    else
                    {
                        foreach (var plannedDetailed in listPlannedDetailed)
                        {
                            plannedExpMainCatVm.PlannedAmount += plannedDetailed.PlannedAmount;
                            plannedExpMainCatVm.SpentAmount   += plannedDetailed.SpentAmount;
                        }
                        sumOfPlanned += plannedExpMainCatVm.PlannedAmount;
                    }
                    model.PlannedExpOfMainCat.Add(plannedExpMainCatVm);
                }
            }
            model.MonthOfYear  = monthOfYear;
            model.SumOfPlanned = sumOfPlanned;
            model.Count        = model.PlannedExpOfMainCat.Count;
            return(model);
        }