public IHttpActionResult PutPortfolioItem(int id, PortfolioItem portfolioItem) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != portfolioItem.Id) { return BadRequest(); } db.Entry(portfolioItem).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PortfolioItemExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostPortfolioItem(PortfolioItem portfolioItem) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.PortfolioItems.Add(portfolioItem); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = portfolioItem.Id }, portfolioItem); }