public IActionResult Index(int year = 2020, bool withAbsence = true) { var resources = _context.Set <Resource>() .Include(res => res.Employee) .Include(x => x.ResourceGroupType) .ToList(); var resourceCapacities = _context.Set <ResourceCapacity>() .Include(x => x.Resource) .Include(x => x.Period) .Where(x => x.Period.Start.Year == year) .ToList(); var absence = _context.Set <AbstractCalendarEntry>().ToList(); if (withAbsence) { var capacityWithAbsenceService = new CapacityWithAbsenceService(resourceCapacities); resourceCapacities = capacityWithAbsenceService.GetCapacityWithAbsence(absence); } var builder = new CapacityViewModelBuilder(resources, resourceCapacities, year, withAbsence); var model = builder.Build(); ViewBag.CurrentYear = DateTime.Now.Year; ViewBag.Year = year; ViewBag.Months = MonthGeneratorService.GetAllMonths(year); return(View(model)); }
// GET public IActionResult Index(int year = 2020) { ViewBag.Year = year; var absences = _context.Set <AbstractCalendarEntry>() .Include(abs => abs.CalendarEmployee) .ThenInclude(e => e.Employee) .ToList(); var resourcesCapacity = _context.Set <ResourceCapacity>() .Include(res => res.Resource) .ThenInclude(res => res.Employee) .ToList(); var functioningCapacityResources = _context.Set <FunctioningCapacityResource>() .Include(res => res.Resource) .ThenInclude(res => res.Employee).ToList(); var resources = _context.Set <Resource>() .Include(res => res.Employee) .Include(res => res.ResourceGroupType) .ToList(); var periods = _context.Set <Period>().Where(per => per.Start.Year == year).OrderBy(per => per.Start).ToList(); var builder = new AbsencesViewModelBuilder(year, absences, resourcesCapacity, functioningCapacityResources, resources, periods); var model = builder.Build(); ViewBag.Months = MonthGeneratorService.GetAllMonths(year); return(View(model)); }
private AbsencesViewModel MakeAbsencesViewModel(string group) { return(new AbsencesViewModel { Months = MonthGeneratorService.GetAllMonths(_year), ResourceAbsences = GetResourceAbsencesDictionary(group) }); }