public void PutProduct(int id, Product Product) { Product.Id = id; if (!repository.Update(Product)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } }
public HttpResponseMessage PostProduct(Product item) { item = repository.Add(item); var response = Request.CreateResponse<Product>(HttpStatusCode.Created, item); string uri = Url.Link("DefaultApi", new { id = item.Id }); response.Headers.Location = new Uri(uri); return response; }
public bool Update(Product item) { int index = Products.FindIndex(p => p.Id == item.Id); if (index == -1) { return false; } Products.RemoveAt(index); Products.Add(item); return true; }
public Product Add(Product item) { item.Id = _nextId++; Products.Add(item); return item; }