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