예제 #1
0
 private static void SetHttpServiceResult <Type>(HttpServiceResult <Type> hts, HttpResponseMessage response)
 {
     if ((response != null) && (response.IsSuccessStatusCode))
     {
         string json = response.Content.ReadAsStringAsync().Result;
         hts.ResultData = JsonConvert.DeserializeObject <Type>(json);
     }
     else
     {
         hts.IsError = true;
         string  json   = response.Content.ReadAsStringAsync().Result;
         dynamic result = JsonConvert.DeserializeObject(json);
         if (result["error_description"] != null)
         {
             hts.ErrorMessage = result["error_description"];
         }
         else if (result["error"] != null)
         {
             hts.ErrorMessage = result["error"];
         }
         else if (result["ErrorMessage"] != null)
         {
             hts.ErrorMessage = result["ErrorMessage"];
         }
         else if (result["Message"] != null)
         {
             hts.ErrorMessage = result["Message"];
         }
         else
         {
             hts.ErrorMessage = "不明なエラーが発生しました。";
         }
     }
 }
예제 #2
0
        public static async Task <string> CreateUser(User newUser, string password, string confirmationPassword)
        {
            Dictionary <string, string> contents = new Dictionary <string, string>
            {
                { "PUserName", newUser.PUserName },
                { "Email", newUser.Email },
                { "Password", password },
                { "ConfirmPassword", confirmationPassword },
                { "TwitterAccount", newUser.TwitterAccount }
            };

            HttpServiceResult <dynamic> hsr = await HttpService.PostDataFromServiceWithToken <dynamic>("api/account/register", contents);

            if (!hsr.IsError)
            {
                SetLoginUserEmail(newUser.Email);
                await Login(password);

                IsLogin = true;
                return("");
            }
            else
            {
                return(hsr.ErrorMessage);
            }
        }
예제 #3
0
        public static async Task <HttpServiceResult <Type> > GetDataFromService <Type>(string queryString)
        {
            HttpServiceResult <Type> hts = new HttpServiceResult <Type>();
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(BaseUrl + queryString);

            SetHttpServiceResult(hts, response);
            return(hts);
        }
예제 #4
0
        public static async Task <HttpServiceResult <Type> > PostDataFromService <Type>(string queryString, Dictionary <string, string> contents)
        {
            HttpServiceResult <Type> hts = new HttpServiceResult <Type>();
            HttpClient          client   = new HttpClient();
            var                 iparams  = new FormUrlEncodedContent(contents);
            HttpResponseMessage response = await client.PostAsync(BaseUrl + queryString, iparams);

            SetHttpServiceResult(hts, response);
            return(hts);
        }
예제 #5
0
        public static async Task <HttpServiceResult <Type> > GetDataFromServiceWithToken <Type>(string queryString)
        {
            HttpServiceResult <Type> hts = new HttpServiceResult <Type>();
            HttpClient client            = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", UserController.GetLoginUserToken());
            HttpResponseMessage response = await client.GetAsync(BaseUrl + queryString);

            SetHttpServiceResult(hts, response);
            return(hts);
        }
예제 #6
0
        public static async Task <HttpServiceResult <Type> > PutDataFromServiceWithToken <Type>(string queryString, Dictionary <string, string> contents)
        {
            HttpServiceResult <Type> hts = new HttpServiceResult <Type>();
            HttpClient client            = new HttpClient();
            var        iparams           = new FormUrlEncodedContent(contents);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", UserController.GetLoginUserToken());
            HttpResponseMessage response = await client.PutAsync(BaseUrl + queryString, iparams);

            SetHttpServiceResult(hts, response);
            return(hts);
        }
예제 #7
0
        public static async Task <HttpServiceResult <Type> > PostDataFromService <Type>(string url, Dictionary <string, string> contents, string authHeader)
        {
            HttpServiceResult <Type> hts = new HttpServiceResult <Type>();
            HttpClient client            = new HttpClient();
            var        iparams           = new FormUrlEncodedContent(contents);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeader);
            HttpResponseMessage response = await client.PostAsync(url, iparams);

            SetHttpServiceResult(hts, response);
            return(hts);
        }
