コード例 #1
0
        public ActionResult <Escola> PostEscola([FromBody] Escola escola)
        {
            try
            {
                if (escola == null)
                {
                    return(NoContent());
                }

                _contexto.Escolas.Add(escola);
                _contexto.SaveChanges();

                return(CreatedAtAction("GetEscola", new { id = escola.IdEscola }, escola));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
コード例 #2
0
        public ActionResult <Turma> PostTurma([FromBody] Turma turma)
        {
            try
            {
                if (turma == null)
                {
                    return(NoContent());
                }
                if (turma.Escola == null)
                {
                    return(BadRequest());
                }

                _contexto.Turmas.Add(turma);
                _contexto.Entry(turma.Escola).State = EntityState.Detached;
                _contexto.SaveChanges();

                return(CreatedAtAction("GetTurma", new { id = turma.IdTurma }, turma));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }