Пример #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);
        }
Пример #2
0
 public ActionResult Put([FromBody] TrofeuDTO trofeuDTO)
 {
     try
     {
         _trofeuService.Atualizar(trofeuDTO, _usuarioLogado.Obter());
         return(NoContent());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #3
0
 public ActionResult Post([FromBody] TrofeuDTO trofeuDTO)
 {
     try
     {
         int id = _trofeuService.Adicionar(trofeuDTO, _usuarioLogado.Obter());
         return(Ok(id));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #4
0
        public IEnumerable <TrofeuDTO> Listar(int idCaseDeNegocio)
        {
            List <TrofeuDTO> response = new List <TrofeuDTO>();

            var trofeus = _trofeuRepository.Listar(idCaseDeNegocio);

            foreach (var trofeu in trofeus)
            {
                TrofeuDTO trofeuDTO = new TrofeuDTO(trofeu);
                response.Add(trofeuDTO);
            }

            return(response);
        }
Пример #5
0
        public void Atualizar(TrofeuDTO trofeuDTO, Usuario usuarioLogado)
        {
            if (trofeuDTO == null || !trofeuDTO.Id.HasValue)
            {
                throw new Exception("Solicitação inválida.");
            }

            Trofeu trofeu = ObterPorId(trofeuDTO.Id.Value);

            if (trofeu == null || trofeu.IdCase != trofeuDTO.IdCase)
            {
                throw new Exception("Troféu não encontrado.");
            }

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

            trofeuDTO.PreencherEntidade(trofeu);

            Atualizar(trofeu);
        }