Пример #1
0
        public async Task <ResponseObject> AddMatch(Tournament tournament, Match match, int phase)
        {
            if (phase <= 0)
            {
                phase = 1;
            }
            MatchDAO    matchDAO   = new MatchDAO(match, phase);
            HttpContent putContent = new StringContent(JObject.FromObject(matchDAO).ToString());

            putContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var wc       = new AuthHttpClient();
            var response = await wc.PostAsync(ApiAccess.GetMatchUrl(tournament.Id, match.Id), putContent);

            ResponseObject contentResponse = new ResponseObject();
            String         jstr            = response.Content.ReadAsStringAsync().Result;

            if (response.StatusCode == HttpStatusCode.Created)
            {
                contentResponse.Content = JObject.Parse(jstr);
                contentResponse.Success = true;
            }
            else
            {
                contentResponse.Content = JArray.Parse(jstr);
                contentResponse.Success = false;
            }
            return(contentResponse);
        }
Пример #2
0
        public async Task <ResponseObject> AddClub(Club club)
        {
            HttpContent postContent = new StringContent(JObject.FromObject(club).ToString());

            postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var wc       = new AuthHttpClient();
            var response = await wc.PostAsync(new Uri(ApiAccess.ClubUrl), postContent);

            return(GetResponseService.TraiteResponse(response, new ClubDAO(), false));
        }
Пример #3
0
        public async Task <ResponseObject> AddTournamentAsync(Tournament tournament)
        {
            TournamentListDAO tournamentListDAO = new TournamentListDAO(tournament);
            HttpContent       postContent       = new StringContent(JObject.FromObject(tournamentListDAO).ToString());

            postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var wc       = new AuthHttpClient();
            var response = await wc.PostAsync(new Uri(ApiAccess.TournamentUrl), postContent);

            return(GetResponseService.TraiteResponse(response, new TournamentDAO(), false));
        }
Пример #4
0
        public async Task <ResponseObject> LogIn(String username, String password)
        {
            LogInDAO infoLogin = new LogInDAO(username, password);

            HttpContent postContent = new StringContent(JObject.FromObject(infoLogin).ToString());

            postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var wc       = new AuthHttpClient();
            var response = await wc.PostAsync(new Uri(ApiAccess.LogInUrl), postContent);

            ResponseObject responseO = GetResponseService.TraiteResponse(response, new LoginResponseDAO(), false);

            if (responseO.Success)
            {
                ApiAccess.Instance.Token = ((LoginResponseDAO)responseO.Content).AccessToken;
            }
            return(responseO);
        }
Пример #5
0
        public async Task <bool> AddUser(User user)
        {
            HttpContent postContent = new StringContent(JObject.FromObject(user).ToString());

            postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var wc = new AuthHttpClient();

            try
            {
                var response = await wc.PostAsync(await ApiAccess.GetRessource(ApiAccess.URL.USERS), postContent);

                GetResponseService.TraiteResponse(response, new UserDAO(), false);
                return(true);
            }
            catch (HttpRequestException)
            {
                throw new GetDataException();
            }
        }
Пример #6
0
        public async Task <bool> AddPointMatch(long matchId, Point point)
        {
            HttpContent putContent = new StringContent(JObject.FromObject(point).ToString());

            putContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var wc = new AuthHttpClient();

            try
            {
                var response = await wc.PostAsync(await ApiAccess.GetRessource(ApiAccess.URL.POINTS, matchId), putContent);

                GetResponseService.HandleResponse(response, null, false);
                return(true);
            }
            catch (HttpRequestException)
            {
                throw new GetDataException();
            }
        }
Пример #7
0
        public async Task <bool> AddTournamentAsync(Tournament tournament)
        {
            TournamentListDAO tournamentListDAO = new TournamentListDAO(tournament);
            HttpContent       postContent       = new StringContent(JObject.FromObject(tournamentListDAO).ToString());

            postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var wc = new AuthHttpClient();

            try
            {
                var response = await wc.PostAsync(await ApiAccess.GetRessource(ApiAccess.URL.TOURNAMENTS), postContent);

                GetResponseService.HandleResponse(response, new TournamentDAO(), false);
                return(true);
            }
            catch (HttpRequestException)
            {
                throw new GetDataException();
            }
        }
Пример #8
0
        public async Task <bool> LogIn(String username, String password)
        {
            LogInDAO infoLogin = new LogInDAO(username, password);

            HttpContent postContent = new StringContent(JObject.FromObject(infoLogin).ToString());

            postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var wc = new AuthHttpClient();

            try
            {
                var response = await wc.PostAsync(await ApiAccess.GetRessource(ApiAccess.URL.LOGIN), postContent);

                LoginResponseDAO responseO = (LoginResponseDAO)GetResponseService.TraiteResponse(response, new LoginResponseDAO(), false);
                AuthHttpClient.Token = responseO.AccessToken;
            }
            catch (HttpRequestException)
            {
                throw new GetDataException();
            }

            return(true);
        }
Пример #9
0
        public async Task <ResponseObject> AddPointMatch(long matchId, Point point)
        {
            HttpContent putContent = new StringContent(JObject.FromObject(point).ToString());

            putContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var wc       = new AuthHttpClient();
            var response = await wc.PostAsync(ApiAccess.GetMatchPointUrl(matchId), putContent);

            ResponseObject contentResponse = new ResponseObject();
            String         jstr            = response.Content.ReadAsStringAsync().Result;

            if (response.StatusCode == HttpStatusCode.Created)
            {
                contentResponse.Content = JObject.Parse(jstr);
                contentResponse.Success = true;
            }
            else
            {
                contentResponse.Content = JArray.Parse(jstr);
                contentResponse.Success = false;
            }
            return(contentResponse);
        }
Пример #10
0
        public async Task <bool> AddMatch(Tournament tournament, Match match, int phase)
        {
            if (phase <= 0)
            {
                phase = 1;
            }
            MatchDAO    matchDAO   = new MatchDAO(match, phase);
            HttpContent putContent = new StringContent(JObject.FromObject(matchDAO).ToString());

            putContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var wc = new AuthHttpClient();

            try
            {
                var response = await wc.PostAsync(await ApiAccess.GetRessource(ApiAccess.URL.MATCHS, tournament.Id, match.Id), putContent);

                GetResponseService.HandleResponse(response, null, false);
                return(true);
            }
            catch (HttpRequestException)
            {
                throw new GetDataException();
            }
        }