// PUT api/OrderLines/5 public IHttpActionResult PutOrderLine(int id, OrderLine orderline) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != orderline.Id) { return(BadRequest()); } db.Entry(orderline).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OrderLineExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "OrderID,OrderName,OrderDate,Paid,AmountLeft,Total")] Orders orders) { if (ModelState.IsValid) { db.OrdersList.Add(orders); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(orders)); }
public ActionResult Create(Orders orders) { if (ModelState.IsValid) { db.OrdersDbSet.Add(orders); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(orders)); }
public IActionResult Post(Order order) { //Determine the next ID int newID = _context.Orders.Any() ? _context.Orders.Select(x => x.Id).Max() + 1 : 1; order.Id = newID; _context.Orders.Add(order); _context.SaveChanges(); return(Ok(order)); }
public void UpdateOrderStatus(long id, string newStatus) { var order = _dBContext.Orders.FirstOrDefault(x => x.OxId == id); var statusId = _dBContext.OrderStatuses.FirstOrDefault(x => x.Name.Trim().ToLower() == newStatus.Trim().ToLower())?.Id; if (order != null) { order.OrderStatus = statusId; _dBContext.SaveChanges(); } }
public void Import(OrdersXml ordersXml) { using (var transaction = _dBContext.Database.BeginTransaction()) { try { foreach (var orderXml in ordersXml.Orders) { Import(orderXml); Import(orderXml.BillingAddress, orderXml.Oxid); foreach (var paymentXml in orderXml.Payments) { Import(paymentXml, orderXml.Oxid); } foreach (var articleXml in orderXml.Articles) { Import(articleXml, orderXml.Oxid); } _dBContext.SaveChanges(); } } catch { _dBContext.Database.RollbackTransaction(); } finally { _dBContext.Database.CommitTransaction(); } } }
private void SeedData() { if (!dbContext.Orders.Any()) { var items = new List <DB.OrderItem>(); items.Add(new DB.OrderItem(55, 45, 6, 23.50M)); items.Add(new DB.OrderItem(56, 324, 67, 101.00M)); items.Add(new DB.OrderItem(57, 1, 32, 1.75M)); items.Add(new DB.OrderItem(58, 567, 12, 43.00M)); dbContext.Orders.Add(new DB.Order() { Id = 1, CustomerId = 99, OrderDate = DateTime.Now, Total = 0, Items = items }); dbContext.Orders.Add(new DB.Order() { Id = 2, CustomerId = 98, OrderDate = DateTime.Now, Total = 0, Items = items }); dbContext.Orders.Add(new DB.Order() { Id = 3, CustomerId = 97, OrderDate = DateTime.Now, Total = 0, Items = items }); dbContext.Orders.Add(new DB.Order() { Id = 4, CustomerId = 96, OrderDate = DateTime.Now, Total = 0, Items = items }); dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Orders.Any()) { dbContext.Orders.Add(new Db.Order { Id = 1, CustomerId = 1, OrderDate = DateTime.Now, Total = 8800, Items = new List <Db.OrderItem> { new OrderItem { Id = 1, OrderId = 1, ProductId = 1, Quantity = 10, UnitPrice = 2300 }, new OrderItem { Id = 2, OrderId = 1, ProductId = 2, Quantity = 5, UnitPrice = 500 }, new OrderItem { Id = 3, OrderId = 1, ProductId = 3, Quantity = 6, UnitPrice = 6000 } } }); dbContext.Orders.Add(new Db.Order { Id = 2, CustomerId = 2, OrderDate = DateTime.Now, Total = 24000, Items = new List <Db.OrderItem> { new OrderItem { Id = 4, OrderId = 2, ProductId = 1, Quantity = 10, UnitPrice = 5500 }, new OrderItem { Id = 5, OrderId = 2, ProductId = 2, Quantity = 15, UnitPrice = 500 }, new OrderItem { Id = 6, OrderId = 2, ProductId = 3, Quantity = 16, UnitPrice = 18000 } } }); dbContext.SaveChanges(); } }
public Task <bool> SaveOrder(PizzaOrderModel orderModel) { var order = new PizzaOrder(orderModel.Pizza); foreach (var topping in orderModel.Toppings) { order.Orders.Add(new PizzaOrderDetail(order, topping)); } var saveOrder = new TaskCompletionSource <bool>(); if (order.Orders.Any()) { _context.PizzaOrders.Add(order); _context.SaveChanges(); saveOrder.SetResult(true); } return(saveOrder.Task); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new OrdersDBContext( serviceProvider.GetRequiredService <DbContextOptions <OrdersDBContext> >())) { // Look for any board games already in database. if (context.Orders.Any()) { return; // Database has been seeded } context.Orders.AddRange( new Order { Id = 1, Crust = "NORMAL", Flavor = "CHICKEN-FAJITA", Size = "L", TableNo = 3, }, new Order { Id = 2, Crust = "NORMAL", Flavor = "BEEF-NORMAL", Size = "M", TableNo = 5, }, new Order { Id = 3, Crust = "THIN", Flavor = "CHEESE", Size = "S", TableNo = 2, } ); context.SaveChanges(); } }