Ejemplo n.º 1
0
        public InventoryListVM(NinjaListVM ninjaListVM)
        {
            _ninjaListVM = ninjaListVM;

            NinjaVM = _ninjaListVM.SelectedNinja;


            using (var context = new NinjaEntities())
            {
                var index          = NinjaVM.NinjaId;
                var inventoryItems = context.InventoryItems.ToList();
                var inventoryID    = (inventoryItems.Select(e => new InventoryVM(e)).Where(e => e.NinjaId == index)).ToList();

                var equipments = context.Equipments.ToList();
                EquipmentInventoryOC = new ObservableCollection <EquipmentVM>(equipments.Select(e => new EquipmentVM(e)).Where(e => inventoryID.Any(e2 => e2.EquipmentId == e.EquipmentId)));
            }


            ShowNinjaCommand      = new RelayCommand(ShowNinjas);
            ShowEquipmentsCommand = new RelayCommand(ShowEquipements);
            ShowShopCommand       = new RelayCommand(ShowShop);
            ShowVisualGearCommand = new RelayCommand(ShowVisualGear);
            EquipItemCommand      = new RelayCommand(EquipItem);

            SellEverythingCommand = new RelayCommand(SellEverything);
        }
Ejemplo n.º 2
0
        public ShopVM(NinjaListVM ninjaListVM, InventoryListVM inventoryListVM)
        {
            this._ninjaListVM = ninjaListVM;

            this.NinjaVM = _ninjaListVM.SelectedNinja;

            this._inventoryListVM = inventoryListVM;



            using (var context = new NinjaEntities())
            {
                var equipment = context.Equipments.ToList();
                ShopItemsOC = new ObservableCollection <EquipmentVM>(equipment.Select(e => new EquipmentVM(e)));
            }



            ShowInventoryCommand = new RelayCommand(ShowInventory);
            BuyItemCommand       = new RelayCommand(BuyItem);



            ShowLegsCategoryCommand      = new RelayCommand(RetrieveLegsItems);
            ShowBeltCategoryCommand      = new RelayCommand(RetrieveBeltItems);
            ShowChestCategoryCommand     = new RelayCommand(RetrieveChestItems);
            ShowBootsCategoryCommand     = new RelayCommand(RetrieveBootsItems);
            ShowShouldersCategoryCommand = new RelayCommand(RetrieveShouldersItems);
        }
Ejemplo n.º 3
0
        //--- Delete ---

        private void DeleteNinja()
        {
            using (var context = new NinjaEntities())
            {
                var ninja = SelectedNinja.ToModel();

                context.Entry(ninja).State = EntityState.Deleted;
                context.SaveChanges();
            }

            NinjasOC.Remove(SelectedNinja);
        }
Ejemplo n.º 4
0
        //--- Delete ---

        private void DeleteEquipment()
        {
            using (var context = new NinjaEntities())
            {
                var equipment = SelectedEquipment.ToModel();

                context.Entry(equipment).State = EntityState.Deleted;
                context.SaveChanges();
            }

            EquipmentsOC.Remove(SelectedEquipment);
        }
        private void UpdateEquipment()
        {
            using (var context = new NinjaEntities())
            {
                var equipment = EquipmentVM.ToModel();

                context.Entry(equipment).State = EntityState.Modified;
                context.SaveChanges();
            }

            _equipmentListVM.HideUpdateEquipment();
        }
Ejemplo n.º 6
0
        private void UpdateNinja()
        {
            using (var context = new NinjaEntities())
            {
                var ninja = NinjaVM.ToModel();

                context.Entry(ninja).State = EntityState.Modified;
                context.SaveChanges();
            }

            _ninjaListVM.HideUpdateNinja();
        }
Ejemplo n.º 7
0
        private void AddEquipment()
        {
            var equipment = Equipment.ToModel();

            using (var context = new NinjaEntities())
            {
                context.Equipments.Add(equipment);
                context.Entry(equipment).State = EntityState.Added;
                context.SaveChanges();
            }

            _equipmentListVM.EquipmentsOC.Add(Equipment);
            _equipmentListVM.HideAddEquipment();
        }
