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