Esempio n. 1
0
        public int Adicionar(TrofeuDTO trofeuDTO, Usuario usuarioLogado)
        {
            if (trofeuDTO == null || trofeuDTO.Id > 0)
            {
                throw new Exception("Solicitação inválida.");
            }

            CaseDeNegocio caseDeNegocio = _caseDeNegocioService.ObterPorId(trofeuDTO.IdCase);

            if (caseDeNegocio == null)
            {
                throw new Exception("Case de negócio não encontrado.");
            }

            if (!_caseDeNegocioService.UsuarioEstaAssociadoAoCaseDeNegocioComoProfessor(usuarioLogado, caseDeNegocio))
            {
                throw new Exception("Usuário não possui permissão.");
            }

            Trofeu trofeu = new Trofeu();

            trofeu.IdCase        = caseDeNegocio.Id;
            trofeu.CaseDeNegocio = caseDeNegocio;

            trofeuDTO.PreencherEntidade(trofeu);

            Adicionar(trofeu);

            return(trofeu.Id);
        }
        public AvaliarRespostasDTO ObterDadosDePreparacaoParaAvaliarRespostas(int idLicao, Usuario usuarioLogado)
        {
            Licao licao = _licaoRepository.GetById(idLicao);

            if (licao == null)
            {
                throw new Exception("Lição não encontrada.");
            }

            bool ehProfessor = _caseDeNegocioService.UsuarioEstaAssociadoAoCaseDeNegocioComoProfessor(usuarioLogado, licao.CaseDeNegocio);

            if (!ehProfessor)
            {
                throw new Exception("Apenas professores têm permissão para avaliar as lições entregues.");
            }

            var trofeus = _trofeuRepository.Listar(licao.IdCase);

            return(new AvaliarRespostasDTO(licao, trofeus));
        }
Esempio n. 3
0
        public void Atribuir(AtribuirTrofeuRequest request, Usuario usuario)
        {
            Trofeu trofeu = _trofeuRepository.GetById(request.IdTrofeu);

            if (trofeu == null)
            {
                throw new Exception("Troféu não localizado.");
            }

            CaseDeNegocio caseDeNegocio = _caseDeNegocioService.ObterPorId(trofeu.IdCase);

            if (!_caseDeNegocioService.UsuarioEstaAssociadoAoCaseDeNegocioComoProfessor(usuario, caseDeNegocio))
            {
                throw new Exception("Usuário não possui permissão para esta solicitação.");
            }

            EntregaDeLicao entregaDeLicao = _entregaDeLicaoRepository.GetById(request.IdEntregaDeLicao);

            if (entregaDeLicao == null)
            {
                throw new Exception("Lição não localizada.");
            }
            else if (entregaDeLicao.Licao.IdCase != caseDeNegocio.Id)
            {
                throw new Exception("Lição não pode ser associada à este troféu.");
            }

            Resposta resposta = null;

            if (request.IdResposta != null && request.IdResposta > 0)
            {
                resposta = _respostaRepository.GetById(request.IdResposta.Value);
                if (resposta == null)
                {
                    throw new Exception("Questão não localizada.");
                }
                else if (resposta.IdEntregaDeLicao != entregaDeLicao.Id)
                {
                    throw new Exception("Resposta não associada à lição.");
                }
            }

            EntregaDeTrofeu entregaDeTrofeu = new EntregaDeTrofeu(trofeu, entregaDeLicao, resposta);

            Adicionar(entregaDeTrofeu);
        }