Esempio n. 1
0
 public void PutProduct(int id, Product product)
 {
     product.Id = id;
     if (!repository.Update(product))
     {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
 }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
 public Product Add(Product item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     item.Id = _nextId++;
     products.Add(item);
     return item;
 }
Esempio n. 4
0
 public bool Update(Product item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     int index = products.FindIndex(p => p.Id == item.Id);
     if (index == -1)
     {
         return false;
     }
     products.RemoveAt(index);
     products.Add(item);
     return true;
 }