public IList <DTOSolucEducFormaAquisicao> ConsultarSolucaoEducacional(int pUsuario, int pFornecedor, int pFormaAquisicao) { solucaoEducacionalBM = new BMSolucaoEducacional(); IList <SolucaoEducacional> lstSolEduc = solucaoEducacionalBM.ConsultarSolucaoEducacionalWebServices(pUsuario, pFornecedor, pFormaAquisicao); IList <FormaAquisicao> lstFormaAquisicao = (from fa in lstSolEduc select fa.FormaAquisicao).ToList(); IList <DTOSolucEducFormaAquisicao> lstResult = new List <DTOSolucEducFormaAquisicao>(); foreach (FormaAquisicao fa in lstFormaAquisicao) { DTOSolucEducFormaAquisicao dtofa = new DTOSolucEducFormaAquisicao() { Nome = fa.Nome, CodigoFormaAquisicao = fa.ID, ListaSolucaoEducacional = new List <DTOSolucEducSolucaoEducacional>() }; IList <SolucaoEducacional> lstSolEducFA = (from se in lstSolEduc where se.FormaAquisicao.ID == fa.ID select se).ToList(); foreach (SolucaoEducacional se in lstSolEducFA) { MatriculaOferta mo = (from of in (new BMOferta()).ObterPorFiltro(new Oferta() { SolucaoEducacional = se }) select of.ListaMatriculaOferta).FirstOrDefault().Where(x => x.StatusMatricula != enumStatusMatricula.CanceladoAdm && x.StatusMatricula != enumStatusMatricula.CanceladoAluno) .OrderByDescending(x => x.DataSolicitacao).FirstOrDefault(); DTOSolucEducSolucaoEducacional dtoSE = new DTOSolucEducSolucaoEducacional() { CodigoSolucaoEducacional = se.ID, Nome = se.Nome, SolucaoEducacionalMatricula = mo == null ? null : (new DTOSolucEducSolucaoEducacionalMatricula() { DataSolicitacao = mo.DataSolicitacao, StatusMatricula = mo.StatusMatricula.ToString() }) }; dtofa.ListaSolucaoEducacional.Add(dtoSE); } lstResult.Add(dtofa); } return(lstResult); }