Esempio n. 1
0
        // PUT api/Narratives/5
        public IHttpActionResult PutNarrative(int id, Narrative narrative)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != narrative.ID)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Esempio n. 2
0
        public IHttpActionResult PostNarrative(Narrative narrative)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Narratives.Add(narrative);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = narrative.ID }, narrative);
        }