예제 #1
0
        public static async System.Threading.Tasks.Task <bool> WritePrefsToSPList(Preference body)
        {
            string token = await GetDataHelper.GetAuthenticationToken();

            //"{'UserName':'******', 'Uni_ID':'likansf3993', 'TenantID':'7454731348764','ServiceURL':'abcghij','SelectedCategories':'a, b, c','NewsNotificationTime':' ','EnTNotifyMe':' ','EnTNotificationTime':' ','TaskNotificationTime':' ','NewsNotificationFlag':' ','EnTNotificationFlag':' ','NewsNotifyMe':' '}";
            string cats = string.Join(",", body.News.SelectedCategories);
            //change below code to some model
            string finalBody = "{'UserName' :'" + body.UserName + "', 'Uni_ID' :'" + body.UserInfo[0].UniqueID + "', 'TenantID' :'" + body.UserInfo[0].TenantID + "', 'ServiceURL' :'" + body.UserInfo[0].ServiceURl + "', 'SelectedCategories' :'" + cats + "', 'NewsNotificationTime' :'" + body.News.NewsNotificationTime + "', 'EnTNotifyMe' :'" + body.EandT.EandTNotifyMe + "', 'EnTNotificationTime' :'" + body.EandT.EandTNotificationTime + "', 'TaskNotificationTime' :'" + body.Task.TaskNotificationTime + "', 'NewsNotificationFlag' :'" + body.News.NewsNotificationFlag + "', 'EnTNotificationFlag' :'" + body.EandT.EandTNotificationFlag + "', 'NewsNotifyMe' :'" + body.News.NewsNotifyMe + "'}";



            string endpoint = "https://avadheshftc.sharepoint.com/sites/EmployeeConnectPrototype/_api/web/lists/GetByTitle('PreferencesList')/items";

            using (var client = new HttpClient())
            {
                using (var request = new HttpRequestMessage(HttpMethod.Post, endpoint))
                {
                    request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    request.Content = new StringContent(finalBody, Encoding.UTF8, "application/json");

                    using (HttpResponseMessage response = await client.SendAsync(request))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            return(true);
                        }
                        return(false);
                    }
                }
            }
        }
예제 #2
0
        public static async System.Threading.Tasks.Task GetPreferencesandWriteToFile() // need to decide how many time it will run and update the data file.
        {
            string token = await GetDataHelper.GetAuthenticationToken();

            string          endpoint = "https://avadheshftc.sharepoint.com/sites/EmployeeConnectPrototype/_api/web/Lists(guid'e8937172-f3f3-478e-97bb-d5699f8d8945')/items";
            SPFXPreferences pref     = null;

            using (var client = new HttpClient())
            {
                using (var request = new HttpRequestMessage(HttpMethod.Get, endpoint))
                {
                    string location = System.Web.Hosting.HostingEnvironment.MapPath(@"~\TestData\");
                    request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);

                    using (HttpResponseMessage response = await client.SendAsync(request))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            var json = await response.Content.ReadAsStringAsync();

                            try
                            {
                                pref = (new JavaScriptSerializer().Deserialize <SPFXPreferences>(json));
                                File.WriteAllText(location + "PreferencesMock.json", json);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                }
            }
        }