Exemple #1
0
        public async Task <FilamentModel> AddFilaments(object model)
        {
            Console.WriteLine(JsonConvert.SerializeObject(model));
            var response = await client.PostAsJsonAsync("/datas", model);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                Console.WriteLine(json);
                return(FilamentModel.fromJson(JObject.Parse(JObject.Parse(json)["data"].ToString())));
            }
            return(null);
        }
Exemple #2
0
        public async Task <List <FilamentModel> > GetFilaments(string creator, string type, string color)
        {
            string        url     = "/datas";
            StringBuilder builder = new StringBuilder();

            if (creator != null && !creator.Equals(""))
            {
                builder.Append("creator=" + creator + "&");
            }
            if (type != null && !type.Equals(""))
            {
                builder.Append("type=" + type + "&");
            }
            if (color != null && !color.Equals(""))
            {
                builder.Append("color=" + color + "&");
            }
            var response = await client.GetAsync(builder.Length > 0?url + "?" + builder.ToString().Substring(0, builder.Length - 1) : url);

            if (response.IsSuccessStatusCode)
            {
                var contents = await response.Content.ReadAsStringAsync();

                JObject result = JObject.Parse(contents);
                JArray  array  = JArray.Parse(result["data"].ToString());
                List <FilamentModel> models = new List <FilamentModel>();
                foreach (JObject item in array)
                {
                    Console.WriteLine(item);
                    FilamentModel model = FilamentModel.fromJson(item);
                    models.Add(model);
                }
                return(models);
            }
            return(null);
        }