public int UpdateLastRead(int accountID, bool isPost, DateTime?time = null) { int unreadPostID = 0; ViewCount++; if (accountID > 0) { if (time == null) { time = DateTime.UtcNow; } var lastRead = ForumThreadLastReads.SingleOrDefault(x => x.AccountID == accountID); if (lastRead == null) { lastRead = new ForumThreadLastRead() { AccountID = accountID }; ForumThreadLastReads.Add(lastRead); } var firstUnreadPost = ForumPosts.FirstOrDefault(x => x.Created > (lastRead.LastRead ?? DateTime.MinValue)); if (firstUnreadPost != null) { unreadPostID = firstUnreadPost.ForumPostID; } lastRead.LastRead = time; if (isPost) { lastRead.LastPosted = time; } } return(unreadPostID); }
public async Task <ActionResult <ForumPosts> > Post(ForumPosts post) { await repo.AddPostAsync(post); await repo.SaveChangesAsync(); return(CreatedAtAction("GetPost", new { id = post.PostID }, post)); }
public IActionResult Forum(ForumPosts model) { model.Date = DateTime.Now; // Store the model in the database repo.AddPost(model); return(Redirect("ForumPost")); }
public ActionResult DeleteConfirmed(int id) { ForumPosts forumPosts = db.ForumPosts.Find(id); db.ForumPosts.Remove(forumPosts); db.SaveChanges(); return(RedirectToAction("Index")); }
public void UpdatePostAsync(ForumPosts post, int id) { var e = context.ForumPosts.Find(id); e.PostTopic = post.PostTopic; e.PostText = post.PostText; e.Name = post.Name; e.Date = post.Date; e.PostRating = post.PostRating; }
public async Task <ActionResult <ForumPosts> > PutPost(int id, ForumPosts post) { if (id != post.PostID) { return(NotFound()); } repo.UpdatePostAsync(post, id); await repo.SaveChangesAsync(); return(post); }
protected void ForumPosts_DataBound(object sender, EventArgs args) { var pager = ForumPosts.FindControl("ForumPostsPager") as DataPager; if (pager == null) { return; } pager.Visible = pager.PageSize < pager.TotalRowCount; }
public ActionResult Edit([Bind(Include = "ID,Title,Text,ForumGroupID,CreatedBy,CreatedDate")] ForumPosts forumPosts) { if (ModelState.IsValid) { db.Entry(forumPosts).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ForumGroupID = new SelectList(db.ForumGroups, "ID", "Title", forumPosts.ForumGroupID); return(View(forumPosts)); }
public async Task <ForumPosts> DeletePostAsync(int?id) { ForumPosts movie = context.ForumPosts.FirstOrDefault(e => e.PostID == id); if (movie != null) { context.ForumPosts.Remove(movie); await context.SaveChangesAsync(); } return(await Task.FromResult(movie)); }
public Task <int> AddPostAsync(ForumPosts post) { int success = 0; if (post != null) { post.PostID = posts.Count + 1; posts.Add(post); success = 1; } return(Task.FromResult <int>(success)); }
public ActionResult DeletePost(Guid id) { var list = database.ForumComments.Where(q => q.ForumPostID == id); database.ForumComments.RemoveRange(list); ForumPosts post = database.ForumPosts.Find(id); database.ForumPosts.Remove(post); database.SaveChanges(); return(Json(new { state = "success", msg = "با موفقیت انجام شد." }, JsonRequestBehavior.AllowGet)); }
// GET: ForumPosts/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ForumPosts forumPosts = db.ForumPosts.Find(id); if (forumPosts == null) { return(HttpNotFound()); } return(View(forumPosts)); }
[RBAC]//Standard User public ActionResult CreatePost(ForumPosts post) { database.ForumPosts.Add(new ForumPosts { ID = Guid.NewGuid(), Title = post.Title, CreatedDate = DateTime.Now, Text = post.Text, CreatedBy = new Guid(HttpContext.User.Identity.Name), ForumGroupID = post.ForumGroupID }); database.SaveChanges(); return(RedirectToAction("AllPost", new { groupID = post.ForumGroupID })); }
[RBAC]//Standard User public ActionResult EditPost([Bind(Exclude = "ForumGroupID,ID")] ForumPosts post, string id, string ForumGroupID) { post.ID = new Guid(id.ToString().Decrypt()); post.ForumGroupID = new Guid(ForumGroupID.Decrypt()); post.CreatedBy = new Guid(HttpContext.User.Identity.Name); post.CreatedDate = DateTime.Now; database.Entry(post).State = EntityState.Modified; if (ModelState.IsValid) { database.SaveChanges(); } return(RedirectToAction("AllPost", new { groupID = post.ForumGroupID })); }
// GET: ForumPosts/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ForumPosts forumPosts = db.ForumPosts.Find(id); if (forumPosts == null) { return(HttpNotFound()); } ViewBag.ForumGroupID = new SelectList(db.ForumGroups, "ID", "Title", forumPosts.ForumGroupID); return(View(forumPosts)); }
public IActionResult Forum(ForumPosts model) { if (ModelState.IsValid) { model.Name = userManager.GetUserAsync(User).Result; model.Name.Name = model.Name.UserName; model.Date = DateTime.Now; // Store the model in the database repo.AddPost(model); } else { return(View(model)); } return(Redirect("ForumPost")); // displays all messages }
private GlobalCache() { curForumIndex = 0; retries = 0; moduleCacheLoaded = false; forumPostCacheLoaded = new List<bool>(0); modules = new List<Module>(); forumPostTitles = new List<ForumPostTitle>(); forumPosts = new List<ForumPost>(); obsForumPosts = new ForumPosts(); obsForumPostTitles = new ForumPostTitles(); btn_modules = new List<Button>(); uiPostTitle = new List<ForumPost>(); obsUiPostTitle = new ForumPosts(); }
[RBAC]//Standard User public ActionResult EditPost(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ForumPosts item = database.ForumPosts.Find(id); //اگر شخص مورد نظر، پست را ایجاد کرده بود، یا ادمین کل بود if (item.CreatedBy.ToString() == HttpContext.User.Identity.Name || ControllerContext.Controller.IsSysAdmin()) { ViewBag.ForumGroupID = new SelectList(database.ForumGroups, "ID", "Title", item.ForumGroupID); return(View(item)); } else { return(RedirectToAction("Unauthorised")); } }
public void AddBookTest() { // Arrange var repo = new FakeForumsRepository(); var controller = new HomeController(repo); var post = new ForumPosts() { PostTopic = "Low lighting Techniques", Name = new User() { Name = "Me" }, PostText = "Really useful info!" }; // Act controller.Forum(post); // Assert var retrievePost = repo.Posts.ToList()[0]; Assert.Equal(0, System.DateTime.Now.Date.CompareTo(retrievePost.Date.Date)); }
public void UpdatePost(ForumPosts post) { throw new NotImplementedException(); }
public async Task <int> AddPostAsync(ForumPosts post) { context.ForumPosts.Add(post); return(await context.SaveChangesAsync()); }
public void AddPost(ForumPosts forumPost) { context.ForumPosts.Add(forumPost); context.SaveChanges(); }
public void UpdatePost(ForumPosts post) { context.ForumPosts.Update(post); context.SaveChanges(); }
public void AddPost(ForumPosts forumPost) { forumPost.PostID = posts.Count; posts.Add(forumPost); }