예제 #1
0
 public List <Blog> GetAllBlogs()
 {
     using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
     {
         return(context.Blogs.ToList());
     }
 }
예제 #2
0
 private Category GetCategoryByName(string newCategory)
 {
     using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
     {
         return(context.Categories.FirstOrDefault(c => c.CategoryName == newCategory));
     }
 }
예제 #3
0
 public List <Category> getAllCategories()
 {
     using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
     {
         return(context.Categories.ToList());
     }
 }
예제 #4
0
 public Category GetCategory(int id)
 {
     using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
     {
         return(context.Categories.FirstOrDefault(c => c.CategoryId == id));
     }
 }
예제 #5
0
 public List <Blog> GetFeaturedBlogs()
 {
     using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
     {
         return(context.Blogs.Where(b => b.IsFeatured == true).ToList());
     }
 }
예제 #6
0
        public void AddBlog(Blog blog)
        {
            using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
            {
                List <Category> cats = new List <Category>();
                foreach (var cat in blog.BlogCategories)
                {
                    cats.Add(context.Categories.FirstOrDefault(c => c.CategoryName == cat.CategoryName));
                }

                blog.BlogCategories = cats;

                context.Blogs.Add(blog);
                context.SaveChanges();
            }
        }
예제 #7
0
        public Category AddNewCategory(string newCategory)
        {
            Category toAdd = new Category();

            using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
            {
                toAdd.CategoryName = newCategory;
                context.Categories.Add(toAdd);
                context.SaveChanges();
            }

            Category toReturn = new Category();

            toReturn = GetCategoryByName(newCategory);

            return(toReturn);
        }