public string Guide_AgencyGetAllByRole(string d, string ri, string w) { DateTime?date = null; try { date = DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture); } catch { } var routeId = -1; try { routeId = Int32.Parse(ri); } catch { } var way = w; var route = TransferRequestByDateBLL.RouteGetById(routeId); var role = TransferRequestByDateBLL.RoleGetByName("Guides"); var listGuide = TransferRequestByDateBLL.AgencyGetAllByRole(role).Future().ToList(); var listGuideInDay = TransferRequestByDateBLL.Guide_AgencyGetAllGuideInDay(role, date, route).Future().ToList(); var listGuideDTO = new List <AgencyDTO>(); listGuide.ForEach(guide => { var guideInDay = listGuideInDay.Where(x => x.Id == guide.Id).FirstOrDefault(); Expense guideExpenseInDay = null; if (guideInDay != null) { guideExpenseInDay = TransferRequestByDateBLL.ExpenseGetAllByCriterion(guide, date, route) .Future().SingleOrDefault(); } var guideDTO = new AgencyDTO() { Id = guide.Id, Name = guideExpenseInDay != null ? guideExpenseInDay.Guide.Name + " - " + guideExpenseInDay.Cruise.Code : guide.Name, Group = guideInDay != null ? "Guide in day" : null, }; listGuideDTO.Add(guideDTO); }); if (way == "Back") { var listGuideDayBefore = TransferRequestByDateBLL.Guide_AgencyGetAllGuideInDay(role, date.Value.AddDays(-1), route).Future().ToList(); listGuideDayBefore.ForEach(guideDayBefore => { var guideDTO = new AgencyDTO() { Id = guideDayBefore.Id, Name = guideDayBefore.Name, Group = guideDayBefore != null ? "Guide day before" : null, }; listGuideDTO.Add(guideDTO); }); } Dispose(); return(JsonConvert.SerializeObject(listGuideDTO)); }