Esempio n. 1
0
        public ListDetailedCatForListVm GetDetailedCategoriesForList(int mainCategoryId)
        {
            var detailedCategories = _detailedCRepo.GetDetailedCategoriesOfMainCategory(mainCategoryId).ProjectTo <DetailedCatForListVm>
                                         (_mapper.ConfigurationProvider).ToList();
            string mainCategoryName = _mainCRepo.GetMainCategoryNameById(mainCategoryId);

            var detailedCatList = new ListDetailedCatForListVm()
            {
                DetailedCategories = detailedCategories,
                MainCategoryId     = mainCategoryId,
                MainCategoryName   = mainCategoryName,
                Count = detailedCategories.Count
            };

            return(detailedCatList);
        }
        public PlannedExpensesOfAllDetailedCatVm GetPlannedExpensesOfMainCPerMonth(DateTime monthOfYear, int mainCategoryId)
        {
            string   mainCategoryName = _mainCRepo.GetMainCategoryNameById(mainCategoryId);
            DateTime date             = FirstDayOfMonthFromDateTime(monthOfYear);
            var      model            = new PlannedExpensesOfAllDetailedCatVm()
            {
                MonthOfYear      = date,
                MainCategoryId   = mainCategoryId,
                MainCategoryName = mainCategoryName
            };

            int countDetCategories = _mainCRepo.GetCountOfDetailedCategories(mainCategoryId);

            if (countDetCategories != 0)
            {
                bool isPlanned = CheckIfMonthWasPlanned(date);
                if (isPlanned)
                {
                    CreatePlannedExpensesForNewDetailedCategories(mainCategoryId, date);
                    var plannedExpenses = GetPlannedExpensesFromDetailedCategories(mainCategoryId, date);
                    model.PlannedExpOfDetailedCat = plannedExpenses;
                    model.Count = plannedExpenses.Count;
                }
                else
                {
                    //there are detailed categories, but not planned for the month.
                    model.Count = -1;
                }
            }
            return(model);
        }