public void HeroAppService_UpdateKeyValue_True()
        {
            var validationResult = new ValidationResult();
            var viewModel        = new HeroViewModel()
            {
                HeroName  = "test",
                HeroPrice = 5,
                HeroType  = new HeroTypeViewModel()
                {
                    HeroTypeName = "test"
                }
            };
            var keyValue = new Dictionary <string, string>();

            keyValue.Add("HeroName", "asd");
            keyValue.Add("HeroDeleted", "true");

            var repo = MockRepository.GenerateStub <IHeroRepository>();

            repo.Stub(s => s.GetByName(viewModel.HeroName)).Return(null);

            var repoType = MockRepository.GenerateStub <IHeroTypeRepository>();

            repoType.Stub(s => s.GetByName("test")).Return(new HeroType());

            var appService = new HeroAppService(new HeroService(repo, repoType));

            validationResult.Add(appService.Update(viewModel, keyValue));

            Assert.IsTrue(validationResult.IsValid);
        }
Esempio n. 2
0
        private void NewHeroView(Hero hero)
        {
            HeroViewModel heroViewModel = new HeroViewModel(hero);

            heroViewModel.View.DataContext = hero;
            View.AllHeroesSP.Children.Add(heroViewModel.View);
        }
Esempio n. 3
0
        public void PlayerAppService_BuyHero_True()
        {
            //Arrange
            var player = new PlayerViewModel()
            {
                PlayerName  = "test",
                PlayerMoney = 300
            };

            var hero = new HeroViewModel()
            {
                HeroName  = "test",
                HeroPrice = 24
            };

            //Act
            var repoPlayer = MockRepository.GenerateStub <IPlayerRepository>();

            repoPlayer.Stub(s => s.GetById(player.PlayerId)).Return(Mapper.Map <PlayerViewModel, Player>(player));

            var repoHero = MockRepository.GenerateStub <IHeroRepository>();

            repoHero.Stub(s => s.GetById(hero.HeroId)).Return(Mapper.Map <HeroViewModel, Hero>(hero));

            var repoType = MockRepository.GenerateStub <IHeroTypeRepository>();

            var heroService   = new HeroService(repoHero, repoType);
            var playerService = new PlayerService(repoPlayer, heroService);
            var AppService    = new PlayerAppService(playerService, heroService);

            player.ValidationResult.Add(AppService.BuyHero(player.PlayerId, hero.HeroId));

            Assert.IsTrue(player.ValidationResult.IsValid);
        }
        public void HeroAppService_Add_True()
        {
            var validationResult = new ValidationResult();
            var viewModel        = new HeroViewModel()
            {
                HeroName  = "test",
                HeroPrice = 23,
                HeroType  = new HeroTypeViewModel()
                {
                    HeroTypeName = "test"
                }
            };

            var repo = MockRepository.GenerateStub <IHeroRepository>();

            repo.Stub(s => s.GetByName(viewModel.HeroName)).Return(null);

            var repoType = MockRepository.GenerateStub <IHeroTypeRepository>();

            repoType.Stub(s => s.GetByName(viewModel.HeroType.HeroTypeName)).Return(new HeroType());

            var appService = new HeroAppService(new HeroService(repo, repoType));

            validationResult.Add(appService.Add(viewModel));

            Assert.IsTrue(validationResult.IsValid);
        }
Esempio n. 5
0
        public async Task <IActionResult> Index()
        {
            var home = await DB.Find <Models.Home>().FirstOrDefaultAsync();

            if (home == null)
            {
                return(NotFound());
            }

            var model = new HomeViewModel
            {
                Hero       = HeroViewModel.FromHome(home),
                Components = new List <IViewModel> {
                    new SliderViewModel()
                    {
                        Title = "hello slider"
                    }
                }
            };

            ViewBag.BrowserTitle      = !string.IsNullOrEmpty(home.BrowserTitle) ? home.BrowserTitle : ViewBag.BrowserTitle;
            ViewBag.GoogleDescription = !string.IsNullOrEmpty(home.GoogleDescription) ? home.GoogleDescription : ViewBag.GoogleDescription;
            //ViewBag.FacebookImages = ToAbsoluteUrl(HomeObject.Image.Src);

            // somewhere prepare the HeroViewComponentModel
            //ViewBag.HeroViewComponentModel = HeroViewComponentModel
            return(View(model));
        }
