Exemple #1
0
 public List <Blog> GetAllBlogs()
 {
     using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
     {
         return(context.Blogs.ToList());
     }
 }
Exemple #2
0
 private Category GetCategoryByName(string newCategory)
 {
     using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
     {
         return(context.Categories.FirstOrDefault(c => c.CategoryName == newCategory));
     }
 }
Exemple #3
0
 public List <Category> getAllCategories()
 {
     using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
     {
         return(context.Categories.ToList());
     }
 }
Exemple #4
0
 public Category GetCategory(int id)
 {
     using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
     {
         return(context.Categories.FirstOrDefault(c => c.CategoryId == id));
     }
 }
Exemple #5
0
 public List <Blog> GetFeaturedBlogs()
 {
     using (SeekingPuraVidaDbContext context = new SeekingPuraVidaDbContext())
     {
         return(context.Blogs.Where(b => b.IsFeatured == true).ToList());
     }
 }
Exemple #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();
            }
        }
Exemple #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);
        }