示例#1
0
        private void Edit()
        {
            Shop.SelectedItem.Name         = UpdatedName;
            Shop.SelectedItem.Category     = UpdatedCategory;
            Shop.SelectedItem.Price        = Convert.ToInt32(UpdatedPrice);
            Shop.SelectedItem.Agility      = Convert.ToInt32(UpdatedAgility);
            Shop.SelectedItem.Intelligence = Convert.ToInt32(UpdatedIntelligence);
            Shop.SelectedItem.Strength     = Convert.ToInt32(UpdatedStrength);

            int counter = 0;

            foreach (var item in _selectedNinja.InventoryItems)
            {
                if (item.ToModel().Id == Shop.SelectedItem.ToModel().Id)
                {
                    _selectedNinja.InventoryItems[counter] = Shop.SelectedItem;
                    _selectedNinja.UpdateStats();
                    break;
                }
                counter++;
            }

            using (var context = new LeagueOfNinjasEntities())
            {
                context.Entry(Shop.SelectedItem.ToModel()).State = EntityState.Modified;
                context.Entry(_selectedNinja.ToModel()).State    = EntityState.Modified;
                context.SaveChanges();
            }

            ItemVM selectedItem = Shop.SelectedItem;

            Shop.RetrieveCategoryItems(Shop.SelectedItem.Category);
            Shop.SelectedItem = selectedItem;
        }
示例#2
0
        private void Add(object parameter)
        {
            ItemVM Item = new ItemVM();

            Item.Name         = Name;
            Item.Price        = Convert.ToInt32(Price);
            Item.Category     = SelectedCategory;
            Item.Intelligence = Convert.ToInt32(Intelligence);
            Item.Agility      = Convert.ToInt32(Agility);
            Item.Strength     = Convert.ToInt32(Strength);

            using (var context = new LeagueOfNinjasEntities())
            {
                context.Gears.Add(Item.ToModel());
                context.SaveChanges();
            }

            _shopVM.ShopItems.Add(Item);
            _shopVM.TempShopItems.Add(Item);
            _shopVM.RetrieveCategoryItems(SelectedCategory);

            SelectedCategory = Item.Category;
            Agility          = Item.Agility.ToString();
            Intelligence     = Item.Intelligence.ToString();
            Strength         = Item.Strength.ToString();
            Price            = Item.Price.ToString();
            Name             = Item.Name;
        }
示例#3
0
        private void Clear(object parameter)
        {
            int id = SelectedNinja.ToModel().Id;

            foreach (var item in SelectedNinja.InventoryItems)
            {
                using (var ctx = new LeagueOfNinjasEntities())
                {
                    Ninja ninja = (from n in ctx.Ninjas
                                   where n.Id == id
                                   select n).FirstOrDefault <Ninja>();

                    Gear gear = ninja.Gears.FirstOrDefault <Gear>();
                    ninja.Intelligence -= item.Intelligence;
                    ninja.Strength     -= item.Strength;
                    ninja.Agility      -= item.Agility;
                    ninja.Gold         += item.Price;

                    //removing item from ninja
                    ninja.Gears.Remove(gear);
                    ctx.SaveChanges();
                }
            }
            SelectedNinja.ClearInventory();
        }
示例#4
0
 private void Delete(object parameter)
 {
     using (var context = new LeagueOfNinjasEntities())
     {
         context.Entry(SelectedNinja.ToModel()).State = EntityState.Deleted;
         context.SaveChanges();
     }
     Ninjas.Remove(SelectedNinja);
 }
示例#5
0
 private void Add(object parameter)
 {
     _ninjas.Ninjas.Add(Ninja);
     using (var context = new LeagueOfNinjasEntities())
     {
         context.Entry(Ninja.ToModel()).State = EntityState.Added;
         context.SaveChanges();
     }
 }
示例#6
0
 private void Edit(object parameter)
 {
     SelectedNinja.Name = NewName;
     SelectedNinja.Gold = Convert.ToInt32(NewGold);
     using (var context = new LeagueOfNinjasEntities())
     {
         context.Entry(SelectedNinja.ToModel()).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#7
0
 private void BuyItem(object parameter)
 {
     using (var context = new LeagueOfNinjasEntities())
     {
         Ninja n = context.Ninjas.Find(NinjaList.SelectedNinja.ToModel().Id);
         Gear  g = context.Gears.Find(SelectedItem.ToModel().Id);
         n.Gears.Add(g);
         n.Gold         -= SelectedItem.Price;
         n.Intelligence += g.Intelligence;
         n.Strength     += g.Strength;
         n.Agility      += g.Agility;
         context.SaveChanges();
     }
     NinjaList.SelectedNinja.AddItem(SelectedItem);
 }
示例#8
0
        private void DeleteItem(object parameter)
        {
            NinjaList.SelectedNinja.RemoveItem(SelectedItem);
            ShopItems.Remove(SelectedItem);

            using (var context = new LeagueOfNinjasEntities())
            {
                context.Entry(NinjaList.SelectedNinja.ToModel()).State = EntityState.Modified;
                context.Entry(SelectedItem.ToModel()).State            = EntityState.Deleted;

                context.SaveChanges();
            }

            TempShopItems.Remove(SelectedItem);
        }