public FluConsentTemplateListModel GetFluConsentTemplateList(FluConsentTemplateModelFilter filter, int pageNumber, int pageSize, out int totalRecords) { var templates = _fluConsentTemplateRepository.GetTemplates(filter, pageNumber, pageSize, out totalRecords); var healthPlans = _corporateAccountRepository.GetByFluConsentTemplateIds(templates.Select(x => x.Id)); var list = new List <FluConsentTemplateViewModel>(); foreach (var template in templates) { var healthPlanName = "N/A"; var fluConsentHealthPlans = healthPlans.Where(x => x.FluConsentTemplateId == template.Id); if (!fluConsentHealthPlans.IsNullOrEmpty()) { healthPlanName = string.Join(", ", fluConsentHealthPlans.Select(x => x.Name)); } list.Add(new FluConsentTemplateViewModel { Id = template.Id, Name = template.Name, HealthPlan = healthPlanName, IsActive = template.IsActive, IsPublished = template.IsPublished }); } return(new FluConsentTemplateListModel { Collection = list, Filter = filter }); }