Ejemplo n.º 1
0
        public IHttpActionResult PostProductsSection(ProductsSection productsSection)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.ProductsSection.Add(productsSection);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ProductsSectionExists(productsSection.Id))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = productsSection.Id }, productsSection);
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutProductsSection(int id, ProductsSection productsSection)
        {
            if (!User.IsInRole("Administrators"))
            {
                return BadRequest("User must be admin!");
            }

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }