Пример #1
0
        public ActionResult RandomMatch(int id)
        {
            int mId = 0;

            for (int j = 0; j < id; j++)
            {
                var playerToMatch = PlayerToMatch();

                var model   = new MatchCon().CreateMatchViewModel(new CreateMatchViewModel(), playerToMatch);
                var teamone = _fussballRepository.CreateOrGetTeam(model.PlayerOneId, model.PlayerTwoId);
                var teamtwo = _fussballRepository.CreateOrGetTeam(model.PlayerThreeId, model.PlayerFourId);
                _unitOfWork.SaveChanges();

                Match  matchtemp;
                Random random   = new Random();
                int    randomNr = random.Next(0, 2); // creates a number between 0 and 51
                if (randomNr == 0)
                {
                    matchtemp = _fussballRepository.CreateMatch(model.PlayerOneId, model.PlayerTwoId, model.PlayerThreeId, model.PlayerFourId);
                }
                else
                {
                    matchtemp = _fussballRepository.CreateMatch(model.PlayerThreeId, model.PlayerFourId, model.PlayerOneId, model.PlayerTwoId);
                }

                _unitOfWork.SaveChanges();
                var match   = _fussballRepository.GetMatch(matchtemp.Id);
                var dbMatch = new MatchCon().SetResult(match, matchtemp.EndGoalsTeamRed + random.Next(1, 11), matchtemp.EndGoalsTeamBlue + random.Next(1, 11));
                _unitOfWork.SaveChanges();
                mId = match.Id;
            }
            return(RedirectToAction("Result", "MvcMatch", new { id = mId }));
        }
Пример #2
0
        private void Match(CreateMatchViewModel hold, int s1, int s2)
        {
            _unitOfWork.SaveChanges();
            var match = _fussballRepository.CreateMatch(hold.PlayerOneId, hold.PlayerTwoId, hold.PlayerThreeId, hold.PlayerFourId);

            _unitOfWork.SaveChanges();
            var dbmatch      = _fussballRepository.GetMatch(match.Id);
            var dbMatchsaved = new MatchCon().SetResult(dbmatch, s1, s2);

            _unitOfWork.SaveChanges();
        }
Пример #3
0
        public ActionResult CreateMatch(CreateMatchViewModel vm)
        {
            var strList = new List <string> {
                vm.PlayerOne, vm.PlayerTwo, vm.PlayerThree, vm.PlayerFour
            };
            var players       = _fussballRepository.GetPlayers().ToList();
            var playerToMatch = players.Where(item => strList.Contains(item.Initials)).OrderBy(p => p.Score).ThenBy(i => Guid.NewGuid()).ToList();

            if (playerToMatch.Distinct().Count() != 4) // Fail first
            {
                return(View(vm));
            }
            var model = new MatchCon().CreateMatchViewModel(vm, playerToMatch);

            _fussballRepository.CreateOrGetTeam(model.PlayerOneId, model.PlayerTwoId);
            _fussballRepository.CreateOrGetTeam(model.PlayerThreeId, model.PlayerFourId);
            _unitOfWork.Save();

            return(RedirectToAction("Match", model));
        }