Exemple #1
0
        // PUT api/Reason/5
        public IHttpActionResult PutReason(int id, Reason reason)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != reason.reasonId)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemple #2
0
        public IHttpActionResult PostReason(Reason reason)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Reasons.Add(reason);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = reason.reasonId }, reason);
        }