コード例 #1
0
        public BlogsDb()
        {
            BlogEntry blogEntry  = new BlogEntry("Why I love C#", "admin", "Because it's awesome.", new string[] { "C#" });
            BlogEntry blogEntry2 = new BlogEntry("Why I love ASP.NET MVC", "admin", "Becaues it's great.", new string[] { "C#", "ASP.NET", "MVC" });
            BlogEntry blogEntry3 = new BlogEntry("Why I love .NET", "admin", "Because it's a more centralized framework than the Java community offers.", new string[] { ".NET", "EF" });

            blogEntry.AddComment(blogEntry, "user", "a comment");
            blogEntry.AddComment(blogEntry, "user", "another comment");
            blogEntries.Add(blogEntry);
            blogEntries.Add(blogEntry2);
            blogEntries.Add(blogEntry3);
        }
コード例 #2
0
        public bool AddComment(BlogEntry blogEntry, string user, string text)
        {
            Comment comment = new Comment(blogEntry, user, text);

            try
            {
                _comments.Add(comment);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #3
0
        public bool EditBlogEntry(BlogEntry entry)
        {
            BlogEntry blogentry = blogEntries.Find(b => b.Slug.Equals(entry.Slug));

            if (blogentry == null)
            {
                throw new Exception("Could not find blog entry");
            }
            else
            {
                int entryIndex = blogEntries.FindIndex(b => b.Slug.Equals(entry.Slug));
                blogEntries[entryIndex] = entry;
                return(true);
            }
        }
コード例 #4
0
        public bool AddEntry(BlogEntry blogEntry)
        {
            BlogEntry alreadyExistsBlogEntry = blogEntries.Find(b => b.Slug.Equals(blogEntry.Slug));

            if (alreadyExistsBlogEntry != null)
            {
                throw new BlogAlreadyExistsException(EXCEPTION_MESSAGE);
            }

            blogEntries.Add(blogEntry);
            if (blogEntries.Contains(blogEntry))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
 public bool RemoveBlogEntry(BlogEntry blogEntry)
 {
     return(blogEntries.Remove(blogEntry));
 }