示例#1
0
        public static async Task GetYearTerms(ObservableCollection<YearTerm> YearTermsList)
        {
            var response = await http.GetAsync("http://uwproject.feifei.ca/api/YearTerms");
            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 yearTermId = (int)root.GetObjectAt(i).GetNamedNumber("YearTermId");
                    int year = (int)root.GetObjectAt(i).GetNamedNumber("Year");
                    int term = (int)root.GetObjectAt(i).GetNamedNumber("Term");
                    bool isDefault = root.GetObjectAt(i).GetNamedBoolean("IsDefault");
                    string description = root.GetObjectAt(i).GetNamedString("Description");
                    var yearTerm = new YearTerm
                    {
                        YearTermId = yearTermId,
                        Year = year,
                        Term = term,
                        IsDefault = isDefault,
                    };
                    YearTermsList.Add(yearTerm);
                }
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot retrieve any record");
                await dialog.ShowAsync();
            }
        }
示例#2
0
        public static async Task GetYearTerms(ObservableCollection <YearTerm> YearTermsList)
        {
            var http     = new HttpClient();
            var response = await http.GetAsync("http://uwproject.feifei.ca/api/YearTerms");

            var result = await response.Content.ReadAsStringAsync();

            JsonValue value = JsonValue.Parse(result);
            JsonArray root  = value.GetArray();

            for (uint i = 0; i < root.Count; i++)
            {
                int    yearTermId  = (int)root.GetObjectAt(i).GetNamedNumber("YearTermId");
                int    year        = (int)root.GetObjectAt(i).GetNamedNumber("Year");
                int    term        = (int)root.GetObjectAt(i).GetNamedNumber("Term");
                bool   isDefault   = root.GetObjectAt(i).GetNamedBoolean("IsDefault");
                string description = root.GetObjectAt(i).GetNamedString("Description");
                var    yearTerm    = new YearTerm
                {
                    YearTermId = yearTermId,
                    Year       = year,
                    Term       = term,
                    IsDefault  = isDefault,
                };
                YearTermsList.Add(yearTerm);
            }
        }
示例#3
0
        public static async Task GetYearTerms(ObservableCollection <YearTerm> YearTermsList)
        {
            var response = await http.GetAsync("http://uwproject.feifei.ca/api/YearTerms");

            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    yearTermId  = (int)root.GetObjectAt(i).GetNamedNumber("YearTermId");
                    int    year        = (int)root.GetObjectAt(i).GetNamedNumber("Year");
                    int    term        = (int)root.GetObjectAt(i).GetNamedNumber("Term");
                    bool   isDefault   = root.GetObjectAt(i).GetNamedBoolean("IsDefault");
                    string description = root.GetObjectAt(i).GetNamedString("Description");
                    var    yearTerm    = new YearTerm
                    {
                        YearTermId = yearTermId,
                        Year       = year,
                        Term       = term,
                        IsDefault  = isDefault,
                    };
                    YearTermsList.Add(yearTerm);
                }
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot retrieve any record");
                await dialog.ShowAsync();
            }
        }
示例#4
0
        public static async Task GetYearTerms(ObservableCollection<YearTerm> YearTermsList)
        {
            var http = new HttpClient();
            var response = await http.GetAsync("http://uwproject.feifei.ca/api/YearTerms");
            var result = await response.Content.ReadAsStringAsync();

            JsonValue value = JsonValue.Parse(result);
            JsonArray root = value.GetArray();
            for (uint i = 0; i < root.Count; i++)
            {
                int yearTermId = (int)root.GetObjectAt(i).GetNamedNumber("YearTermId");
                int year = (int)root.GetObjectAt(i).GetNamedNumber("Year");
                int term = (int)root.GetObjectAt(i).GetNamedNumber("Term");
                bool isDefault = root.GetObjectAt(i).GetNamedBoolean("IsDefault");
                string description = root.GetObjectAt(i).GetNamedString("Description");
                var yearTerm = new YearTerm
                {
                    YearTermId = yearTermId,
                    Year = year,
                    Term = term,
                    IsDefault = isDefault,
                };
                YearTermsList.Add(yearTerm);
            }
        }
