Ejemplo n.º 1
0
        public string AddCategory(string userName, string userToken)
        {
            var categoryId = string.Empty;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_globalAppSettings.EmbedDetails.RootUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                var content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("Name", userName)
                });
                client.DefaultRequestHeaders.Add("Authorization", "bearer" + " " + userToken);
                client.DefaultRequestHeaders.Add("ETag", DashboardModel.RandomString());
                var    result        = client.PostAsync(_globalAppSettings.EmbedDetails.RootUrl + "/api/" + _globalAppSettings.EmbedDetails.SiteIdentifier + "/v2.0/categories", content).Result;
                string resultContent = result.Content.ReadAsStringAsync().Result;
                var    response      = JsonConvert.DeserializeObject <ApiResponse>(resultContent);
                categoryId = response.Status ? response.Data.ToString() : string.Empty;
            }

            return(categoryId);
        }