示例#1
0
        public static async Task <List <GetPostCategory> > GetAllPostCategory()
        {
            try
            {
                HttpClient client = new HttpClient();

                TokenValidator.CheckTokenValidity();
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));
                var response = await client.GetAsync(getpostcategoryUrl);

                HttpContent httpContent = response.Content;

                var json = await httpContent.ReadAsStringAsync();

                var church = JsonConvert.DeserializeObject <List <GetPostCategory> >(json);

                if (church != null)
                {
                    Preferences.Set("PostCategory", json);
                }
                return(church);
            }
            catch (Exception r)
            {
                return(null);
            }
        }
示例#2
0
        public static async Task <bool> LikePost(LikeRequest like)
        {
            TokenValidator.CheckTokenValidity();
            try
            {
                var client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));
                var json     = JsonConvert.SerializeObject(like);
                var content  = new StringContent(json, Encoding.UTF8, "application/json");
                var response = await client.PostAsync(likepostUrl, content);

                if (!response.IsSuccessStatusCode)
                {
                    return(false);
                }

                // var responsecontent = JsonConvert.DeserializeObject<RegisterResponse>(jsonResult);
                return(true);
            }
            catch (Exception r)
            {
                Debug.WriteLine(r.Message);
            }
            return(false);
        }
示例#3
0
        public static async Task <bool> PostShare(string postId)
        {
            TokenValidator.CheckTokenValidity();
            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));
            var response = await client.GetAsync(sharepostUrl + postId);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
示例#4
0
        public static async Task <bool> PostComment(PostCommentReq req)
        {
            TokenValidator.CheckTokenValidity();
            var client  = new HttpClient();
            var json    = JsonConvert.SerializeObject(req);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));
            var response = await client.PostAsync(createcommentUrl, content);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
示例#5
0
        public static async Task <List <GroupChats> > GetGroupChat(string groupId)
        {
            TokenValidator.CheckTokenValidity();
            try
            {
                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));

                var response = await client.GetAsync(groupchatUrl + groupId);

                HttpContent httpContent = response.Content;
                var         json        = await httpContent.ReadAsStringAsync();

                var groups = JsonConvert.DeserializeObject <List <GroupChats> >(json);

                return(groups);
            }
            catch (Exception c)
            {
                Debug.WriteLine(c.Message);
            }
            return(null);
        }