/// <summary> /// Create a new product /// </summary> /// <param name="item">The product item as specified in the body as xml/json.</param> /// <returns></returns> 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 Product Add(Product item) { if (item == null) { throw new ArgumentNullException("item"); } item.Id = _nextId++; products.Add(item); return item; }
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; }
private void AddTestData(ProductContext context) { var warehouse1 = new Warehouse() { Locality = "SP", Quantity = 12, Type = "ECOMMERCE" }; var warehouse2 = new Warehouse() { Locality = "MOEMA", Quantity = 3, Type = "PHYSICAL_STORE" }; var inventory = new Inventory() { Warehouses = new List <Warehouse>() }; inventory.Warehouses.Add(warehouse1); inventory.Warehouses.Add(warehouse2); var testeProduto1 = new Models.Product { ProductId = 1, Name = "L'Oréal Professionnel Expert Absolut Repair Cortex Lipidium - Máscara de Reconstrução 500g", Sku = 43264, // Inventory = inventory }; context.Products.Add(testeProduto1); context.SaveChanges(); }
/// <summary> /// Update a product /// </summary> /// <param name="id">Id of the product to update.</param> /// <param name="product">Request body which will replace the product contents.</param> /// <returns></returns> public void PutProduct(int id, Product product) { product.Id = id; if (!repository.Update(product)) { throw new HttpResponseException(HttpStatusCode.NotFound); } }