public IHttpActionResult PutProduct(int id, Product product) { var currentUser = manager.FindById(User.Identity.GetUserId()); if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != product.ProductId) { return BadRequest(); } product.UserId = currentUser.Id; db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostProduct(Product product) { var currentUser = manager.FindById(User.Identity.GetUserId()); if (!ModelState.IsValid) { return BadRequest(ModelState); } product.UserId = currentUser.Id; db.Products.Add(product); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { controller = "ProductApi", id = product.ProductId }, new Product { ProductId = product.ProductId, ProductName = product.ProductName, ProductDetails = product.ProductDetails, ProductPrice = product.ProductPrice }); }