Ejemplo n.º 1
0
        public static void DeletePost(int postId)
        {
            CSCB766BlogDBEntities blogDB = new CSCB766BlogDBEntities();
            Post deletedPost = blogDB.Posts.SingleOrDefault(p => p.PostID == postId);

            blogDB.DeleteObject(deletedPost);
            blogDB.SaveChanges();
        }
Ejemplo n.º 2
0
        public static Post EditPost(int postId, string title, string postContent)
        {
            CSCB766BlogDBEntities blogDB = new CSCB766BlogDBEntities();
            Post editedPost = blogDB.Posts.SingleOrDefault(p => p.PostID == postId);

            editedPost.PostTitle = title;
            editedPost.PostContent = postContent;
            blogDB.SaveChanges();

            return editedPost;
        }
Ejemplo n.º 3
0
        public static Post CreatePost(string title, string postContent)
        {
            Post newPost = new Post();
            newPost.PostTitle = title;
            newPost.PostContent = postContent;
            newPost.PostDate = DateTime.Now;

            CSCB766BlogDBEntities blogDB = new CSCB766BlogDBEntities();
            blogDB.Posts.AddObject(newPost);
            blogDB.SaveChanges();

            return newPost;
        }
Ejemplo n.º 4
0
        public static Comment AddComment(int postId, string author, string text)
        {
            CSCB766BlogDBEntities blogDB = new CSCB766BlogDBEntities();
            Comment comment = new Comment();

            comment.PostID = postId;
            comment.Author = author;
            comment.CommentText = text;

            blogDB.Comments.AddObject(comment);
            blogDB.SaveChanges();

            return comment;
        }