Exemple #1
0
 public void AddSelectedEquipToNinja()
 {
     //Check if the budget is high enough, if false a message will be shown
     if (NinjaViewModel.BugetIsHighEnough(SelectedEquip.ToEntity()))
     {
         //Check if the ninja already has equips
         if (NinjaViewModel.Equips != null)
         {
             var oldCategoryEquip = NinjaViewModel.Equips
                                    .Where(src => src.CategoryId.Equals(SelectedEquip.CategoryId))
                                    .FirstOrDefault();
             //Check if the selected equip was not added yet
             if (oldCategoryEquip != null)
             {
                 //Remove the previously added equip with the same category
                 NinjaViewModel.RemoveEquipment(oldCategoryEquip);
             }
         }
         NinjaViewModel.AddEquipment(SelectedEquip.ToEntity());
         ReloadEquipment();
         RaisePropertyChanged(() => NinjaViewModel);
         RaisePropertyChanged(() => IsCreateEnabled);
         RaisePropertyChanged(() => IsClearEnabled);
     }
 }
Exemple #2
0
        public ShopViewModel(IGenericRepository <Category> categoryRepository, IGenericRepository <Equip> equipRepository, IGenericRepository <Ninja> ninjaRepository, IGenericRepository <NinjaEquip> ninjaEquipRepository)
        {
            _categoryRepository   = categoryRepository;
            _equipRepository      = equipRepository;
            _ninjaRepository      = ninjaRepository;
            _ninjaEquipRepository = ninjaEquipRepository;

            Categories     = new ObservableCollection <CategoryViewModel>(_categoryRepository.GetAll().Select(c => new CategoryViewModel(c)));
            Equipment      = new ObservableCollection <EquipViewModel>(_equipRepository.GetAll().Select(e => new EquipViewModel(e)));
            AllNinjas      = new ObservableCollection <NinjaViewModel>(_ninjaRepository.GetAll().Select(n => new NinjaViewModel(n)));
            NinjaViewModel = new NinjaViewModel();

            BuyEquip    = new RelayCommand(AddSelectedEquipToNinja);
            CreateNinja = new RelayCommand(SaveNewNinja);
            SaveNinja   = new RelayCommand(SaveCurrentNinja);
            LoadNinja   = new RelayCommand(LoadCurrentNinja);
            ClearNinja  = new RelayCommand(ClearCurrentNinja);
            NewNinja    = new RelayCommand(NewNinjaModel);
        }