public void ListDihInOrder(int id_dish, int count) //заполнение промежутоного списка заказа { if (count != 0) { var content = new content_orders(); int MaxId; if (db.content_orders.Count() != 0) { MaxId = int.Parse(db.content_orders.Max(p => p.id_content_order).ToString()) + 1; } else { if (orders.ListDishesinOrd.Count() != 0) { MaxId = orders.ListDishesinOrd.Max(p => p.id_content_order) + 1; } else { MaxId = 1; } } content.id_content_order = MaxId; content.id_dish = id_dish; content.count_dish = count; orders.ListDishesinOrd.Add(content); } }
public int SaveOrd(int id_emp, int id_tab) //сохранение информации о заказе { orders ord = new orders(); ord.id_employee = db.employee.First(p => p.id_employee == id_emp).id_employee; ord.id_table = id_tab; ord.time_order = DateTime.Now.TimeOfDay; var stock = new List <stocks>(); if (db.stocks.Where(p => p.start_time < p.end_time) != null) { stock = db.stocks.Where(p => p.start_time <= ord.time_order && p.end_time >= ord.time_order).ToList(); } if (db.stocks.Where(p => p.start_time > p.end_time) != null) { stock.AddRange(db.stocks.Where(p => (p.start_time > p.end_time) && ((p.start_time >= ord.time_order) || (p.end_time >= ord.time_order))).ToList()); } if (stock.Count != 0) { var discount = stock.Min(p => p.discount); ord.id_stock = db.stocks.First(p => p.discount == discount).id_stock; } else { ord.id_stock = null; } db.orders.Add(ord); db.SaveChanges(); foreach (content_orders i in ListDishesinOrd) { var content = new content_orders(); content.id_content_order = i.id_content_order; content.id_order = ord.id_order; content.id_dish = db.list_of_dishes.First(p => p.id_dish == i.id_dish).id_dish; content.count_dish = i.count_dish; db.content_orders.Add(content); db.SaveChanges(); } return(ord.id_order); }