Ejemplo n.º 1
0
        public async Task<IHttpActionResult> PutNeighbourhood(int id, Neighbourhood neighbourhood)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != neighbourhood.NeighbourhoodID)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Ejemplo n.º 2
0
        public async Task<IHttpActionResult> PostNeighbourhood(Neighbourhood neighbourhood)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Neighbourhoods.Add(neighbourhood);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = neighbourhood.NeighbourhoodID }, neighbourhood);
        }