Ejemplo n.º 1
0
        public void ModifyCard(RevisionCardSQL revisionCard, string newTopic,
                               string newQuestion, string newAnswer)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(newTopic) || string.IsNullOrWhiteSpace(newQuestion) || string.IsNullOrWhiteSpace(newAnswer))
                {
                    throw new Exception("Topic, Question or Answer not filled in correctly!");
                }

                dataModel.SaveDeleteCard(revisionCard);

                revisionCard.Topic    = newTopic;
                revisionCard.Question = newQuestion;
                revisionCard.Answer   = newAnswer;

                dataModel.SaveCard(revisionCard);

                OnUpdate?.Invoke();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public void AddNewCard(string topicName, string question, string answer, bool isNewTopic)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(topicName) || string.IsNullOrWhiteSpace(question) || string.IsNullOrWhiteSpace(answer))
                {
                    throw new Exception("Topic, Question or Answer not filled in correctly!");
                }

                var newRevisionCard = new RevisionCardSQL {
                    Topic = topicName, Question = question, Answer = answer
                };

                var topic = GetTopicByName(topicName);

                //If topic is entered by user but topic of same name already exists
                //then throw error so that user can assign card to already existing topic
                if (topic != null && isNewTopic)
                {
                    throw new Exception("Topic of name " + topicName + " already exists!");
                }
                else if (topic == null)
                {
                    AddNewTopic(topicName);
                }

                dataModel.SaveCard(newRevisionCard);

                OnUpdate?.Invoke();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
 public void DeleteCard(RevisionCardSQL cardToRemove)
 {
     try
     {
         dataModel.SaveDeleteCard(cardToRemove);
         OnUpdate?.Invoke();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 4
0
        public void SaveDeleteCard(RevisionCardSQL revisionCard)
        {
            var topic = GetTopicByName(revisionCard.Topic);

            if (!RevisionGroups[topic].Contains(revisionCard))
            {
                return;
            }

            RevisionGroups[topic].Remove(revisionCard);
            conn.Delete(revisionCard);

            topic.CardCount -= 1;
            SaveTopic(topic); //Save topic card count decrease
        }
Ejemplo n.º 5
0
        public void SaveCard(RevisionCardSQL revisionCard)
        {
            var topic = GetTopicByName(revisionCard.Topic);

            if (RevisionGroups[topic].Contains(revisionCard)) // Revision card present so must be updated
            {
                conn.Update(revisionCard);
            }
            else // Revision card not present so must be saved as new
            {
                RevisionGroups[topic].Add(revisionCard);
                conn.Insert(revisionCard);

                topic.CardCount += 1;
                SaveTopic(topic); // Save topic card count increase
            }
        }