示例#1
0
        public IHttpActionResult PutContraction(int id, Contraction contraction)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != contraction.Id || !CurrentUser.Contractions.Any(c => c.Id == id))
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
示例#2
0
        public IHttpActionResult PostContraction(Contraction contraction)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            CurrentUser.Contractions.Add(contraction);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = contraction.Id }, contraction);
        }