Beispiel #1
0
        public List <MatriculaOferta> ObterMatriculaOfertaPorOferta(int ofertaId, int limit = 30, int page = 0, Usuario usuarioLogado = null)
        {
            try
            {
                if (ofertaId <= 0)
                {
                    throw new Exception("Oferta. Campo Obrigatório ");
                }

                var query = _bmMatriculaOferta.ObterTodosIQueryable()
                            .Select(x => new MatriculaOferta
                {
                    ID = x.ID,
                    FornecedorNotificado = x.FornecedorNotificado,
                    StatusMatricula      = x.StatusMatricula,
                    DataSolicitacao      = x.DataSolicitacao,
                    LinkAcesso           = x.LinkAcesso,
                    Oferta = new Oferta
                    {
                        ID = x.Oferta.ID
                    },
                    Usuario = new Usuario
                    {
                        ID   = x.Usuario.ID,
                        Nome = x.Usuario.Nome
                    },
                    UF = new Uf
                    {
                        ID = x.UF.ID
                    }
                })
                            .Where(x => x.Oferta.ID == ofertaId)
                            .OrderBy(x => x.Usuario.Nome).AsQueryable();

                if (usuarioLogado != null)
                {
                    query = query.Where(x => x.UF.ID == usuarioLogado.UF.ID);
                }

                query = page == 0 ? query.Take(limit) : query.Skip(page * limit).Take(limit);

                var result = query.ToList();

                // Preencher matrículas turmas.
                PreencherMatriculaTurma(result);

                // Preencher dados dos usuários.
                PreencherUsuarios(result);

                // Preencher dados das ofertas.
                PreencherOfertas(result);

                return(result);
            }
            catch (Exception ex)
            {
                throw new AcademicoException(ex.Message);
            }
        }