private void btnAddPost_Click(object sender, EventArgs e) { var cbStatus = 0; if (cbPublish.Checked) { cbStatus = 1; } var newPost = new post { post_author = int.Parse((cbbUser.Text)), post_content = tbContent.Text, post_title = tbTitle.Text, status = cbStatus, date_created = DateTime.Now, date_updated = DateTime.Now }; using (var ctx = new AppEntities()) { if (ctx.users.Find(newPost.post_author) != null) { ctx.posts.Add(newPost); ctx.SaveChanges(); this.postsTableAdapter.Fill(this.appDataSet2.posts); } else { } } }
private static int CountPost() { using (var ctx = new AppEntities()) { return(ctx.posts .Count(o => o.status == 1)); } }
private static IEnumerable <post> LoadPostPagination(int realPage, int numberPostPerPage) { using (var ctx = new AppEntities()) { var postPaging = ctx.posts .Where(item => item.status == 1) .Distinct() .OrderByDescending(d => d.id) .Skip(realPage * numberPostPerPage) .Take(numberPostPerPage) .ToList(); return(postPaging); } }