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

            db.Indication.Add(indication);

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

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

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }