public StatModel SetLists(DateTime start, DateTime end, StatModel stat, int factoryId) { while (end.Date != start.Date) { if (ShiftManager.CheckShiftsOnDay(start, factoryId)) { var row = new ExelRow() { Date = start.ToShortDateString(), TotalDayWeight = ShiftManager.GetShiftTotalWeightByDay(start, factoryId), TotalProduction = ShiftManager.GetShiftProductionByDay(start, factoryId), IncidentCount = IncidentManager.GetByDay(start, factoryId).Count }; stat.ExelTable.Add(row); foreach (var e in IncidentManager.GetByDay(start, factoryId)) { var i = stat.IncidentTable.FirstOrDefault(I => I.Cause == e.Cause.Name); if (i != null) { i.IncidentCount++; } else { stat.IncidentTable.Add(new IncidentRow() { Cause = e.Cause.Name, IncidentCount = 1 }); } } } start = start.AddDays(1); } return(stat); }