private void InsertValueIntoAzureSearch(AzureSearchValue pItem) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://gpstermsearch.search.windows.net/indexes/gpsterms/docs/index?api-version=2015-02-28"); request.Method = "POST"; request.ContentType = "application/json"; request.Headers.Add("api-key", Values.AzureSearchApiKey); try { var serializer = new JavaScriptSerializer(); var serializedResult = serializer.Serialize(pItem); using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(serializedResult); streamWriter.Flush(); streamWriter.Close(); } WebResponse response = request.GetResponse(); var streamReader = new StreamReader(response.GetResponseStream()); var result = streamReader.ReadToEnd(); } catch (Exception ex) { Console.WriteLine(ex.InnerException); EventViewerLogger.LogError("AzureSearch: " + ex.Message); } }
public void InsertEntry(int pPersonID, string pOperatorName, string pPhone, int pCountryID) { try { CountryEN personCountry = topupDAL.GetCountryByID(pCountryID); string operatorBrand = pOperatorName + " " + personCountry.Name; OperatorEN operatorFound = topupDAL.GetOperatorByBrand(pCountryID, operatorBrand); if (operatorFound != null) { RangeAzureSearch item = new RangeAzureSearch(); item.country_code = (operatorFound.ISO2Code != String.Empty) ? operatorFound.ISO2Code : ""; item.mnc = (operatorFound.Mnc != String.Empty) ? operatorFound.Mnc : ""; item.mcc = "706"; item.mno_id = Convert.ToString(operatorFound.OperatorID); item.term_end = pPhone; item.term_init = pPhone; item.term_id = Guid.NewGuid().ToString(); AzureSearchValue azureValue = new AzureSearchValue(); List <RangeAzureSearch> values = new List <RangeAzureSearch>(); values.Add(item); azureValue.value = values; InsertValueIntoAzureSearch(azureValue); } } catch (Exception ex) { Console.WriteLine(ex.InnerException); EventViewerLogger.LogError("AzureSearch: " + ex.Message); } }