Exemplo n.º 1
0
        public CreationViewModel(IPageHelper p) : base(p)
        {
            TopicIndex = 0;

            //Set execute code when calling the create card command
            //Resets input fields and creates card in model
            CreateCard = new Command(execute: async() =>
            {
                try
                {
                    string topic;
                    if (TopicIndex != 0)
                    {
                        topic = TopicNames[TopicIndex];                  //Add to existing topic
                    }
                    else
                    {
                        topic = TopicName;  //Add to new topic
                    }
                    model.AddNewCard(topic, question, answer, enableNewTopicNameInput);

                    //Clear fields
                    TopicName = "";
                    Question  = "";
                    Answer    = "";

                    //Ensures that last selected topic remains selected
                    TopicIndex = TopicNames.IndexOf(topic);

                    await p.MessagePopup("Card created", "Revision card has been created and added to topic " + topic);
                }
                catch (Exception ex)
                {
                    await p.MessagePopup("Error occurred", "Error: " + ex.Message);
                }
            });
        }
Exemplo n.º 2
0
        public ManageModifyCardViewModel(IPageHelper p, RevisionCardSQL revisionCard) : base(p)
        {
            TopicIndex = 0;

            int originalTopicIndex = TopicNames.IndexOf(revisionCard.Topic);

            TopicIndex = originalTopicIndex;
            Question   = revisionCard.Question;
            Answer     = revisionCard.Answer;

            SaveChangesCommand = new Command(execute: async() =>
            {
                try
                {
                    string topic;
                    if (TopicIndex != 0)
                    {
                        topic = TopicNames[TopicIndex];                  //Change to existing topic
                    }
                    else
                    {
                        topic = TopicName;  //Change to new topic
                    }
                    model.ModifyCard(revisionCard, topic, question, answer);

                    //Ensures that last selected topic remains selected
                    TopicIndex = TopicNames.IndexOf(topic);

                    await p.MessagePopup("Saved changes", "Changes to revision card have been saved.");
                }
                catch (Exception ex)
                {
                    await p.MessagePopup("Error occurred", "Error: " + ex.Message);
                }
            });
        }