Exemple #1
0
        public void AddArticle_AddsArticleToAuthor_ArticleList()
        {
            Author testAuthor = new Author("Bob");

            testAuthor.Save();
            Article testArticle = new Article("Bob", "bob");

            testArticle.Save();

            testAuthor.AddArticle(testArticle);
            List <Article> result   = testSpecialty.GetArticles();
            List <Article> testList = new List <Article> {
                testArticle
            };

            CollectionAssert.AreEqual(testList, result);
        }
        public ActionResult Update(int artID, string title, string author)
        {
            Article article = Article.Find(artID);

            article.Edit(title);
            Author existingAuthor = Author.Find(author);

            if (existingAuthor != null)
            {
                existingAuthor.AddArticle(article);
            }
            else
            {
                Author newAuthor = new Author(author);
                newAuthor.Save();
                newAuthor.AddArticle(article);
            }
            return(RedirectToAction("Show", new { articleID = artID }));
        }
        public ActionResult Create(string title, string author)
        {
            Article article = new Article(title);

            article.Save();
            Author existingAuthor = Author.Find(author);

            if (existingAuthor != null)
            {
                existingAuthor.AddArticle(article);
            }
            else
            {
                Author newAuthor = new Author(author);
                newAuthor.Save();
                newAuthor.AddArticle(article);
            }
            return(RedirectToAction("Show", new { articleID = article.GetID() }));
        }
        public ActionResult Create(int artID, string title, string imageLink, string body, string author)
        {
            Section newSection = new Section(title, imageLink, body, artID);
            Article article    = Article.Find(artID);

            newSection.Save();
            Author existingAuthor = Author.Find(author);

            if (existingAuthor != null)
            {
                existingAuthor.AddArticle(article);
            }
            else
            {
                Author newAuthor = new Author(author);
                newAuthor.Save();
                newAuthor.AddArticle(article);
            }
            return(RedirectToAction("Show", "Articles", new { articleID = artID }));
        }
        public ActionResult Update(int artID, int sectionID, string title, string imageLink, string body, string author)
        {
            Section section = Section.Find(sectionID);
            Article article = Article.Find(artID);

            section.Edit(title, imageLink, body);
            Author existingAuthor = Author.Find(author);

            if (existingAuthor != null)
            {
                existingAuthor.AddArticle(article);
            }
            else
            {
                Author newAuthor = new Author(author);
                newAuthor.Save();
                newAuthor.AddArticle(article);
            }
            // Author au = new Author(author);
            // au.Save();
            // au.AddArticle(Article.Find(artID));
            return(RedirectToAction("Show", "Articles", new { articleID = artID }));
        }