public TableViewModel()
        {
            bl = new BussinesLogic();
            //List<Ration> rations = bl.GetAllRations();
            //List<Order> orders = bl.GetAllOrders();
            Tables = new ObservableCollection <Table>();
            _PopulateTables(bl.GetAllTables().AsQueryable());


            Delete = new DeleteCommand(
                () => CanDelete,
                table =>
            {
                CurrentTable = null;
                _PopulateTables(bl.GetAllTables().AsQueryable());
            });

            DeleteRationCmd = new DelegateCommand(
                ration => CanDelete,
                ration =>
            {
                CurrentTable.RationList.Remove(CurrentRation);
                bl.Delete(CurrentRation);
                bl.Update(CurrentTable);
                CurrentRation = null;
                _PopulateTables(bl.GetAllTables().AsQueryable());
            });

            AddTableCmd = new DelegateCommand(
                ration =>
            {
                //CurrentOrder.RationList.Add(new Ration());
                //bl.Delete(CurrentRation);
                //bl.Update(CurrentOrder);
                Table newTable = new Table();
                bl.Insert(newTable);
                CurrentTable = newTable;
                _PopulateTables(bl.GetAllTables().AsQueryable());
            });

            AddRationCmd = new DelegateCommand(
                ration =>
            {
                CurrentTable.RationList.Add(new Ration()
                {
                    CreationDate = DateTime.Now
                });
                //bl.Delete(CurrentRation);
                bl.Update(CurrentTable);
                _PopulateTables(bl.GetAllTables().AsQueryable());
            });
        }
Esempio n. 2
0
        public void Execute(object parameter)
        {
            if (CanExecute(parameter))
            {
                var table = parameter as Table;
                if (table != null)
                {
                    var result = MessageBox.Show("Are you sure you wish to delete the Table?",
                                                 "Confirm Delete", MessageBoxButton.OKCancel);

                    if (result.Equals(MessageBoxResult.OK))
                    {
                        BussinesLogic bl = new BussinesLogic();
                        bl.Delete(table);
                        if (_deleted != null)
                        {
                            _deleted(table);
                        }
                    }
                }
            }
        }