예제 #1
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();
            }
        }
예제 #2
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);
        }