Ejemplo n.º 8
0
        private void AddNinja()
        {
            var ninja = Ninja.ToModel();

            using (var context = new NinjaEntities())
            {
                context.Ninjas.Add(ninja);
                context.Entry(ninja).State = EntityState.Added;
                context.SaveChanges();
            }

            _ninjaListVM.NinjasOC.Add(Ninja);
            _ninjaListVM.HideAddNinja();
        }
Ejemplo n.º 9
0
        public EquipmentListVM(InventoryListVM inventoryListVM)
        {
            _inventoryListVM = inventoryListVM;

            using (var context = new NinjaEntities())
            {
                var equipments = context.Equipments.ToList();
                EquipmentsOC = new ObservableCollection <EquipmentVM>(equipments.Select(r => new EquipmentVM(r)));
            }

            ShowAddEquipmentCommand    = new RelayCommand(ShowAddEquipment, CanShowAddEquipment);
            ShowUpdateEquipmentCommand = new RelayCommand(ShowUpdateEquipment, CanUpdateEquipment);
            DeleteEquipmentCommand     = new RelayCommand(DeleteEquipment);

            ShowIventoryCommand = new RelayCommand(ShowInventory);
        }
Ejemplo n.º 10
0
        public NinjaListVM(MainVM mainVM)
        {
            _mainVM = mainVM;
            App.Current.MainWindow.Close();

            using (var context = new NinjaEntities())
            {
                var ninjas = context.Ninjas.ToList();
                NinjasOC = new ObservableCollection <NinjaVM>(ninjas.Select(r => new NinjaVM(r)));
            }

            ShowAddNinjaCommand    = new RelayCommand(ShowAddNinja, CanShowAddNinja);
            ShowUpdateNinjaCommand = new RelayCommand(ShowUpdateNinja, CanUpdateNinja);
            DeleteNinjaCommand     = new RelayCommand(DeleteNinja);

            ShowInventoryCommand = new RelayCommand(ShowInventory);
        }
Ejemplo n.º 11
0
        private void SellEverything()
        {
            foreach (EquipmentVM e in EquipmentInventoryOC)
            {
                NinjaVM.Money += e.EquipmentValue;
            }


            using (var context = new NinjaEntities())
            {
                context.InventoryItems.Where(p => p.NinjaId == NinjaVM.NinjaId).ToList().ForEach(p => context.InventoryItems.Remove(p));

                var ninja = NinjaVM.ToModel();
                context.Entry(ninja).State = EntityState.Modified;
                context.SaveChanges();
            }


            EquipmentInventoryOC.Clear();
        }
Ejemplo n.º 12
0
        public void RetrieveCategoryItems(string equipmentType)
        {
            ShopItemsOC.Clear();

            using (var context = new NinjaEntities())
            {
                var equipment = context.Equipments.ToList();

                foreach (var e in equipment)
                {
                    if (e.EquipmentType == equipmentType)
                    {
                        ShopItemsOC.Add(new EquipmentVM(e));
                    }
                }
            }



            this.RaisePropertyChanged();
        }
Ejemplo n.º 13
0
        private void BuyItem()
        {
            if (SelectedEquipment != null && NinjaVM.Money > SelectedEquipment.EquipmentValue)
            {
                var InventoryItemVM = new InventoryVM();
                var inventoryItem   = InventoryItemVM.ToModel();


                inventoryItem.NinjaId          = NinjaVM.NinjaId;
                inventoryItem.IsUsingEquitment = false;
                inventoryItem.EquipmentId      = SelectedEquipment.EquipmentId;

                _inventoryListVM.EquipmentInventoryOC.Add(SelectedEquipment);


                using (var context = new NinjaEntities())
                {
                    EquipmentVM items = new EquipmentVM(context.Equipments.Where(e => e.EquipmentId == inventoryItem.EquipmentId).First());



                    NinjaVM.Money -= items.EquipmentValue;

                    var ninja = NinjaVM.ToModel();
                    context.Entry(ninja).State = EntityState.Modified;

                    context.InventoryItems.Add(inventoryItem);
                    context.Entry(inventoryItem).State = EntityState.Added;
                    context.SaveChanges();
                }


                this.RaisePropertyChanged();
                ShopItemsOC.Remove(SelectedEquipment);
            }
        }