public static Post FindPostById(int postId) { CSCB766BlogDBEntities blogDB = new CSCB766BlogDBEntities(); Post requestedPost = blogDB.Posts.SingleOrDefault(p => p.PostID == postId); return requestedPost; }
public static void DeletePost(int postId) { CSCB766BlogDBEntities blogDB = new CSCB766BlogDBEntities(); Post deletedPost = blogDB.Posts.SingleOrDefault(p => p.PostID == postId); blogDB.DeleteObject(deletedPost); blogDB.SaveChanges(); }
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; }
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; }
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; }
public static int CommentCount() { CSCB766BlogDBEntities blogDB = new CSCB766BlogDBEntities(); var count = blogDB.Comments.Count(p => p.CommentID >= 1); if (count != 0) { return count; } else { return 0; } }
protected void Page_Load(object sender, EventArgs e) { string requestPostId = Request.Params["id"]; postId = Int32.Parse(requestPostId); Post viewedPost = BlogDAL.FindPostById(postId); this.LabelPostTitle.Text = viewedPost.PostTitle; this.LabelPostContent.Text = viewedPost.PostContent; this.LabelPostDate.Text = viewedPost.PostDate.ToString(); this.HyperLinkEdit.NavigateUrl = "Admin/EditPost.aspx?id=" + postId.ToString(); this.HyperLinkDelete.NavigateUrl = "Admin/DeletePost.aspx?id=" + postId.ToString(); string str = postId.ToString(); if (!Page.IsPostBack) { if (viewedPost.Comments.Count > 0) { MultiViewComments.ActiveViewIndex += 1; } if (HttpContext.Current.User.Identity.IsAuthenticated) { this.MultiViewEditDelete.ActiveViewIndex += 1; } else { this.MultiViewEditDelete.ActiveViewIndex -= 1; } } CSCB766BlogDBEntities blogDB = new CSCB766BlogDBEntities(); EntityDataSourceComments.WhereParameters.Add(new Parameter("PageId", TypeCode.Int32, postId.ToString())); }