コード例 #1
0
 public void PutProduct(int id, Product Product)
 {
     Product.Id = id;
     if (!repository.Update(Product))
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
     }
 }
コード例 #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;
        }
コード例 #3
0
 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;
 }
コード例 #4
0
 public Product Add(Product item)
 {
     item.Id = _nextId++;
     Products.Add(item);
     return item;
 }