예제 #1
0
        public async Task<IHttpActionResult> PutVillage(int id, Village village)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VillageExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #2
0
        public async Task<IHttpActionResult> PostVillage(Village village)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Villages.Add(village);
            await db.SaveChangesAsync();

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