コード例 #1
0
        public IHttpActionResult PosttbEstudante(tbEstudante tbEstudante)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tbEstudante.Add(tbEstudante);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (tbEstudanteExists(tbEstudante.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = tbEstudante.Id }, tbEstudante));
        }
コード例 #2
0
        public IHttpActionResult PuttbEstudante(int id, tbEstudante tbEstudante)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tbEstudante.Id)
            {
                return(BadRequest());
            }

            db.Entry(tbEstudante).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tbEstudanteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public IHttpActionResult GettbEstudante(int id)
        {
            tbEstudante tbEstudante = db.tbEstudante.Find(id);

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

            return(Ok(tbEstudante));
        }
コード例 #4
0
        public IHttpActionResult DeletetbEstudante(int id)
        {
            tbEstudante tbEstudante = db.tbEstudante.Find(id);

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

            db.tbEstudante.Remove(tbEstudante);
            db.SaveChanges();

            return(Ok(tbEstudante));
        }