public IHttpActionResult PostDiscount(Discount discount) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Discount.Add(discount); try { db.SaveChanges(); } catch (DbUpdateException) { if (DiscountExists(discount.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = discount.Id }, discount); }
public IHttpActionResult PutDiscount(int id, Discount discount) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != discount.Id) { return BadRequest(); } db.Entry(discount).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DiscountExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }