Пример #1
0
        public IHttpActionResult PostCountryRegion(CountryRegion countryRegion)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.CountryRegions.Add(countryRegion);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CountryRegionExists(countryRegion.CountryRegionCode))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = countryRegion.CountryRegionCode }, countryRegion);
        }
Пример #2
0
        public IHttpActionResult PutCountryRegion(string id, CountryRegion countryRegion)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != countryRegion.CountryRegionCode)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }