void LoadTime(string RoomCode) { int i = 1; dgTime.Rows.Clear(); using (Maintenance _maintain = new Maintenance()) { var valueGetTime = _maintain.GetTime(); valueGetTime.ForEach(x => { var valueRoomAndTime = _maintain.GetRoomTime().Where(xx => xx.RoomCode == RoomCode && xx.TimeCode == x.TimeCode).FirstOrDefault(); dgTime.Rows.Add(valueRoomAndTime != null ? valueRoomAndTime.ID : x.ID, i, x.TimeStart.Value.ToString("HH:mm:ss tt") + " to " + x.TimeEnd.Value.ToString("HH:mm:ss tt"), valueRoomAndTime != null ? valueRoomAndTime.Status : false, valueRoomAndTime != null ? valueRoomAndTime.TimeCode : x.TimeCode); i++; }); } }