public void AddWebpage(Models.Webpage page) { using (var context = new Models.PostContext()) { context.Webpages.Add(page); context.SaveChanges(); } }
//public void UpdatePost(Post toUpdate) //{ // using (var context = new Models.PostContext()) // { // var post = context.Posts.FirstOrDefault(x => x.PostID == toUpdate.PostID); // post = toUpdate; // context.SaveChanges(); // } //} public void ApprovePost(List<int> postID) { using (var context = new Models.PostContext()) { foreach (var p in postID) { var post = context.Posts.FirstOrDefault(x => x.PostID == p); post.IsApproved = true; context.SaveChanges(); } } }
public void DeletePost(List<int> postID) { foreach (var ID in postID) { using (var context = new Models.PostContext()) { var post = context.Posts.Where(x => x.PostID == ID); foreach (var p in post) { context.Posts.Remove(p); } context.SaveChanges(); } } }
public void AddPost(Post newPost) { using (var context = new Models.PostContext()) { Models.Post post = new Models.Post(); post.Title = newPost.Title; post.IsApproved = newPost.IsApproved; post.DatePosted = newPost.DatePosted; post.Content = newPost.Content; post.CatID = newPost.CatID; post.Categories = newPost.Categories.Select(x => new Models.Category() { category = x.category }).ToList(); context.Posts.Add(post); context.SaveChanges(); } }