Esempio n. 6
0
        public void PlayerAppService_BuyHero_WithoutMoney_False()
        {
            //Arrange
            var player = new PlayerViewModel()
            {
                PlayerName  = "test",
                PlayerMoney = 23
            };

            var hero = new HeroViewModel()
            {
                HeroName  = "test",
                HeroPrice = 24
            };

            //Act
            var repoPlayer = MockRepository.GenerateStub <IPlayerRepository>();

            repoPlayer.Stub(s => s.GetById(player.PlayerId)).Return(Mapper.Map <PlayerViewModel, Player>(player));

            var repoHero = MockRepository.GenerateStub <IHeroRepository>();

            repoHero.Stub(s => s.GetById(hero.HeroId)).Return(Mapper.Map <HeroViewModel, Hero>(hero));

            var repoType = MockRepository.GenerateStub <IHeroTypeRepository>();

            var heroService   = new HeroService(repoHero, repoType);
            var playerService = new PlayerService(repoPlayer, heroService);
            var AppService    = new PlayerAppService(playerService, heroService);

            player.ValidationResult.Add(AppService.BuyHero(player.PlayerId, hero.HeroId));

            Assert.IsFalse(player.ValidationResult.IsValid);
            Assert.IsTrue(player.ValidationResult.Erros.Any(e => e.Message == "You don't have money to buy this hero. Please chose another"));
        }
Esempio n. 7
0
 public void UpdateProperties()
 {
     RelationToMainHeroText = "";
     GovernorOfText         = "";
     Skills.Clear();
     Traits.Clear();
     UpdateLearningSkillSelection();
     foreach (SkillObject item in SkillObject.All)
     {
         Skills.Add(new EncyclopediaSkillVM(item, _hero.GetSkillValue(item)));
     }
     foreach (TraitObject heroTrait in CampaignUIHelper.GetHeroTraits())
     {
         if (_hero.GetTraitLevel(heroTrait) != 0)
         {
             Traits.Add(new EncyclopediaTraitItemVM(heroTrait, _hero));
         }
     }
     IsChild = _hero.IsChild;
     if (_hero != Hero.MainHero)
     {
         RelationToMainHeroText = CampaignUIHelper.GetHeroRelationToHeroText(_hero, Hero.MainHero).ToString();
     }
     if (_hero.GovernorOf != null)
     {
         GameTexts.SetVariable("SETTLEMENT_NAME", _hero.GovernorOf.Owner.Settlement.EncyclopediaLinkWithName);
         GovernorOfText = GameTexts.FindText("str_governor_of_label").ToString();
     }
     HeroModel = new HeroViewModel();
     HeroModel.FillFrom(_hero);
     Banner_9 = new ImageIdentifierVM(BannerCode.CreateFrom(_hero.ClanBanner), nineGrid: true);
 }
Esempio n. 8
0
        public ActionResult AddHero(HeroViewModel newHeroViewModel, HttpPostedFileBase uploadImage)
        {
            if (ModelState.IsValid && uploadImage != null)
            {
                byte[] imageData;
                // считываем переданный файл в массив байтов
                using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                {
                    imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                }
                // установка массива байтов
                Image newImage = new Image(imageData);
                _imgRep.Add(newImage);

                newHeroViewModel.Id    = Guid.NewGuid();
                newHeroViewModel.Image = newImage;

                // Настройка AutoMapper
                Mapper.Initialize(cfg => cfg.CreateMap <HeroViewModel, Hero>());
                // сопоставление
                Hero newHero = Mapper.Map <HeroViewModel, Hero>(newHeroViewModel);

                _heroRep.Add(newHero);

                return(RedirectToAction("Index"));
            }
            return(View());
        }
Esempio n. 9
0
 public ActionResult Edit(HeroViewModel vmodel)
 {
     if (ModelState.IsValid)
     {
         bool isUniversal = TranslationBL.CheckIfUniversal(vmodel.HeroesTrans);
         db.Entry(vmodel.Hero).State = EntityState.Modified;
         foreach (var item in vmodel.HeroesTrans)
         {
             if (item.nameHero != null)
             {
                 if (isUniversal)
                 {
                     item.languageId      = LanguageBL.FindIdLanguageByShortForm("all");
                     db.Entry(item).State = EntityState.Modified;
                 }
                 else
                 {
                     db.Entry(item).State = EntityState.Modified;
                 }
             }
         }
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(vmodel));
 }
        public ActionResult Hero()
        {
            var viewModel = new HeroViewModel();

            viewModel.LinkData = ControllerHelper.GetLinkData(viewModel.DataSource, ProjConstants.Fields.Hero.Link, ProjConstants.Fields.Hero.LinkTextFallBack);
            return(View(ProjConstants.Views.Hero, viewModel));
        }
Esempio n. 11
0
        public async Task <IActionResult> Put([FromBody] HeroViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var updateHero = await _heroRepository.Get(model.Id.Value);

                if (updateHero == null)
                {
                    return(NotFound());
                }

                updateHero = _mapper.Map <Hero>(model);
                await _heroRepository.Update(updateHero);

                return(Ok(model));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { Msg = ex.Message }));
            }
        }
