public DashboardModel CompanyDashboard(int year, int month) { var firstDay = new DateTime(year, month, 1); var lastDay = new DateTime(year, month, DateTime.DaysInMonth(year, month)); var query = TimeKeeperUnit.Projects .Get(x => x.StartDate <= firstDay && (!x.EndDate.HasValue || x.EndDate.Value >= firstDay)); DashboardModel dm = new DashboardModel(query.Select(x => x.Team).Count(), query.Count); dm.NumberOfEmployees = query .Select(x => x.Team) .SelectMany(x => x.Engagements) .Select(x => x.Employee) .GroupBy(x => x.Engagements.GroupBy(y => y.Team.Projects.GroupBy(z => z.Id))) .Count(); dm.NumberOfProjects = query.Count; dm.TotalHours = query .Select(x => x.Team) .SelectMany(x => x.Engagements) .Select(x => x.Employee) .SelectMany(x => x.Days) .GroupBy(x => x.Employee) .Sum(x => x.Key.Days.Where(y => y.Date >= firstDay && y.Date <= lastDay).Sum(y => y.Hours)); for (int i = 0; i < dm.PTOHours.Count(); i++) { dm.PTOHours[i] = query .Select(x => x.Team) .ElementAt(i) .Engagements .Select(x => x.Employee) .SelectMany(x => x.Days) .GroupBy(x => x.Employee) .Sum(x => x.Key.Days .Where(y => y.Date >= firstDay && y.Date <= lastDay && y.Type != DayType.WorkingDay) .Sum(y => y.Hours)); dm.OvertimeHours[i] = query .Select(x => x.Team) .ElementAt(i) .Engagements .Select(x => x.Employee) .SelectMany(x => x.Days) .GroupBy(x => x.Employee) .Sum(x => x.Key.Days.Where(y => y.Date >= firstDay && y.Date <= lastDay && y.Hours > 8) .Sum(y => y.Hours - 8)); } return(dm); }
public DashboardModel TeamDashboard(string teamId, int year, int month) { var query = TimeKeeperUnit.Teams.Get(teamId); DashboardModel list = new DashboardModel(query.Engagements .Where(x => (x.Employee.BeginDate.Year <= year && x.Employee.BeginDate.Month <= month) && (x.Employee.EndDate.HasValue && x.Employee.EndDate.Value.Year >= year && x.Employee.EndDate.Value.Month >= month)).Count()); list.NumberOfProjects = query.Projects .Where(x => (x.StartDate.Year <= year && x.StartDate.Month <= month) && (x.EndDate.HasValue && x.EndDate.Value.Year >= year && x.EndDate.Value.Month >= month)).Count(); list.TotalHours = query.Projects.SelectMany(x => x.Details.Select(y => y.Hours)).Sum(); for (int i = 0; i < list.NumberOfEmployees; i++) { //list.Utilization[i] = } return(list); }