Example #1
0
        public static async Task GetActiveOptions(ObservableCollection<Option> OptionsList)
        {
            var response = await http.GetAsync("http://uwproject.feifei.ca/api/Options");
            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();
                JsonValue value = JsonValue.Parse(result);
                JsonArray root = value.GetArray();
                for (uint i = 0; i < root.Count; i++)
                {
                    int optionId = (int)root.GetObjectAt(i).GetNamedNumber("OptionId");
                    string title = root.GetObjectAt(i).GetNamedString("Title");
                    bool isActive = root.GetObjectAt(i).GetNamedBoolean("IsActive");

                    if (isActive == true)
                    {
                        var option = new Option
                        {
                            OptionId = optionId,
                            Title = title,
                            IsActive = isActive,
                        };
                        OptionsList.Add(option);
                    }
                }
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot retrieve any record");
                await dialog.ShowAsync();
            }
        }
 private async void EditOption_Click(object sender, RoutedEventArgs e)
 {
     int id;
     if (OptionIdWillBeEdited.Text != "" && OptionTitleWillBeEdited.Text != "" && Int32.TryParse(OptionIdWillBeEdited.Text, out id))
     {
         string title = OptionTitleWillBeEdited.Text;
         bool active = ((string)OptionActiveWillBeEdited.SelectionBoxItem == "Yes") ? true : false;
         var obj = new Option() { OptionId = id, Title = title, IsActive = active };
         await OptionManager.EditOption(new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json"), obj, Options);
     }
 }
Example #3
0
        public static async Task EditOption(StringContent optionJsonToBeEdited, Option updatedOption, ObservableCollection<Option> OptionsList)
        {
            var http = new HttpClient();
            string requestUri = "http://uwproject.feifei.ca/api/Options/" + updatedOption.OptionId;
            var response = await http.PutAsync(requestUri, optionJsonToBeEdited);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();
                Option currentOption = OptionsList.FirstOrDefault(o => o.OptionId == updatedOption.OptionId);
                currentOption = updatedOption; 
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot edit record");
                await dialog.ShowAsync();
            }
        }
Example #4
0
        public static async Task GetOptions(ObservableCollection<Option> OptionsList)
        {
            var http = new HttpClient();
            var response = await http.GetAsync("http://uwproject.feifei.ca/api/Options");
            var result = await response.Content.ReadAsStringAsync();

            JsonValue value = JsonValue.Parse(result);
            JsonArray root = value.GetArray();
            for (uint i = 0; i < root.Count; i++)
            {
                int optionId = (int)root.GetObjectAt(i).GetNamedNumber("OptionId");
                string title = root.GetObjectAt(i).GetNamedString("Title");
                bool isActive = root.GetObjectAt(i).GetNamedBoolean("IsActive");
                var option = new Option
                {
                    OptionId = optionId,
                    Title = title,
                    IsActive = isActive,
                };
                OptionsList.Add(option);
            }
        }