예제 #1
0
 /// <summary>
 /// Create a new Topic object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="created">Initial value of the Created property.</param>
 /// <param name="isValid">Initial value of the IsValid property.</param>
 public static Topic CreateTopic(global::System.Int32 id, global::System.String name, global::System.DateTime created, global::System.Boolean isValid)
 {
     Topic topic = new Topic();
     topic.ID = id;
     topic.Name = name;
     topic.Created = created;
     topic.IsValid = isValid;
     return topic;
 }
예제 #2
0
 /// <summary>
 /// Add a new topic
 /// </summary>
 /// <param name="topic">Topic entity</param>
 public void AddNewTopic(Topic topic)
 {
     dbase.Topics.AddObject(topic);
 }
예제 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Topics EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTopics(Topic topic)
 {
     base.AddObject("Topics", topic);
 }
예제 #4
0
        public ActionResult Create(BibleTopicsViewModel updateModel)
        {
            BibleTopicsViewModel btvm = new BibleTopicsViewModel();
            btvm.Bible = new Bible();
            btvm.BibleBooksVM = new BibleBooksViewModel();
            btvm.TopicList = repo.GetAllTopics();

            btvm.Bible.Verse = updateModel.Book + " " + updateModel.BookVerse + " " + updateModel.BookVersion;
            // If verse already exist
            int bibleID;
            if (repo.CheckVerse(btvm.Bible.Verse))
            {
                bibleID = repo.GetBibleIDByVerse(btvm.Bible.Verse);
                return RedirectToRoute("Edit", new { action = "Verse", id = bibleID });
            }

            if (ModelState.IsValid)
            {
                #region Adding Verse

                int bookID = repo.GetBookID(updateModel.Book);
                btvm.Bible.Message = updateModel.VerseMessage;
                btvm.Bible.Created = DateTime.Now;
                btvm.Bible.IsValid = true;
                btvm.Bible.BookID = bookID;
                repo.AddNewVerse(btvm.Bible);
                repo.Save();
                bibleID = btvm.Bible.ID;

                #endregion

                #region Adding Topic

                int topicID;
                string[] splitTopics = Regex.Split(updateModel.AddedTopic, ", ");
                foreach (string item in splitTopics)
                {
                    Topic topic = new Topic();
                    if (repo.CheckTopic(item))
                    {
                        topicID = repo.GetTopicID(item);
                        topic = repo.GetTopic(topicID);
                        if (topic.IsValid == false)
                        {
                            topic.IsValid = true;
                            UpdateModel(topic);
                            repo.Save();
                        }
                    }
                    else
                    {
                        topic.Name = item;
                        topic.Created = DateTime.Now;
                        topic.IsValid = true;
                        repo.AddNewTopic(topic);
                        repo.Save();
                        topicID = topic.ID;
                    }
                    repo.AddBibleAndTopic(bibleID, topicID);
                    repo.Save();
                }
                return RedirectToRoute("Edit", new { action = "Verse", id = bibleID });

                #endregion
            }

            return View(btvm);
        }