public void CreateNewCategory(string catName) { using (var dataContext = new BlogAspNetContext()) { var newCategory = new Category(); newCategory.Name = catName; dataContext.Add(newCategory); dataContext.SaveChanges(); } }
public void CreateNewPost(string title, string post, int?categoryId) { using (var dataContext = new BlogAspNetContext()) { var newPost = new Post(); newPost.Post1 = post; newPost.Datetime = DateTime.Now; newPost.Title = title; newPost.FkCategoryId = categoryId; dataContext.Add(newPost); dataContext.SaveChanges(); } }