示例#1
0
 public void Adicionar(ProfessorTurmas professorTurma)
 {
     try
     {
         _ctx.ProfessorTurmas.Add(professorTurma);
         _ctx.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
示例#2
0
        public ProfessorTurmas BuscarPorId(Guid id)
        {
            try
            {
                ProfessorTurmas professorTurma = _ctx.ProfessorTurmas.Find(id);

                return(professorTurma);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public IActionResult Post([FromForm] ProfessorTurmas professorTurma)
        {
            try
            {
                _professorTurmaRepository.Adicionar(professorTurma);

                return(Ok(professorTurma));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#4
0
        public void Remover(Guid id)
        {
            try
            {
                ProfessorTurmas professorTurma = BuscarPorId(id);

                if (professorTurma == null)
                {
                    throw new Exception("Professor não encontrado");
                }

                _ctx.ProfessorTurmas.Remove(professorTurma);
                _ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public IActionResult Get(Guid id)
        {
            try
            {
                ProfessorTurmas professorTurma = _professorTurmaRepository.BuscarPorId(id);


                if (professorTurma == null)
                {
                    return(NotFound());
                }

                return(Ok(professorTurma));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IActionResult Put(Guid id, ProfessorTurmas professorTurma)
        {
            try
            {
                var ProfessorTurma = _professorTurmaRepository.BuscarPorId(id);

                if (ProfessorTurma == null)
                {
                    return(NotFound());
                }

                professorTurma.IdProfessorTurma = id;
                _professorTurmaRepository.Editar(professorTurma);

                return(Ok(professorTurma));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#7
0
        public void Editar(ProfessorTurmas professorTurma)
        {
            try
            {
                ProfessorTurmas professorTurmaTemp = BuscarPorId(professorTurma.IdProfessorTurma);

                if (professorTurmaTemp == null)
                {
                    throw new Exception("Professor não encontrado");
                }

                professorTurmaTemp.IdUsuario = professorTurma.IdUsuario;
                professorTurmaTemp.IdTurma   = professorTurma.IdTurma;

                _ctx.ProfessorTurmas.Update(professorTurmaTemp);
                _ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }