Exemplo n.º 1
0
        public void Execute(object parameter)
        {
            List <DbModel.Item> Items;

            using (var context = new DbModel.CodeFirstContext())
            {
                Services.GenericCRUD <DbModel.Item> ItemsCRUD = new Services.GenericCRUD <DbModel.Item>(context);
                Items = ItemsCRUD.Read();

                Console.WriteLine($"{ parameter}");

                if (parameter.ToString() == "All")
                {
                    _VM.Items = Items;
                }
                else if (parameter.ToString() == "Assepted")
                {
                    _VM.Items = (Items.Where(item => item.Category.Name == "Assepted")).ToList <DbModel.Item>();
                }
                else if (parameter.ToString() == "OnStore")
                {
                    _VM.Items = (Items.Where(item => item.Category.Name == "OnStore")).ToList <DbModel.Item>();
                }
                else if (parameter.ToString() == "Sold")
                {
                    _VM.Items = (Items.Where(item => item.Category.Name == "Sold")).ToList <DbModel.Item>();
                }
                else if (parameter.ToString() == "DatePeriod")
                {
                }
            }
        }
Exemplo n.º 2
0
        public void Execute(object parameter)
        {
            if (parameter.ToString() == "Add")
            {
                Views.InsertItemPage window = ((Views.InsertItemPage)_viewmodel.childWindow);
                string ItemTitle            = window.TextBox_ItemTitle.Text;
                int    ItemPrice            = Convert.ToInt32(window.TextBox_ItemPrice.Text);

                DbModel.Item NewItem = new DbModel.Item
                {
                    Title                = ItemTitle,
                    Price                = ItemPrice,
                    CategoryId           = 1,
                    MovingToCategoryDate = DateTime.Now,
                    StorageId            = 1
                };

                using (var context = new DbModel.CodeFirstContext())
                {
                    Services.GenericCRUD <DbModel.Item> ItemsCRUD = new Services.GenericCRUD <DbModel.Item>(context);
                    ItemsCRUD.Create(NewItem);
                }
                _viewmodel.FilterGridCommand.Execute("Assepted");
            }
            else if (parameter.ToString() == "MoveOnStore")
            {
                Views.MoveItemToStoreView window = ((Views.MoveItemToStoreView)_viewmodel.childWindow);
                DbModel.Item SelectedItem        = (DbModel.Item)window.ComboBox_ItemSelector.SelectedItem;
                /// Correct UPDATING !
                using (var context = new DbModel.CodeFirstContext())
                {
                    var item = context.Items.Where(i => i.ItemId == SelectedItem.ItemId).FirstOrDefault();
                    item.CategoryId = 2;
                    context.SaveChanges();
                }
                _viewmodel.FilterGridCommand.Execute("Assepted");
            }
            else if (parameter.ToString() == "Sell")
            {
                Views.SellingItemView window       = ((Views.SellingItemView)_viewmodel.childWindow);
                DbModel.Item          SelectedItem = (DbModel.Item)window.ComboBox_ItemSelector.SelectedItem;
                /// Correct UPDATING !
                using (var context = new DbModel.CodeFirstContext())
                {
                    var item = context.Items.Where(i => i.ItemId == SelectedItem.ItemId).FirstOrDefault();
                    item.CategoryId = 3;
                    context.SaveChanges();
                }
                _viewmodel.FilterGridCommand.Execute("OnStore");
            }

            _viewmodel.childWindow.Close();
        }
Exemplo n.º 3
0
        public ViewModelBase()
        {
            SpawnWindowCommand = new Commands.SpawnWindowCommand(this);
            FilterGridCommand  = new Commands.FilterGridCommand(this);
            CRUDCommand        = new Commands.CRUDCommand(this);

            using (var context = new DbModel.CodeFirstContext())
            {
                ItemsCRUD  = new Services.GenericCRUD <DbModel.Item>(context);
                this.Items = ItemsCRUD.Read();

                CategoriesCRUD  = new Services.GenericCRUD <DbModel.Category>(context);
                this.Categories = CategoriesCRUD.Read();

                StoragesCRUD  = new Services.GenericCRUD <DbModel.Storage>(context);
                this.Storages = StoragesCRUD.Read();

                //Items.ForEach(i => Console.WriteLine(i.Title));
                //Categories.ForEach(i => Console.WriteLine(i.Name));
                //Storages.ForEach(i => Console.WriteLine(i.Name));
            }
        }