示例#1
0
 public void AddWebpage(Models.Webpage page)
 {
     using (var context = new Models.PostContext())
     {
         context.Webpages.Add(page);
         context.SaveChanges();
     }
 }
示例#2
0
        //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();
                }
            }
        }
示例#3
0
        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();
                }
            }
        }
示例#4
0
        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();
            }
        }