public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != product.Id) { return BadRequest(); } 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) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Products.Add(product); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = product.Id }, product); }
public SeedData() { Category topliNapitci = new Category { Name = "Topli napitci", ChildCategories = new List<Category> { new Category { Name="Kave", ChildCategories = new List<Category>() }, new Category { Name="Čajevi", ChildCategories = new List<Category>() }, new Category { Name="Ostalo" } } }; Category alkohol = new Category { Name = "Alkohol", ChildCategories = new List<Category> { new Category { Name="Pive", ChildCategories = new List<Category>() }, new Category { Name="Žestoko", ChildCategories = new List<Category>() }, new Category { Name ="Ostalo" } } }; Category sokovi = new Category { Name = "Sokovi", ChildCategories = new List<Category> { new Category { Name="Gazirani", ChildCategories = new List<Category>() }, new Category { Name="Negazirani", ChildCategories = new List<Category>() }, new Category { Name="Ostalo" } } }; Product kava1 = new Product { Name = "Kava s toplim mlijekom", Price = 10.00, CategoryId = 32 }; Product kava2 = new Product { Name = "Kava s hladnim mlijekom", Price = 10.00, CategoryId = 32 }; Product caj = new Product { Name = "Čaj od kamilice", Price = 12.00, CategoryId = 42 }; Waiter waiter1 = new Waiter { FirstName = "Matija", LastName = "Vukić", Password = "******", Orders = new List<Order>() }; Waiter waiter2 = new Waiter { FirstName = "Shimun", LastName = "Matić", Password = "******", Orders = new List<Order>() }; Waiter waiter3 = new Waiter { FirstName = "Adolf", LastName = "Hitler", Password = "******", Orders = new List<Order>() }; //3 kave s toplim mlijekom + 1 čaj Order order1 = new Order { Paid = false, Processed = false, TableId = 7, OrderItems = new List<OrderItem> { new OrderItem { ProductId = 11, Quantity = 3 }, new OrderItem { ProductId = 31, Quantity = 1 } } }; //db.Orders.Add(order1); //db.Orders.Add(order2); //db.Waiters.Add(waiter1); //db.Waiters.Add(waiter2); //db.Waiters.Add(waiter3); //db.Products.Add(kava1); //db.Products.Add(kava2); //db.Products.Add(caj); //db.Categories.Add(topliNapitci); //db.Categories.Add(alkohol); //db.Categories.Add(sokovi); db.SaveChanges(); }