/// <summary> /// Build object to string result /// </summary> /// <param name="lstRosters"></param> /// <param name="date"></param> /// <returns></returns> private static object BuildListSection(TList<Roster> lstRosters, DateTime? date) { object lst = null; try { DataRepository.RosterProvider.DeepLoad(lstRosters); // Lay danh sach doctor theo appointment var lstDoctor = new TList<Users>(); // Lay danh sach service theo appointment var lstService = new TList<Services>(); foreach (var roster in lstRosters) { Roster roster1 = roster; if (!lstDoctor.Exists(doctor => doctor.Username == roster1.Username)) { lstDoctor.Add(roster.UsernameSource); } lstDoctor.Sort((p1, p2) => p1.DisplayName.CompareTo(p2.DisplayName)); DataRepository.UsersProvider.DeepLoad(roster1.UsernameSource); if (!lstService.Exists(service => service.Id == roster1.UsernameSource.ServicesId)) { lstService.Add(DataRepository.ServicesProvider.GetById(Convert.ToInt32(roster1.UsernameSource.ServicesId))); } } // Sort theo priority lstService.Sort("PriorityIndex ASC"); var dtStart = Convert.ToDateTime(date); var dtEnd = new DateTime(dtStart.Year, dtStart.Month, dtStart.Day, 23, 59, 59); dtStart = new DateTime(dtStart.Year, dtStart.Month, dtStart.Day); lst = lstService.Select(service => new { service.Id, Title = string.IsNullOrEmpty(service.ShortTitle) ? service.Title : service.ShortTitle, Date = String.Format("{0:MM-dd-yyyy HH:mm:ss}", date), Doctors = lstDoctor.Where(doctor => doctor.ServicesId == service.Id) .Select(doctor => new { key = doctor.Username, label = doctor.DisplayName, Rosters = lstRosters.Where(roster => roster.Username == doctor.Username) .Select(roster => new { startTime = (roster.StartTime < dtStart ? dtStart : roster.StartTime).ToString("MM-dd-yyyy HH:mm:ss"), endTime = (roster.EndTime > dtEnd ? dtEnd : roster.EndTime).ToString("MM-dd-yyyy HH:mm:ss"), color = roster.RosterTypeIdSource.ColorCode }).ToList() }).ToList() }).ToList(); } catch (Exception ex) { LoggerController.WriteLog(System.Runtime.InteropServices.Marshal.GetExceptionCode(), ex, Network.GetIpClient()); } return lst; }