예제 #1
0
        public IHttpActionResult PutNewUnit(int id, NewUnit newUnit)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #2
0
        public IHttpActionResult PostNewUnit(NewUnit newUnit)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.NewUnits.Add(newUnit);
            db.SaveChanges();

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