Пример #1
0
        public Response <bool> AddUserMatch(string userId, string matchId)
        {
            var  response = new Response <bool>();
            Guid id       = Guid.NewGuid();

            var userMatch = new UserMatches
            {
                UserId  = userId,
                MatchId = matchId,
                Id      = id.ToString()
            };

            try
            {
                var result      = _umRepository.Add(userMatch);
                var updateMatch = _repository.Find(x => x.Id == matchId).FirstOrDefault();
                updateMatch.CurrentPlayers++;
                _repository.Update(updateMatch);
                _logger.LogInfo("new player added to match");
                response.Payload = true;
                response.Status  = System.Net.HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                _logger.LogError("join player to match failed");
                response.Messages.Add(new ResponseMessage
                {
                    Type    = Contracts.Enums.ResponseMessageEnum.Exception,
                    Message = ex.Message,
                });
                response.Status = System.Net.HttpStatusCode.InternalServerError;
            }
            return(response);
        }
Пример #2
0
        public async Task <UserMatches> GetUserMatchesAsync(string name)
        {
            string path = _configuration["Pubg:ApiRoot"] + $"players?filter[playerNames]={name}";

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(path);
                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer", _configuration["Pubg:ApiToken"]);
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                UserMatches         user     = null;
                HttpResponseMessage response = await client.GetAsync(path);

                if (response.IsSuccessStatusCode)
                {
                    user = await response.Content.ReadAsAsync <UserMatches>();
                }
                return(user);
            }
        }
Пример #3
0
        public List <Matches> GetAllMatches(DataStore datastore)
        {
            var matchesId = UserMatches.Select(x => x.MatchId).ToList();

            return(datastore.db.Matches.Where(x => matchesId.Contains(x.Id)).ToList());
        }