コード例 #1
0
        public async Task <GridResult> ObterDadosGrid(GridRequest request = null)
        {
            var result = new GridResult();

            if (request == null)
            {
                result.Total = await _projetoRepository.CountAsync();

                result.Data = (await _projetoRepository.GetAllAsync())
                              .Select(x => new { x.Id, x.Tema, x.Descricao, x.Periodo, NomeProfessor = x.Professor.Usuario.Nome });
                return(result);
            }

            var data = string.IsNullOrWhiteSpace(request.Search) ?
                       await _projetoRepository.GetAllAsync() :
                       await _projetoRepository.SearchAsync(x =>
                                                            x.Tema.IndexOf(request.Search, StringComparison.OrdinalIgnoreCase) >= 0 ||
                                                            x.Descricao.IndexOf(request.Search, StringComparison.OrdinalIgnoreCase) >= 0 ||
                                                            x.Periodo.IndexOf(request.Search, StringComparison.OrdinalIgnoreCase) >= 0 ||
                                                            x.Professor.Usuario.Nome.IndexOf(request.Search, StringComparison.OrdinalIgnoreCase) >= 0);

            result.Total = data.Count();

            if (!string.IsNullOrWhiteSpace(request.OrderBy))
            {
                if (request.Direction == Direction.Descendent)
                {
                    data =
                        request.OrderBy == "tema" ? data.OrderByDescending(x => x.Tema) :
                        request.OrderBy == "descricao" ? data.OrderByDescending(x => x.Descricao) :
                        request.OrderBy == "periodo" ? data.OrderByDescending(x => x.Periodo) :
                        request.OrderBy == "nomeProfessor" ? data.OrderByDescending(x => x.Professor.Usuario.Nome) : data;
                }
                else
                {
                    data =
                        request.OrderBy == "tema" ? data.OrderBy(x => x.Tema) :
                        request.OrderBy == "descricao" ? data.OrderBy(x => x.Descricao) :
                        request.OrderBy == "periodo" ? data.OrderBy(x => x.Periodo) :
                        request.OrderBy == "nomeProfessor" ? data.OrderBy(x => x.Professor.Usuario.Nome) : data;
                }
            }

            if (request.PageSize > 0 && request.Page > 0)
            {
                data = data.Skip((request.Page - 1) * request.PageSize).Take(request.Page * request.PageSize);
            }

            result.Data = data.Select(x => new { x.Id, x.Tema, x.Descricao, x.Periodo, NomeProfessor = x.Professor.Usuario.Nome });

            return(result);
        }
コード例 #2
0
        public async Task <GridResult> ObterDadosAvaliacoes(Guid id, GridRequest request = null)
        {
            var data = new List <ResultadoAvaliacaoCriterio>();

            var aluno = await _alunoRepository.GetByIdAsync(id);

            var projetos = await _projetoRepository.GetAllAsync();

            var projetoAtual = (await _projetoRepository.SearchAsync(x =>
                                                                     x.Estado == Projeto.EnumEstado.Avaliacao &&
                                                                     x.Grupos.Any(g => g.AssociacaoAlunoGrupo.Any(a => a.AlunoId == id))
                                                                     )).SingleOrDefault();

            if (projetoAtual == null)
            {
                return(new GridResult());
            }

            var grupo = await _grupoRepository.ObterGrupo(id, projetoAtual.Id);

            if (grupo == null)
            {
                return(new GridResult());
            }

            var avaliacoesAluno = await _avaliacaoRepository.ObterAvaliacoesPorAluno(id, grupo.Id);

            var idsAvaliadores = avaliacoesAluno.Select(x => x.AvaliadorId).Distinct().ToList();

            foreach (var avaliacaoCriterio in avaliacoesAluno.GroupBy(x => x.Criterio))
            {
                var resultado = new ResultadoAvaliacaoCriterio
                {
                    Criterio = avaliacaoCriterio.Key,
                };

                foreach (var avaliadorId in idsAvaliadores)
                {
                    var avaliacoesAvaliador = avaliacaoCriterio.Where(x => x.AvaliadorId == avaliadorId);
                    var nota = avaliacoesAvaliador.Sum(x => x.Nota * x.Peso) / (avaliacoesAvaliador.Sum(x => x.Peso) * 1.0);
                    resultado.Notas.Add(double.IsNaN(nota) ? (double?)null : Math.Round(nota, 2));
                }

                var media = resultado.Notas.Average();
                resultado.MediaFinal = media == null ? (double?)null : Math.Round(media.Value, 2);

                data.Add(resultado);
            }

            var result = new GridResult();

            if (request == null)
            {
                result.Total = data.Count();
                result.Data  = data;
                return(result);
            }

            data = string.IsNullOrWhiteSpace(request.Search) ?
                   data :
                   data.Where(x =>
                              x.Criterio.IndexOf(request.Search, StringComparison.OrdinalIgnoreCase) >= 0).ToList();

            result.Total = data.Count();

            if (!string.IsNullOrWhiteSpace(request.OrderBy))
            {
                if (request.Direction == Direction.Descendent)
                {
                    data =
                        request.OrderBy == "mediaFinal" ? data.OrderByDescending(x => x.MediaFinal).ToList() :
                        request.OrderBy == "aluno" ? data.OrderByDescending(x => x.Criterio).ToList() : data;
                }
                else
                {
                    data =
                        request.OrderBy == "mediaFinal" ? data.OrderBy(x => x.MediaFinal).ToList() :
                        request.OrderBy == "aluno" ? data.OrderBy(x => x.Criterio).ToList() : data;
                }
            }

            if (request.PageSize > 0 && request.Page > 0)
            {
                data = data.Skip((request.Page - 1) * request.PageSize).Take(request.Page * request.PageSize).ToList();
            }

            if (data.Count > 0)
            {
                var total = new ResultadoAvaliacaoCriterio {
                    Criterio = "Média Total"
                };

                for (int i = 0; i < idsAvaliadores.Count; i++)
                {
                    total.Notas.Add(data.Select(x => x.Notas[i]).Average());
                }

                total.MediaFinal = Math.Round(total.Notas.Average().Value, 2);

                data.Add(total);
            }

            result.Data = data;

            return(result);
        }