Exemplo n.º 1
0
        public void AddQuestAnswers()
        {
            QnA_Model newQuestionAdd = new QnA_Model {
                Question = Question, Difficulty = Difficulty, Answer = Answer
            };

            QuestionList.Add(newQuestionAdd);



            // string filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "temp.txt");
            //// newQuestionAdd = newQuestionAdd;
            // XmlSerializer serializer  = new XmlSerializer(typeof(List<QnA_Model>));
            // Stream writer = new FileStream(filepath, FileMode.Create); // Initialises the writer

            // serializer.Serialize(writer, Question); // Writes to the file
            // writer.Close();
            // now you can elete under me



            int indexOfAddedQuestion = QuestionList.IndexOf(newQuestionAdd);

            QuestionList.Move(indexOfAddedQuestion, 0);

            //QnA_Model qmodel = new QnA_Model();
            //  qmodel.Question = Question;
            System.Xml.Serialization.XmlSerializer xmlwriter = new System.Xml.Serialization.XmlSerializer(typeof(QnA_Model));
            var paths = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//topicstore.txt";

            System.IO.FileStream file = System.IO.File.Create(paths);

            xmlwriter.Serialize(file, newQuestionAdd);
            file.Close();



            System.Xml.Serialization.XmlSerializer reader =
                new System.Xml.Serialization.XmlSerializer(typeof(QnA_Model));
            System.IO.StreamReader fileRead = new System.IO.StreamReader(paths);
            QnA_Model qmodels = (QnA_Model)reader.Deserialize(file);

            file.Close();



            //string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "temp.txt");



            //  File.WriteAllText(fileName, Question + Difficulty + Answer);
        }
Exemplo n.º 2
0
        public async void EditQuestion()
        {
            int indexOfNewQuestion = QuestionList.IndexOf(SelectedQuestion);

            QuestionList.Remove(SelectedQuestion);
            QnA_Model newQuestionEdit = new QnA_Model {
                Question = Question, Difficulty = Difficulty, Answer = Answer
            };

            QuestionList.Add(newQuestionEdit);
            int indexOfDeletedQuestion = QuestionList.IndexOf(newQuestionEdit);

            if (indexOfNewQuestion >= 0)
            {
                QuestionList.Move(indexOfDeletedQuestion, indexOfNewQuestion);
            }
            else
            {
                await App.Current.MainPage.DisplayAlert("No Flashcard Selected", "You must select a flashcard to edit!", "Gotcha!");
            }
        }