Exemple #1
0
        public async Task <IHttpActionResult> CreateMatch(int warId)
        {
            if (!await IsValidWarId(warId))
            {
                return(NotFound());
            }

            if (await _contestantRepository.GetCount(warId) < 2)
            {
                return(Conflict());
            }

            var user = _mapper.Map <ClaimsPrincipal, War.Users.User>(User as ClaimsPrincipal);
            await _userRepository.Upsert(user);

            var match = await _matchFactory.Create(warId, user.Id);

            var matchModel = _mapper.Map <MatchWithContestants, Models.Match>(match);

            return(Created("", matchModel));
        }
        public async Task <MatchWithContestants> Create(int warId, UserIdentifier userId)
        {
            var contestantCount = await _contestantRepository.GetCount(warId);

            var contestant1Index = _generateRandomNumber(0, contestantCount);
            var contestant2Index = GetContestant2Index(contestantCount, contestant1Index);

            var contestant1 = await _contestantRepository.Get(warId, contestant1Index);

            var contestant2 = await _contestantRepository.Get(warId, contestant2Index);

            Guid matchId = await CreateMatch(warId, contestant1, contestant2, userId);

            var result = new MatchWithContestants
            {
                Contestant1 = contestant1,
                Contestant2 = contestant2,
                Id          = matchId
            };

            return(result);
        }