Esempio n. 1
0
 public IEnumerable<Entry> GetEntries(int blogId)
 {
     using (_context = _contextFactory.CreateContext())
     {
         return _context.Entries.Where(e => e.BlogId == blogId).ToList();
     }
 }
Esempio n. 2
0
 public IList<Blog> GetBlogs()
 {
     using (_context = _contextFactory.CreateContext())
     {
         return _context.Blogs.Include(b => b.Entries).ToList();
     }
 }
Esempio n. 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();
            }
        }
Esempio n. 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();
            }
        }
Esempio n. 5
0
        public void AddBlog(Blog blog)
        {
            if (blog == null)
            {
                throw new ArgumentNullException("blog");
            }

            using (_context = _contextFactory.CreateContext())
            {
                _context.Blogs.Add(blog);
                _context.SaveChanges();
            }
        }
Esempio n. 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();
            }
        }
Esempio n. 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();
            }
        }
Esempio n. 8
0
        public Entry GetEntry(int entryId)
        {
            using (_context = _contextFactory.CreateContext())
            {
                Entry entry = _context.Entries.SingleOrDefault(e => e.EntryId == entryId);

                return entry;
            }
        }