// POST api/<controller> public HttpResponseMessage Post(Order order) { if (ModelState.IsValid) { Order newOrder = new Order { BaseTeaId = order.BaseTea.Id, FlavorId = order.Flavor.Id, SizeId = order.Size.Id, Toppings = new List <Topping>(), }; foreach (var topping in order.Toppings) { newOrder.Toppings.Add(db.Toppings.FirstOrDefault(x => x.Id == topping.Id)); } db.Entry(newOrder).State = EntityState.Added; db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, order); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = order.Id })); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
// POST api/<controller> public HttpResponseMessage Post(Topping topping) { if (ModelState.IsValid) { db.Toppings.Add(topping); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, topping); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = topping.Id })); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
private void Seed(TeaContext testcontext) { testcontext.Products.AddRange(testProducts); testcontext.Customers.AddRange(testCustomers); testcontext.Locations.AddRange(testLocations); testcontext.Locations.AddRange(testLocations2); testcontext.Orders.AddRange(testOrders); testcontext.Orders.AddRange(testOrderHistory1); testcontext.Orders.AddRange(testOrderHistory1); testcontext.Orderitems.AddRange(testOrderItems); testcontext.Inventory.AddRange(testInventory); testcontext.SaveChanges(); }
public static void Initialize(TeaContext context) { if (!context.Products.Any() || !context.Employees.Any()) { context.Employees.AddRange( new Employee { Login = "******", Password = "******" } ); context.Products.AddRange( new Product { Title = "Ассам FBOP", Description = "fbop.txt", Weight = 0.05, Dimensions = "12 x 5 x 3", Quantity = 5, Price = 75, Image = "fbop.jpg" }, new Product { Title = "Те Гуань Инь в.к.", Description = "teguan.txt", Weight = 0.05, Dimensions = "12 x 3 x 2", Quantity = 3, Price = 350, Image = "teguan.jpg" }, new Product { Title = "Хун Му Дань", Description = "hunmudan.txt", Weight = 0.05, Dimensions = "12 x 4 x 5", Quantity = 0, Price = 200, Image = "hunmudan.jpg" }, new Product { Title = "Кения FOP", Description = "fop.txt", Weight = 0.05, Dimensions = "10 x 7 x 3", Quantity = 9, Price = 150, Image = "fop.jpg" }, new Product { Title = "Лун Цзин в.к.", Description = "lunzin.txt", Weight = 0.05, Dimensions = "12 x 5 x 3", Quantity = 42, Price = 200, Image = "lunzin.jpg" }, new Product { Title = "Бай Хуа Сянь Цзы", Description = "buyhia.txt", Weight = 0.05, Dimensions = "12 x 5 x 3", Quantity = 22, Price = 467, Image = "buyhia.jpg" }, new Product { Title = "Дянь Хун Мао Фэн", Description = "dyanhun.txt", Weight = 0.05, Dimensions = "12 x 5 x 3", Quantity = 15, Price = 210, Image = "dyanhun.jpg" }, new Product { Title = "Шу Сян Люй", Description = "shusyan.txt", Weight = 0.05, Dimensions = "12 x 5 x 3", Quantity = 11, Price = 100, Image = "shusyan.jpg" }, new Product { Title = "Дарджилинг FTGFOP1", Description = "dardzhil.txt", Weight = 0.05, Dimensions = "12 x 5 x 3", Quantity = 43, Price = 7530, Image = "dardzhil.jpg" }, new Product { Title = "Цзинь Ло", Description = "zinlo.txt", Weight = 0.05, Dimensions = "12 x 5 x 3", Quantity = 228, Price = 10, Image = "zinlo.jpg" } ); context.SaveChanges(); } }