示例#1
0
        public static async Task GetChoices(ObservableCollection<Choice> ChoiceList)
        {
            var response = await http.GetAsync("http://uwproject.feifei.ca/api/Choices");
            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++)
                {
                    var obj = root.GetObjectAt(i);
                    int choiceId = (int)obj.GetNamedNumber("ChoiceId");
                    string studentId = obj.GetNamedString("StudentId");
                    string studentFirstName = obj.GetNamedString("StudentFirstName");
                    string studentLastName = obj.GetNamedString("StudentLastName");
                    string firstChoiceOptionTitle = obj.GetNamedString("FirstChoiceOptionTitle");
                    string secondChoiceOptionTitle = obj.GetNamedString("SecondChoiceOptionTitle");
                    string thirdChoiceOptionTitle = obj.GetNamedString("ThirdChoiceOptionTitle");
                    string fourthChoiceOptionTitle = obj.GetNamedString("FourthChoiceOptionTitle");
                    string selectionDate = obj.GetNamedString("SelectionDate");
                    int year = (int)obj.GetNamedNumber("Year");
                    int term = (int)obj.GetNamedNumber("Term");
                    var choice = new Choice
                    {
                        ChoiceId = choiceId,
                        StudentId = studentId,
                        StudentFirstName = studentFirstName,
                        StudentLastName = studentLastName,
                        FirstChoiceOptionTitle = firstChoiceOptionTitle,
                        SecondChoiceOptionTitle = secondChoiceOptionTitle,
                        ThirdChoiceOptionTitle = thirdChoiceOptionTitle,
                        FourthChoiceOptionTitle = fourthChoiceOptionTitle,
                        SelectionDate = selectionDate,
                        Year = year,
                        Term = term
                    };
                    ChoiceList.Add(choice);
                }
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot retrieve any record");
                await dialog.ShowAsync();
            }
            
        }
        private async void EditChoice_Click(object sender, RoutedEventArgs e)
        {
            int id = Convert.ToInt16(txtId.Text);
            if (txtId.Text != "" && txtStudentId.Text != "" && txtFName.Text != "" && txtLName.Text != "")
            {
                string studentId = txtStudentId.Text;
                string fName = txtFName.Text;
                string lName = txtLName.Text;
                int firstChoice = Options.Where(o => o.Title == cbFirstChoice.SelectedValue.ToString()).Select(o => o).FirstOrDefault().OptionId;
                int secondChoice = Options.Where(o => o.Title == cbSecondChoice.SelectedValue.ToString()).Select(o => o).FirstOrDefault().OptionId;
                int thirdChoice = Options.Where(o => o.Title == cbThirdChoice.SelectedValue.ToString()).Select(o => o).FirstOrDefault().OptionId;
                int fourthChoice = Options.Where(o => o.Title == cbFourthChoice.SelectedValue.ToString()).Select(o => o).FirstOrDefault().OptionId;

                int yearTerm = YearTerms.Where(y => y.Term == Convert.ToInt16(cbTerm.SelectedValue) && y.Year == Convert.ToInt16(cbYear.SelectedValue)).Select(y => y).FirstOrDefault().YearTermId;
                selectionDate = Choices.Where(c => c.ChoiceId == Convert.ToInt16(id)).Select(c => c).FirstOrDefault().SelectionDate;

                var choice = new Choice() { ChoiceId = id, StudentId = studentId, StudentFirstName = fName, StudentLastName = lName, FirstChoiceOptionTitle = cbFirstChoice.SelectedValue.ToString(), SecondChoiceOptionTitle = cbSecondChoice.SelectedValue.ToString(), ThirdChoiceOptionTitle = cbThirdChoice.SelectedValue.ToString(), FourthChoiceOptionTitle = cbFourthChoice.SelectedValue.ToString(), Year = Convert.ToInt16(cbYear.SelectedValue), Term = Convert.ToInt16(cbTerm.SelectedValue), SelectionDate = selectionDate };
                var obj = new { ChoiceId = id, StudentId = studentId, StudentFirstName = fName, StudentLastName = lName, FirstChoiceOptionId = firstChoice, SecondChoiceOptionId = secondChoice, ThirdChoiceOptionId = thirdChoice, FourthChoiceOptionId = fourthChoice, YearTermId = yearTerm, SelectionDate = selectionDate };

                await ChoiceManager.EditChoice(new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json"), choice, Choices);
                Frame.Navigate(typeof(ManageChoicePage));
            }
        }
示例#3
0
        public static async Task EditChoice(StringContent choiceJsonToBeEdited, Choice updatedChoice, ObservableCollection<Choice> ChoicesList)
        {
            string requestUri = "http://uwproject.feifei.ca/api/Choices/" + updatedChoice.ChoiceId;
            var response = await http.PutAsync(requestUri, choiceJsonToBeEdited);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();
                Choice currentChoice = ChoicesList.FirstOrDefault(c => c.ChoiceId == updatedChoice.ChoiceId);
                currentChoice = updatedChoice;
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot edit record");
                await dialog.ShowAsync();
            }
        }