Example #1
0
        public async Task <List <Property> > GetItemsAsync(string postID)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new Exception(ErrorMessage.NotLogin);
            }
            List <Property> items = new List <Property>();
            string          url   = $"api/properties/get_my_properties/?count=50";

            if (!string.IsNullOrEmpty(postID))
            {
                url += "&post_id=" + postID;
            }
            var json = await client.GetStringAsync(url);

            ErrorMessage.CheckRespond(json);

            JObject root   = JObject.Parse(json);
            var     values = root["posts"].Children();

            foreach (JToken result in values)
            {
                try
                {
                    Property item = result.ToObject <Property>();
                    items.Add(item);
                }
                catch (System.Exception ex)
                {
                    Debug.Write(ex.Message);
                    throw new Exception(ErrorMessage.DecodeEorror);
                }
            }
            return(items);
        }
Example #2
0
        public async Task <int> GetMaxUploadImageCount()
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new Exception(ErrorMessage.NotLogin);
            }

            string url   = "api/properties/get_max_image_count";
            var    count = await client.GetStringAsync(url);

            ErrorMessage.CheckRespond(count);
            return(System.Int32.Parse(count.Trim().Replace("\"", "")));
        }
Example #3
0
        public async Task DeleteItemAsync(string id)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new Exception(ErrorMessage.NotLogin);
            }

            string url = $"api/properties/del/?post_id=" + id;

            var json = await client.GetStringAsync(url);

            ErrorMessage.CheckRespond(json);
        }
Example #4
0
        public async Task <User> GetCurrentUser()
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new Exception(ErrorMessage.NetworkIssue);
            }

            string url  = String.Format("api/properties/get_userinfo/");
            var    json = await client.GetStringAsync(url);

            ErrorMessage.CheckRespond(json);
            return(await Task.Run(() => JsonConvert.DeserializeObject <User>(json)));
        }
Example #5
0
        public async Task SaveCurrentUser(User user)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new Exception(ErrorMessage.NetworkIssue);
            }

            var serializedItem = JsonConvert.SerializeObject(user);
            var content        = new StringContent(serializedItem, Encoding.UTF8, "application/json");

            var response = await client.PostAsync($"api/properties/save_userinfo/", content);

            var stringContent = await response.Content.ReadAsStringAsync();

            ErrorMessage.CheckRespond(stringContent);
        }
Example #6
0
        public async Task <Cookie> RegisterUser(User user)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new Exception(ErrorMessage.NetworkIssue);
            }

            var serializedItem = JsonConvert.SerializeObject(user);
            var content        = new StringContent(serializedItem, Encoding.UTF8, "application/json");

            var response = await client.PostAsync($"api/properties/register/", content);

            var stringContent = await response.Content.ReadAsStringAsync();

            ErrorMessage.CheckRespond(stringContent);
            return(await Task.Run(() => JsonConvert.DeserializeObject <Cookie>(stringContent)));
        }
Example #7
0
        public async Task <string> AddItemAsync(Property item)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new Exception(ErrorMessage.NotLogin);
            }


            var serializedItem = JsonConvert.SerializeObject(item);
            var content        = new StringContent(serializedItem, Encoding.UTF8, "application/json");

            var response = await client.PostAsync($"api/properties/create_property/", content);

            var stringContent = await response.Content.ReadAsStringAsync();

            ErrorMessage.CheckRespond(stringContent);
            return(stringContent.Trim());
        }
Example #8
0
        public async Task <string> UploadImage(string path, string postID, string index)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new Exception(ErrorMessage.NotLogin);
            }

            string url            = String.Format("api/properties/uploadImage?post_id={0}&image_index={1}", postID, index);
            var    requestContent = new MultipartFormDataContent();

            var ImageDate    = File.ReadAllBytes(path);
            var imageContent = new ByteArrayContent(ImageDate);

            imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg");
            requestContent.Add(imageContent, "attachment", System.IO.Path.GetFileName(path));
            var response = await client.PostAsync(url, requestContent);

            var attchmentUrl = await response.Content.ReadAsStringAsync();

            ErrorMessage.CheckRespond(attchmentUrl);
            attchmentUrl = attchmentUrl.Trim();
            attchmentUrl = attchmentUrl.Replace("\\/", "/").Replace("\"", "");
            return(attchmentUrl);
        }