Esempio n. 12
0
        private void NewHeroView(Hero hero)
        {
            HeroViewModel newHeroViewModel = new HeroViewModel(hero);

            newHeroViewModel.InitEquipView();

            view.Units.Children.Add(newHeroViewModel.View);
        }
Esempio n. 13
0
        public async Task <IActionResult> Post([FromBody] HeroViewModel hero)
        {
            hero.Id = await _heroRepo.Create(new Hero()
            {
                Name = hero.Name
            });

            return(Ok(hero));
        }
Esempio n. 14
0
        // GET: Heroes/Create
        //[Authorize(Roles = "admin")]
        //[Authorize(Roles = "manager")]
        public ActionResult Create()
        {
            HeroViewModel vm = new HeroViewModel
            {
                ListLang = LanguageBL.FindLanguageListWithoutUniversal()
            };

            return(View(vm));
        }
Esempio n. 15
0
        public async Task Put(int id, [FromBody] HeroViewModel model)
        {
            var hero = await _heroRepo.GetById(id);

            if (hero != null)
            {
                hero.Name = model.Name;
                await _heroRepo.Update(id, hero);
            }
        }
Esempio n. 16
0
        // GET: Hero
        public ActionResult Index()
        {
            HeroViewModel model = new HeroViewModel(ImageProviderName, Image)
            {
                Title = Title,
                Body  = Body
            };

            return(View("~/ResourcePackages/Bootstrap/MVC/Views/Hero/Hero.cshtml", model));
        }
Esempio n. 17
0
        public ValidationResult Update(HeroViewModel model)
        {
            var hero = Mapper.Map <HeroViewModel, Hero>(model);

            if (!hero.IsValid())
            {
                return(hero.ValidationResult);
            }

            return(_heroService.Update(hero));
        }
Esempio n. 18
0
        public bool AddHero(HeroViewModel model)
        {
            var hero = new Hero
            {
                Name = model.Name
            };

            Uow.Repository <Hero>().Add(hero);
            Uow.Commit();
            return(true);
        }
Esempio n. 19
0
        public ActionResult EditHero(Guid idHero)
        {
            var editHero = _heroRep.Get(idHero);

            // Настройка AutoMapper
            Mapper.Initialize(cfg => cfg.CreateMap <Hero, HeroViewModel>());
            // сопоставление
            HeroViewModel heroViewModel = Mapper.Map <Hero, HeroViewModel>(editHero);

            return(View(heroViewModel));
        }
Esempio n. 20
0
        private IReadOnlyCollection <HeroViewModel> TranslateToViewModel(IEnumerable <KeyValuePair <uint, HeroDetailModel> > heroes)
        {
            List <HeroViewModel> heroViewModels = new List <HeroViewModel>();

            foreach (var hero in heroes)
            {
                HeroViewModel heroViewModel = AutoMapperConfiguration.Mapper.Map <HeroDetailModel, HeroViewModel>(hero.Value);
                heroViewModels.Add(heroViewModel);
            }

            return(heroViewModels);
        }
Esempio n. 21
0
 public ActionResult UpdateHero(HeroViewModel heroViewModel)
 {
     if (Session["RoleID"] != null)
     {
         HeroDataAccess.UpdateHero(Mapper.HeroMap(heroViewModel.SingleHero));
         return(RedirectToAction("ViewHeroes"));
     }
     else
     {
         return(RedirectToAction("ViewHeroes"));
     }
 }
Esempio n. 22
0
 public ActionResult UpdateHero(int HeroID)
 {
     if (Session["RoleID"] != null)
     {
         HeroViewModel heroViewModel = new HeroViewModel();
         heroViewModel.SingleHero = Mapper.HeroMap(HeroDataAccess.GetHeroByID(HeroID));
         return(View(heroViewModel));
     }
     else
     {
         return(RedirectToAction("ViewHeroes"));
     }
 }
Esempio n. 23
0
 //VIEW HEROES
 public ActionResult ViewHeroes()
 {
     if (Session["RoleID"] != null)
     {
         HeroViewModel viewModel = new HeroViewModel();
         viewModel.HeroList = Mapper.HeroMap(HeroDataAccess.GetAllHeroes());
         return(View(viewModel));
     }
     else
     {
         return(RedirectToAction("Login"));
     }
 }
