/// <summary>
 /// Create a new ORDER object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="tABLE_ID">Initial value of the TABLE_ID property.</param>
 public static ORDER CreateORDER(global::System.Guid id, global::System.Guid tABLE_ID)
 {
     ORDER oRDER = new ORDER();
     oRDER.Id = id;
     oRDER.TABLE_ID = tABLE_ID;
     return oRDER;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the ORDER EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToORDER(ORDER oRDER)
 {
     base.AddObject("ORDER", oRDER);
 }
        //Inserted ordered dishes
        public Boolean InsertOrdered(List<OrderDetailDTO> lst, short table_code)
        {
            try
            {

                ORDER order;
                OrderDTO query = (from p in Context.ORDER
                                  where p.TABLES_INFO.CODE == table_code
                                  select new OrderDTO()
                                  {
                                     ID=p.Id,
                                     STATUS=p.STATUS 
                                  }).SingleOrDefault();
                if (query == null)
                {
                    order = new ORDER();
                    query = new OrderDTO();
                    order.Id = Guid.NewGuid();
                    query.ID = order.Id;
                    Guid table_id = (from p in Context.TABLES_INFO where p.CODE == table_code select p.Id).SingleOrDefault();
                    order.TABLE_ID = table_id;
                    order.ADD_TIME = DateTime.Now;
                    order.STATUS = "Chờ xác nhận";
                    query.STATUS = order.STATUS;
                    Context.ORDER.AddObject(order);
                }
                foreach (OrderDetailDTO item in lst)
                {
                    ORDER_DETAIL orderdtl = new ORDER_DETAIL();
                    orderdtl.Id  = Guid.NewGuid();
                    ChefDTO chef = GetChefFree();
                    if (chef != null) orderdtl.CHEF_ID = chef.ID;
                    orderdtl.AMOUNT = item.AMOUNT;
                    orderdtl.DISH_ID = item.DISH_ID;
                    orderdtl.ORDER_ID = query.ID;
                    orderdtl.STATUS = "Chờ làm";
                    Context.ORDER_DETAIL.AddObject(orderdtl);
                }
                Context.SaveChanges();
                if (query.STATUS == "Đang làm")
                {
                    ProccessRepostitory rep = new ProccessRepostitory();
                    rep.SendToChicken(query.ID);
                }
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }