public void AddOrder(string name, string address, String[] commodity) { using (var ctx = new OrderContext()) { string temId = num.ToString("000"); var orders = ctx.Orders.SingleOrDefault(o => o.OrderId == temId); while (orders != null) { num++; temId = num.ToString("000"); orders = ctx.Orders.SingleOrDefault(o => o.OrderId == temId); } } Order order = new Order(num.ToString("000"), name, address); for (int i = 0; i < commodity.Length; i++) { order.AddOrderDetails(commodity[i]); } using (var ctx = new OrderContext()) { ctx.Entry(order).State = EntityState.Added; ctx.SaveChanges(); } }
public void AddOrder(string name, string address, String[] commodity) { Console.WriteLine("创建" + num.ToString("000") + "号订单"); Order order = new Order(num.ToString("000"), name, address); num++; ordernumber++; for (int i = 0; i < commodity.Length; i++) { order.AddOrderDetails(commodity[i]); } list.Add(order); }
public void AddCommodity(string ID, string commdityName) { Order target = Search(ID); target.AddOrderDetails(commdityName); }