예제 #8
0
        public static async Task <ObservableCollection <EventDetailView> > GetEventDetail(int eventId)
        {
            HttpServiceResult <ObservableCollection <EventDetailView> > hsr = await HttpService.GetDataFromService <ObservableCollection <EventDetailView> >("api/eventdetailview/geteventpubs?id=" + eventId + "&apptype=1");

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #9
0
        public static async Task <ObservableCollection <EventDetailView> > GetRecommendedEventDetail()
        {
            HttpServiceResult <ObservableCollection <EventDetailView> > hsr = await HttpService.GetDataFromService <ObservableCollection <EventDetailView> >("api/eventdetailview?apptype=1");

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #10
0
        public static async Task <ObservableCollection <WinPubView> > GetWinPubs()
        {
            HttpServiceResult <ObservableCollection <WinPubView> > hsr = await HttpService.GetDataFromServiceWithToken <ObservableCollection <WinPubView> >("api/winpubs/getwinpubs?eventid=" + UserController.LoginUser.EventId);

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #11
0
        public static async Task <ObservableCollection <EventUserCountView> > GetEventUserCount(int eventId)
        {
            HttpServiceResult <ObservableCollection <EventUserCountView> > hsr = await HttpService.GetDataFromService <ObservableCollection <EventUserCountView> >("api/EventUserCount/" + eventId);

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #12
0
        /// <summary>
        /// ユーザのトランザクションの履歴を取得する
        /// </summary>
        /// <returns>The app accounts.</returns>
        public static async Task <ObservableCollection <Transaction> > GetTransactionHistory()
        {
            HttpServiceResult <ObservableCollection <Transaction> > hsr = await HttpService.GetDataFromServiceWithToken <ObservableCollection <Transaction> >("api/appaccounts/getappaccounts");

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #13
0
        /// <summary>
        /// ユーザ情報の取得
        /// </summary>
        /// <returns>The user infos.</returns>
        public static async Task <string> GetUserInfos()
        {
            HttpServiceResult <User> hsr = await HttpService.GetDataFromServiceWithToken <User>("api/account/userinfoall");

            if (!hsr.IsError)
            {
                LoginUser = hsr.ResultData;
                return("");
            }
            else
            {
                return(hsr.ErrorMessage);
            }
        }
예제 #14
0
        /// <summary>
        /// Gets the user accounts.
        /// </summary>
        /// <returns>The user accounts.</returns>
        public static async Task <string> GetUserAccounts()
        {
            HttpServiceResult <Account> hsr = await HttpService.GetDataFromServiceWithToken <Account>("api/accounts/getaccount");

            if (!hsr.IsError)
            {
                LoginUserAccount = hsr.ResultData;
                return("");
            }
            else
            {
                return(hsr.ErrorMessage);
            }
        }
예제 #15
0
        public static async Task <ObservableCollection <Item> > GetCategoryItems(int pubId, int categoryId)
        {
            HttpServiceResult <ObservableCollection <Item> > hsr =
                await HttpService.GetDataFromServiceWithToken <ObservableCollection <Item> >
                    ("api/items/getitem?pubid=" + pubId + "&categoryid=" + categoryId);

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #16
0
        public static async Task <ObservableCollection <EventView> > GetParticipatedEventsOfEnd(int pubId)
        {
            HttpServiceResult <ObservableCollection <EventView> > hsr =
                await HttpService.GetDataFromServiceWithToken <ObservableCollection <EventView> >
                    ("api/events/GetEventsWithType?type=3&apptype=1&pubid=" + pubId);

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #17
0
        public static async Task <string> GetStepPoint()
        {
            HttpServiceResult <string> hsr =
                await HttpService.GetDataFromServiceWithToken <string>
                    ("api/steppoint/getstepareapoint?point=" + stepManger.GetStepPoints());

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #18
0
        public static async Task <ObservableCollection <Pub> > GetPubsInTargetScope(double baselatitude, double baselongitude, double distance, DateTime targetDateTime)
        {
            HttpServiceResult <ObservableCollection <Pub> > hsr =
                await HttpService.GetDataFromService <ObservableCollection <Pub> >
                    ("api/pubs/getpubs?baselatitude=" + baselatitude + "&baselongitude=" + baselongitude + "&distance=" + distance + "&targetDateTime=" + targetDateTime + "&apptype=1");

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #19
0
        public static async Task <ObservableCollection <PubView> > GetUserPubs()
        {
            HttpServiceResult <ObservableCollection <PubView> > hsr =
                await HttpService.GetDataFromServiceWithToken <ObservableCollection <PubView> >
                    ("api/userpubs/getuserpub?userid=" + LoginUser.Id + "&apptype=1");

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #20
0
        public static async Task <ObservableCollection <EventView> > GetAllNotStartedEvents()
        {
            HttpServiceResult <ObservableCollection <EventView> > hsr =
                await HttpService.GetDataFromServiceWithToken <ObservableCollection <EventView> >
                    ("api/events/GetEventsWithType?type=4&apptype=1");

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #21
0
        public static async Task <ObservableCollection <Category> > GetCategories(int pubId)
        {
            HttpServiceResult <ObservableCollection <Category> > hsr =
                await HttpService.GetDataFromServiceWithToken <ObservableCollection <Category> >
                    ("api/categories/getcateogry?pubid=" + pubId);

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #22
0
        public async Task <HttpServiceResult <T> > Get <T>(string url, Dictionary <string, string>?queryParams = null) where T : class, IServiceResult
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException(nameof(url));
            }

            var serviceResult = new HttpServiceResult <T>();

            try
            {
                url = BuildQueryParams(queryParams, url);

                var request = new HttpRequestMessage(HttpMethod.Get, url);
                using var res = await httpClient.SendAsync(request);

                if (res.IsSuccessStatusCode)
                {
                    serviceResult.IsSucess = true;
                    serviceResult.Result   = await res.Content.ReadFromJsonAsync <T>();
                }
                else
                {
                    serviceResult.IsSucess = false;
                    serviceResult.Error    = await res.Content.ReadFromJsonAsync <HttpServiceError>();
                }

                return(serviceResult);
            }
            catch (Exception e)
            {
                logger.LogError(e, e.Message);
                serviceResult.IsSucess = false;
                serviceResult.Error    = new HttpServiceError()
                {
                    StatusMessage = "Exception occured. Check the logs",
                    StatusCode    = 500
                };

                return(serviceResult);
            }
        }
예제 #23
0
        public static async Task <string> ChangePassword(string oldPassword, string newPassword, string confirmationPassword)
        {
            Dictionary <string, string> contents = new Dictionary <string, string>
            {
                { "OldPassword", oldPassword },
                { "NewPassword", newPassword },
                { "ConfirmPassword", confirmationPassword },
            };

            HttpServiceResult <dynamic> hsr = await HttpService.PostDataFromServiceWithToken <dynamic>("api/account/ChangePassword", contents);

            if (!hsr.IsError)
            {
                return("");
            }
            else
            {
                return(hsr.ErrorMessage);
            }
        }
예제 #24
0
        public static async Task <string> ChangeUser(User targetUser)
        {
            Dictionary <string, string> contents = new Dictionary <string, string>
            {
                { "Id", targetUser.Id },
                { "PUserName", targetUser.PUserName },
                { "Email", targetUser.Email },
                { "TwitterAccount", targetUser.TwitterAccount }
            };

            HttpServiceResult <dynamic> hsr = await HttpService.PutDataFromServiceWithToken <dynamic>("api/aspnetusers/" + targetUser.Id, contents);

            if (!hsr.IsError)
            {
                return("");
            }
            else
            {
                return(hsr.ErrorMessage);
            }
        }
예제 #25
0
        /// <summary>
        /// Gets the event tweet. todo:since_id = "+max_id+"&
        /// </summary>
        /// <returns>The event tweet.</returns>
        public async static Task <string> GetTweets(string keyword)
        {
            /*
             * HttpServiceResult<dynamic> hsr;
             * if(String.IsNullOrEmpty(maxid)) hsr = await HttpService.GetTwitterDataFromServiceWithToken<dynamic>(baseUrl + "1.1/search/tweets.json?q=kirin&result_type=recent&include_entities=true");
             * else hsr = await HttpService.GetTwitterDataFromServiceWithToken<dynamic>(baseUrl + "1.1/search/tweets.json?q=kirin&result_type=recent&include_entities=true&since_id=" + maxid);
             */
            var encodedKeyword = WebUtility.UrlEncode("#" + keyword);
            HttpServiceResult <dynamic> hsr = await HttpService.GetTwitterDataFromServiceWithToken <dynamic>(baseUrl + "1.1/search/tweets.json?q=" + encodedKeyword + "&result_type=recent&include_entities=true");

            if (!hsr.IsError)
            {
                tweetStatuses = hsr.ResultData["statuses"];
                //maxid = tweetStatuses[0]["id"];
                return("");
            }
            else
            {
                return(hsr.ErrorMessage);
            }
        }
예제 #26
0
        public static async Task <EventUserView> ApplyEvent(int eventId, int pubId, string appType)
        {
            Dictionary <string, string> contents = new Dictionary <string, string>
            {
                { "EventId", eventId.ToString() },
                { "PubId", pubId.ToString() },
                { "UserId", UserController.LoginUser.Id },
                { "AppType", appType },
                { "CreateDateTime", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") }
            };

            HttpServiceResult <EventUserView> hsr = await HttpService.PostDataFromServiceWithToken <EventUserView>("api/EventUsers", contents);

            if (!hsr.IsError)
            {
                return(hsr.ResultData);
            }
            else
            {
                return(null);
            }
        }
예제 #27
0
        /// <summary>
        /// ログイン
        /// </summary>
        /// <returns>The login.</returns>
        /// <param name="password">Password.</param>
        public static async Task <string> Login(string password)
        {
            Dictionary <string, string> contents = new Dictionary <string, string>
            {
                { "grant_type", "password" },
                { "username", LoginUser.Email },
                { "password", password }
            };

            HttpServiceResult <dynamic> hsr = await HttpService.PostDataFromService <dynamic>("token", contents);

            if (!hsr.IsError)
            {
                LoginToken = hsr.ResultData["access_token"];
                IsLogin    = true;
                return("");
            }
            else
            {
                return(hsr.ErrorMessage);
            }
        }
예제 #28
0
        //private static string maxid = "";

        public static async Task <string> SetToken()
        {
            string authUrl = baseUrl + "oauth2/token";

            Dictionary <string, string> contents = new Dictionary <string, string>
            {
                { "grant_type", "client_credentials" }
            };

            byte[] bytes        = System.Text.Encoding.UTF8.GetBytes(consumerKey + ":" + consumerSecret);
            string base64string = System.Convert.ToBase64String(bytes);

            HttpServiceResult <dynamic> hsr = await HttpService.PostDataFromService <dynamic>(authUrl, contents, base64string);

            if (!hsr.IsError)
            {
                token = hsr.ResultData["access_token"];
                return("");
            }
            else
            {
                return(hsr.ErrorMessage);
            }
        }
예제 #29
0
        public static async Task <string> PayToPub(int toPubId, long toCash)
        {
            Dictionary <string, string> contents = new Dictionary <string, string>
            {
                { "ToUserType", ((int)CommonDef.UserType.Pub).ToString() },
                { "ToUserId", "-1" },
                { "ToPubId", toPubId.ToString() },
                { "ToAccountId", "-1" },
                { "Cash", toCash.ToString() },
                { "Category", ((int)CommonDef.AppAccountCategory.Pub).ToString() },
                { "FromPubId", "-1" }
            };

            HttpServiceResult <dynamic> hsr = await HttpService.PostDataFromServiceWithToken <dynamic>("api/appaccounts/posttransfer", contents);

            if (!hsr.IsError)
            {
                return("");
            }
            else
            {
                return(hsr.ErrorMessage);
            }
        }
예제 #30
0
        private async Task <List <MoviesListModel> > GetMoviesListModel(HttpServiceResult <BaseMoviesResult> baseMoviesResult, string language)
        {
            var model = new List <MoviesListModel>();

            if (!baseMoviesResult.IsSucess)
            {
                return(model);
            }

            List <BaseMoviesListResult> movies = new List <BaseMoviesListResult>();

            if (baseMoviesResult.Result != null && baseMoviesResult.Result.Results != null)
            {
                movies = baseMoviesResult.Result.Results;
            }


            foreach (var movie in movies)
            {
                var movieModel = new MoviesListModel()
                {
                    Title        = movie.Title,
                    BackdropPath = movie.BackdropPath,
                    VoteAverage  = movie.VoteAverage,
                    Id           = movie.Id,
                    Overview     = movie.Overview,
                    PosterPath   = movie.PosterPath
                };

                if (movie.ReleaseDate != null)
                {
                    if (DateTime.TryParse(movie.ReleaseDate, out DateTime releaseDate))
                    {
                        movieModel.ReleaseDate = releaseDate;
                    }
                }

                if (movie.GenreIds != null)
                {
                    foreach (var genreId in movie.GenreIds)
                    {
                        var genreResult = await genresService.GetGenreById(genreId, language);

                        if (genreResult == null)
                        {
                            continue;
                        }

                        movieModel.Genres.Add(new Models.Genres.GenreModel()
                        {
                            Name = genreResult.Name != null ? genreResult.Name : string.Empty,
                            Id   = genreResult.Id
                        });
                    }
                }

                model.Add(movieModel);
            }

            return(model);
        }