示例#5
0
        private async void Page_Loading(FrameworkElement sender, object args)
        {
            var obj = App.Current as App;
            StudentNumberBox.Text = obj.studentNumber;

            OptionManager.http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", obj.AccessToken);
            await OptionManager.GetActiveOptions(Options);
            YearTermManager.http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", obj.AccessToken);
            defaultYearTerm = await YearTermManager.DefaultYearTerm(defaultYearTerm);
        }
 private async void EditYearTerm_Click(object sender, RoutedEventArgs e)
 {
     int id;
     if (YearTermIdWillBeEdited.Text != "" && Int32.TryParse(YearTermIdWillBeEdited.Text, out id))
     {
         int year = Int32.Parse( (string)YearWillBeEdited.SelectionBoxItem );
         int term = Int32.Parse( (string)TermWillBeEdited.SelectionBoxItem );
         bool isDefault = ((string)YearTermIsDefaultWillBeEdited.SelectionBoxItem == "Yes") ? true : false;
         var obj = new YearTerm() { YearTermId = id, Year = year, Term = term, IsDefault = isDefault };
         await YearTermManager.EditYearTerm(new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json"), obj, YearTerms);
     }
 }
示例#7
0
        public static async Task DeleteYearTerm(string YearTermIdToBeDeleted, ObservableCollection <YearTerm> YearTermList)
        {
            var response = await http.DeleteAsync("http://uwproject.feifei.ca/api/YearTerms/" + YearTermIdToBeDeleted);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                JsonValue value    = JsonValue.Parse(result);
                YearTerm  yearTerm = JsonConvert.DeserializeObject <YearTerm>(value.ToString());
                YearTermList.Remove(yearTerm);
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot delete record");
                await dialog.ShowAsync();
            }
        }
示例#8
0
        public static async Task EditYearTerm(StringContent YearTermJsonToBeEdited, YearTerm updatedYearTerm, ObservableCollection <YearTerm> YearTermList)
        {
            string requestUri = "http://uwproject.feifei.ca/api/YearTerms/" + updatedYearTerm.YearTermId;
            var    response   = await http.PutAsync(requestUri, YearTermJsonToBeEdited);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                YearTerm currentYearTerm = YearTermList.FirstOrDefault(o => o.YearTermId == updatedYearTerm.YearTermId);
                currentYearTerm = updatedYearTerm;
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot edit record");
                await dialog.ShowAsync();
            }
        }
示例#9
0
        public static async Task AddYearTerm(StringContent yearTermJson, ObservableCollection <YearTerm> YearTermList)
        {
            var response = await http.PostAsync("http://uwproject.feifei.ca/api/YearTerms", yearTermJson);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                JsonValue value    = JsonValue.Parse(result);
                YearTerm  yearTerm = JsonConvert.DeserializeObject <YearTerm>(value.ToString());
                YearTermList.Add(yearTerm);
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot add record");
                await dialog.ShowAsync();
            }
        }
示例#10
0
        public static async Task EditYearTerm(StringContent YearTermJsonToBeEdited, YearTerm updatedYearTerm, ObservableCollection<YearTerm> YearTermList)
        {
            var http = new HttpClient();
            string requestUri = "http://uwproject.feifei.ca/api/YearTerms/" + updatedYearTerm.YearTermId;
            var response = await http.PutAsync(requestUri, YearTermJsonToBeEdited);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();
                YearTerm currentYearTerm = YearTermList.FirstOrDefault(o => o.YearTermId == updatedYearTerm.YearTermId);
                currentYearTerm = updatedYearTerm;
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot edit record");
                await dialog.ShowAsync();
            }
        }