public CategoryExpensesViewModel(CategoryExpensesSummary summary, List <Categories> availableCategories, Categories selectedCategory, DateRangeViewModel dateRangeVM) : this(availableCategories, dateRangeVM) { categoryId = selectedCategory.Id; categoryName = selectedCategory.Name; if (summary.GroupedExpenses.Count() == 0) { ChartHeader = $"Nie znaleziono ani jednego wydatku w kategorii {categoryName}"; return; } ChartHeader = $"{categoryName} ({summary.GroupedExpenses.Sum(x => x.TotalPricesSum)}zł)"; BarChartViewModel = new BarChartViewModel() { Type = "horizontalBar", Labels = summary.GroupedExpenses.Select(x => x.Name ?? string.Empty).ToList(), Values = summary.GroupedExpenses.Select(x => x.TotalPricesSum).ToList(), Height = summary.GroupedExpenses.Count() * 20 + 30, LegendSquaresHexColors = new List <string>() { categoryHexBgColor, subCategoriesHexBgColor }, LegendDescriptions = new List <string>() { $"Wydatek należący do kategorii {categoryName}", $"Wydatek należący do jednej z podkategorii kategorii {categoryName}" }, }; foreach (var item in summary.GroupedExpenses) { AddChartBgColor(item); AddChartTootlip(item); } }
public (CategoryExpensesSummary summary, List <Categories> availableCategories, Categories selectedCategory) CategoryExpenses(int categoryId) { Categories selectedCategory = context.Categories.First(x => x.Id == categoryId); List <Categories> availableCategories = GetAvailableCategories(); CategoryTree categoryTree = new CategoryTree(categoryId, availableCategories); List <int> idOfCatWithSubcats = categoryTree.Root.ToList().Select(x => x.Id).ToList(); List <Expenses> expenses = context.Expenses.Where(x => x.UserId == userId && idOfCatWithSubcats.Contains(x.CategoryId) && x.Date >= dateFrom && x.Date <= dateTo).ToList(); List <Units> allUnits = context.Units.ToList(); CategoryExpensesSummary summary = new CategoryExpensesSummary(categoryId, expenses, allUnits); return(summary, availableCategories, selectedCategory); }