Пример #1
0
 public IEnumerable<Entry> GetEntries(int blogId)
 {
     using (_context = _contextFactory.CreateContext())
     {
         return _context.Entries.Where(e => e.BlogId == blogId).ToList();
     }
 }
Пример #2
0
 public IList<Blog> GetBlogs()
 {
     using (_context = _contextFactory.CreateContext())
     {
         return _context.Blogs.Include(b => b.Entries).ToList();
     }
 }
Пример #3
0
        public void AddEntry(int blogId, string title, string body)
        {
            if (String.IsNullOrWhiteSpace(title))
            {
                throw new ArgumentNullException("title");
            }

            if (String.IsNullOrWhiteSpace(body))
            {
                throw new ArgumentNullException("body");
            }

            using (_context = _contextFactory.CreateContext())
            {
                Blog blog = _context.Blogs.SingleOrDefault(b => b.BlogId == blogId);

                if (blog == null)
                {
                    throw new ObjectDoesNotExistException("blog");
                }

                Entry entry = new Entry(title, body);

                blog.AddEntry(entry);

                _context.Entries.Add(entry);
                _context.SaveChanges();
            }
        }
Пример #4
0
        public void RemoveBlog(int blogId)
        {
            using (_context = _contextFactory.CreateContext())
            {
                Blog blog = _context.Blogs.SingleOrDefault(b => b.BlogId == blogId);

                _context.Blogs.Remove(blog);
                _context.SaveChanges();
            }
        }
Пример #5
0
        public void AddBlog(Blog blog)
        {
            if (blog == null)
            {
                throw new ArgumentNullException("blog");
            }

            using (_context = _contextFactory.CreateContext())
            {
                _context.Blogs.Add(blog);
                _context.SaveChanges();
            }
        }
Пример #6
0
        public void EditEntry(int entryId, string title, string body)
        {
            using (_context = _contextFactory.CreateContext())
            {
                Entry entry = _context.Entries.SingleOrDefault(e => e.EntryId == entryId);

                if (entry == null)
                {
                    throw new ObjectDoesNotExistException("entry does not exist with id " + entryId);
                }

                entry.EditEntry(title, body);

                _context.SaveChanges();
            }
        }
Пример #7
0
        public void RemoveEntry(int blogId, int entryId)
        {
            using (_context = _contextFactory.CreateContext())
            {
                Blog blog = _context.Blogs.Include(o => o.Entries).SingleOrDefault(b => b.BlogId == blogId);

                if (blog == null)
                {
                    throw new ObjectDoesNotExistException("blog");
                }

                Entry entry = blog.Entries.SingleOrDefault(e => e.EntryId == entryId);

                if (entry == null)
                {
                    throw new ObjectDoesNotExistException("entry");
                }

                blog.RemoveEntry(entry.EntryId);

                _context.Entries.Remove(entry);
                _context.SaveChanges();
            }
        }
Пример #8
0
        public Entry GetEntry(int entryId)
        {
            using (_context = _contextFactory.CreateContext())
            {
                Entry entry = _context.Entries.SingleOrDefault(e => e.EntryId == entryId);

                return entry;
            }
        }