public List <FormDateReportModel> GenerateDateReport(List <FormDateReportDBModel> obj) { int counter = 0; int chamber = 0; bool isLastChamber = false; var list = new List <FormDateReportModel>(); var shiftCalendarManager = new ShiftCalendarManager(); var itemsList = new List <FormDateReportDBModel>(); foreach (var item in obj) { if ((item == obj.First()) || (item.Silos == itemsList.Last().Silos&& item.Chamber == itemsList.Last().Chamber&& item != obj.Last())) { itemsList.Add(item); } else { var shift = shiftCalendarManager.GetShiftAsString(shiftCalendarManager.GetShift( new TimeSpan(itemsList.First().ProductionDate.Hour, itemsList.First().ProductionDate.Minute, itemsList.First().ProductionDate.Second), new TimeSpan(itemsList.Last().ProductionDate.Hour, itemsList.Last().ProductionDate.Minute, itemsList.Last().ProductionDate.Second))); list.Add(new FormDateReportModel() { Shift = shift, TimeFrom = itemsList.First().ProductionDate, TimeTo = itemsList.Last().ProductionDate, Chamber = itemsList.Last().Chamber, Silos = itemsList.Last().Silos, NumberOfBlocks = itemsList.Count, Operator = itemsList.Last().Operator, DetailedReportForChamber = (from it in itemsList select it).ToList() }); itemsList.Clear(); itemsList.Add(item); } } return(list.IsEmpty() ? null : shiftCalendarManager.RemoveNastedRows(list, list.First().TimeFrom)); }