Esempio n. 1
0
        public bool AddToIndex(PancakeProwler.Data.Common.Models.Recipe recipe)
        {
            var client = GetClient();
            var uri    = new Uri(new Uri(System.Configuration.ConfigurationManager.AppSettings["AzureSearchBaseURI"]),
                                 "indexes/recipes/docs/index?api-version=" + System.Configuration.ConfigurationManager.AppSettings["AzureSearchApiVersion"]);

            HttpRequestMessage request = BuildAddRequest(recipe, uri);

            return(client.SendAsync(request).Result.StatusCode == System.Net.HttpStatusCode.OK);
        }
Esempio n. 2
0
        private HttpRequestMessage BuildAddRequest(PancakeProwler.Data.Common.Models.Recipe recipe, Uri uri)
        {
            var request = new HttpRequestMessage(HttpMethod.Post, uri);

            var model = new SendToSearchEnvelope();

            model.value.Add(new SendToSearchItem {
                Action = "upload", id = recipe.Id.ToString(), ingredients = recipe.Ingredients, name = recipe.Name, steps = recipe.Steps
            });

            request.Content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
            return(request);
        }