Exemplo n.º 1
0
        // POST odata/Sites
        public async Task<IHttpActionResult> Post(Site site)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Sites.Add(site);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (SiteExists(site.SiteNumber))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return Created(site);
        }
Exemplo n.º 2
0
        // PUT odata/Sites(5)
        public async Task<IHttpActionResult> Put([FromODataUri] string key, Site site)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (key != site.SiteNumber)
            {
                return BadRequest();
            }

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

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

            return Updated(site);
        }