public void SaveItem(Int32 productId, Int32 knopaId, CommonUnit.ProductType type)
        {
            ItemService      _itemService      = new ItemService();
            InventoryService _inventoryService = new InventoryService();

            ChecksMenuProductItem query = null;

            if (productId != 0 && knopaId != 0)
            {
                using (menuzRusDataContext db = new menuzRusDataContext(base.connectionString)) {
                    if (type == CommonUnit.ProductType.Alternatives)
                    {
                        query = db.ChecksMenuProductItems.FirstOrDefault(m => m.ProductId == productId);
                        if (query != default(ChecksMenuProductItem))
                        {
                            query.ItemId = knopaId;
                        }
                    }
                    else if (type == CommonUnit.ProductType.Addons)
                    {
                        query = db.ChecksMenuProductItems.FirstOrDefault(m => m.ProductId == productId && m.ItemId == knopaId);
                        if (query == default(ChecksMenuProductItem))
                        {
                            query           = new ChecksMenuProductItem();
                            query.ItemId    = knopaId;
                            query.ProductId = productId;
                            db.ChecksMenuProductItems.InsertOnSubmit(query);
                        }
                        else
                        {
                            db.ChecksMenuProductItems.DeleteOnSubmit(query);
                        }
                    }
                    db.SubmitChanges();
                }
            }
        }
        public ChecksMenu SaveMenuItem(Item menuItem, Int32 tableId, Int32 orderId, Int32 userId)
        {
            ItemService      _itemService      = new ItemService();
            InventoryService _inventoryService = new InventoryService();

            ChecksMenu orderCheckMenu;

            try {
                using (menuzRusDataContext db = new menuzRusDataContext(base.connectionString)) {
                    // New order
                    TableOrder tableOrder = db.TableOrders.FirstOrDefault(m => m.TableId == tableId && m.Status != (Int32)CommonUnit.TableOrderStatus.Closed);
                    if (tableOrder == default(TableOrder))
                    {
                        tableOrder         = new TableOrder();
                        tableOrder.TableId = tableId;
                        tableOrder.Status  = (Int32)CommonUnit.TableOrderStatus.Open;
                        db.TableOrders.InsertOnSubmit(tableOrder);
                        db.SubmitChanges();
                    }

                    Check orderCheck = db.Checks.FirstOrDefault(m => m.id == orderId);
                    if (orderCheck == default(Check))
                    {
                        orderCheck = new Check();
                        orderCheck.TableOrderId = tableOrder.id;
                        orderCheck.Type         = (Int32)CommonUnit.CheckType.Guest;
                        orderCheck.Status       = (Int32)CommonUnit.CheckStatus.Active;
                        orderCheck.UserId       = userId;
                        db.Checks.InsertOnSubmit(orderCheck);
                        db.SubmitChanges();
                    }

                    orderCheckMenu         = new ChecksMenu();
                    orderCheckMenu.CheckId = orderCheck.id;
                    orderCheckMenu.MenuId  = menuItem.id;
                    orderCheckMenu.Status  = (Int32)CommonUnit.MenuItemStatus.Active;
                    db.ChecksMenus.InsertOnSubmit(orderCheckMenu);
                    db.SubmitChanges();

                    foreach (ItemProduct itemProduct in menuItem.ItemProducts)
                    {
                        ChecksMenuProduct product = new ChecksMenuProduct();
                        product.CheckMenuId = orderCheckMenu.id;
                        product.ItemId      = itemProduct.id;
                        db.ChecksMenuProducts.InsertOnSubmit(product);
                        db.SubmitChanges();
                        if (itemProduct.ItemProductAssociations.Count() > 0)
                        {
                            ChecksMenuProductItem item = new ChecksMenuProductItem();
                            item.ProductId = product.id;
                            item.ItemId    = itemProduct.ItemProductAssociations[0].id;
                            db.ChecksMenuProductItems.InsertOnSubmit(item);
                            db.SubmitChanges();
                        }
                    }
                }
            }
            catch (Exception ex) {
                return(null);
            }
            return(orderCheckMenu);
        }