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); }
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); }