Exemplo n.º 1
0
        public IHttpActionResult PutTheory(int id, Theory theory)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != theory.TheoryId)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 2
0
        public IHttpActionResult PostTheory(Theory theory)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Theories.Add(theory);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = theory.TheoryId }, theory);
        }