Esempio n. 24
0
        public WangLordItemVM(Hero hero, Action <WangLordItemVM> onCharacterSelect)
        {
            _hero = hero;
            _onCharacterSelect = onCharacterSelect;
            CharacterCode characterCode = CharacterCode.CreateFrom(hero.CharacterObject);

            Visual    = new ImageIdentifierVM(characterCode);
            Skills    = new MBBindingList <EncyclopediaSkillVM>();
            Traits    = new MBBindingList <EncyclopediaTraitItemVM>();
            Banner_9  = new ImageIdentifierVM(BannerCode.CreateFrom(hero.ClanBanner), nineGrid: true);
            HeroModel = new HeroViewModel();
            HeroModel.FillFrom(_hero);
            RefreshValues();
        }
Esempio n. 25
0
        public BattlefieldViewModel(CMap map, CHeroBase hero, IGameServiceProvider provider)
        {
            _provider      = provider;
            MyHero         = hero;
            Map            = map;
            MoveCommand    = new CRelayCommand(MoveCommandExecuted);
            TradeCommand   = new CRelayCommand(TradeCommandExecuted, TradeCanExecute);
            BattleCommand  = new CRelayCommand(BattleExecute, BattleCanExecute);
            UseItemCommand = new CRelayCommand(UseItemExecute, UseItemCanExecute);

            provider.ServiceCallback.HeroMoved += OnHeroMoved;
            provider.ServiceCallback.UnitDied  += OnUnitDied;
            MyHeroViewModel = new HeroViewModel(hero);
        }
Esempio n. 26
0
        public void Constructor_initialize_properties_correctly(Hero hero)
        {
            //Arrange
            HeroViewModel sut = default;

            //Act
            sut = new HeroViewModel(hero);

            //Assert
            sut.HeroName.Should().Be(hero.HeroName);
            sut.HeroName_ko.Should().Be(hero.HeroName_ko);
            sut.RealName.Should().Be(hero.RealName);
            sut.Comment.Should().Be(hero.Summary);
            sut.Role.Should().Be(hero.Role);
            sut.SignatureColor.Should().Be(hero.SignatureColor_Hex);
        }
Esempio n. 27
0
        public override void OnNavigated(Object data)
        {
            if (!(data is CBattleNavigationData navigationData))
            {
                return;
            }

            MyHero           = navigationData.MyHero;
            Opponent         = navigationData.Opponent;
            Provider         = navigationData.Provider;
            OpponentPosition = navigationData.Position;
            HeroImage        = CUnitTextureFactory.GetTexture(MyHero);
            OpponentImage    = CUnitTextureFactory.GetTexture(Opponent as IPositionable);
            Weapons          = new ObservableCollection <IDamaging>(MyHero.Inventory.OfType <IDamaging>());
            HeroViewModel    = new HeroViewModel(MyHero);
            Update();
        }
Esempio n. 28
0
        public ValidationResult Update(HeroViewModel model, Dictionary <string, string> keyValue)
        {
            model.ValidationResult = _heroService.ValidateModel(model, keyValue);
            if (!model.ValidationResult.IsValid)
            {
                return(model.ValidationResult);
            }

            var hero = SetValues(Mapper.Map <HeroViewModel, Hero>(model), keyValue);

            if (hero.IsValid())
            {
                return(_heroService.Update(hero));
            }

            return(hero.ValidationResult);
        }
Esempio n. 29
0
        public ActionResult Details(Guid idHero)
        {
            var hero = _heroRep.Get(idHero);

            // Настройка AutoMapper
            Mapper.Initialize(cfg => cfg.CreateMap <Hero, HeroViewModel>());
            // сопоставление
            HeroViewModel heroViewModel = Mapper.Map <Hero, HeroViewModel>(hero);

            LevelSystem level = new LevelSystem(heroViewModel.XP);

            heroViewModel.MinXP       = (int)level.MinXP;
            heroViewModel.MaxXP       = (int)level.MaxXP;
            heroViewModel.XPinPercent = (int)level.XPinPercent;

            return(View(heroViewModel));
        }
Esempio n. 30
0
        public InventorySetViewModel(Hero hero)
        {
            this.Hero = hero;
            this.View = new InventorySetPopUp();
            HeroViewModel newHeroViewModel = new HeroViewModel(this.Hero);

            newHeroViewModel.View.InventoryHeroButton.Visibility = System.Windows.Visibility.Collapsed;
            this.HeroView                     = newHeroViewModel.View;
            this.HeroView.Height              = this.View.Grid.Height - 100;
            this.HeroView.HeroImage.Height    = 150;
            this.HeroView.ButtonSP.Visibility = System.Windows.Visibility.Collapsed;
            this.View.HeroViewSP.Children.Add(HeroView);

            EquipmentListing EquipmentListing = new EquipmentListing();

            EquipmentListing.Controller.initEquipView(hero);
            this.view.allObjectSP.Children.Add(EquipmentListing);
        }