Exemplo n.º 1
0
        public IWindow ResolveWindow()
        {
            ConnectionProperties connectionProperties = new ConnectionProperties();
            RestClient           restClient           = new RestClient(connectionProperties);
            ConverterJson        converterJson        = new ConverterJson();

            IUserDao          userDao          = new UserDao(restClient, converterJson);
            IPlayerDao        playerDao        = new PlayerDao(restClient, converterJson);
            IFactionDao       factionDao       = new FactionDao(restClient, converterJson);
            IFactionPlayerDao factionPlayerDao = new FactionPlayerDao(restClient, converterJson);
            //Mapper mapper = new Mapper();
            Converter <Player, PlayerDto> playerConverter = new PlayerConverter();

            IUserService          userService          = new UserService(userDao);
            IPlayerService        playerService        = new PlayerService(playerDao);
            IFactionService       factionService       = new FactionService(factionDao);
            IFactionPlayerService factionPlayerService = new FactionPlayerService(factionPlayerDao);

            IVMFacade        vmFacade        = new VMFacade(factionPlayerService, factionService, playerService);
            IPlayerVmFacade  playerVmFacade  = new PlayerVmFacade(factionPlayerService, factionService, playerService);
            IFactionVmFacade factionVmFacade = new FactionVmFacade(factionPlayerService, factionService, playerService);

            IUserViewModel    userViewModel    = new UserViewModel(vmFacade, userService);
            IPlayerViewModel  playerViewModel  = new PlayerViewModel(playerVmFacade);
            IFactionViewModel factionViewModel = new FactionViewModel(factionVmFacade);
            IMainViewModel    mainViewModel    = new MainViewModel(connectionProperties, playerViewModel, factionViewModel, userViewModel);
            ViewModelFactory  vmFactory        = new ViewModelFactory(mainViewModel);

            Window main = new Main();

            _window = new MainWindowAdapter(main, vmFactory);
            //vmFactory.CreatePlayerVM(_window);
            return(_window);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(FactionViewModel viewModel)
        {
            viewModel.StatusMessage = string.Empty;
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            if (await _db.Factions.AnyAsync(f => f.Name == viewModel.Faction.Name))
            {
                viewModel.StatusMessage = "Error: A faction with that name already exists in the database.";
                return(View(viewModel));
            }

            Faction factionFromDB = await _db.Factions.FindAsync(viewModel.Faction.Id);

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

            List <BattleReport> battleReports = await _db.BattleReports.Where(br => br.PostersFaction == factionFromDB.Name || br.OpponentsFaction == factionFromDB.Name).ToListAsync();

            foreach (BattleReport battleReport in battleReports)
            {
                if (battleReport.PostersFaction == factionFromDB.Name)
                {
                    battleReport.PostersFaction = viewModel.Faction.Name;
                }
                if (battleReport.OpponentsFaction == factionFromDB.Name)
                {
                    battleReport.OpponentsFaction = viewModel.Faction.Name;
                }
                if (battleReport.WinningFaction == factionFromDB.Name)
                {
                    battleReport.WinningFaction = viewModel.Faction.Name;
                }
                if (battleReport.LosingFaction == factionFromDB.Name)
                {
                    battleReport.LosingFaction = viewModel.Faction.Name;
                }
            }

            factionFromDB.Name = viewModel.Faction.Name;

            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(FactionViewModel viewModel)
        {
            viewModel.StatusMessage = string.Empty;
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            if (await _db.Factions.AnyAsync(f => f.Name == viewModel.Faction.Name))
            {
                viewModel.StatusMessage = "Error: A faction with that name already exists in the database.";
                return(View(viewModel));
            }

            _db.Factions.Add(viewModel.Faction);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Faction factionFromDB = await _db.Factions.FindAsync(id);

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

            FactionViewModel viewModel = new FactionViewModel()
            {
                Faction = factionFromDB
            };

            return(View(viewModel));
        }