/// <summary> /// 取 顶级评论 及下的子评论 /// </summary> /// <param name="com"></param> /// <param name="list"></param> /// <returns></returns> private List <BlogComments> GetCom(BlogComments com, List <BlogComments> list) { var li = list.Where(t => t.ToCommentId == com.BlogCommentId).ToList(); li.Insert(0, com); return(li); }
public async Task <IActionResult> Edit(int id, [Bind("BlogCommentsId,Comment,UserProfileId,BlogId")] BlogComments blogComments) { if (id != blogComments.BlogCommentsId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(blogComments); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BlogCommentsExists(blogComments.BlogCommentsId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BlogId"] = new SelectList(_context.BlogArticle, "BlogArticleId", "BlogText", blogComments.BlogId); ViewData["UserProfileId"] = new SelectList(_context.UserProfile, "UserProfileId", "FirstName", blogComments.UserProfileId); return(View(blogComments)); }
public async Task <IActionResult> PutBlogComment([FromRoute] int id, [FromBody] BlogComments blogComment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != blogComment.BlogCommentsId) { return(BadRequest()); } try { await _blogCommentsRepository.Update(blogComment); return(Ok(blogComment)); } catch (DbUpdateConcurrencyException) { if (!await BlogCommentExists(id)) { return(NotFound()); } else { throw; } } }
public async Task <BlogComments> Update(BlogComments blogComment) { _context.BlogComments.Update(blogComment); await _context.SaveChangesAsync(); return(blogComment); }
public async Task <BlogComments> Add(BlogComments blogComment) { await _context.BlogComments.AddAsync(blogComment); await _context.SaveChangesAsync(); return(blogComment); }
public bool Insert(BlogComments blogComment) { blogComment.CommentingDate = DateTime.Now; db.BlogComments.Add(blogComment); if (db.SaveChanges() > 0) { return(true); } return(false); }
public async Task <IActionResult> Create([Bind("BlogCommentsId,Comment,UserProfileId,BlogId")] BlogComments blogComments) { if (ModelState.IsValid) { _context.Add(blogComments); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BlogId"] = new SelectList(_context.BlogArticle, "BlogArticleId", "BlogText", blogComments.BlogId); ViewData["UserProfileId"] = new SelectList(_context.UserProfile, "UserProfileId", "FirstName", blogComments.UserProfileId); return(View(blogComments)); }
public async Task <IActionResult> PostBlogComment([FromBody] BlogComments blogComment, [FromHeader] string UserName) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Models.Users user = _bUsersRepository.GetAll().Where(P => P.UserName == UserName).FirstOrDefault(); // blogComment.UserId = user.UserId; await _blogCommentsRepository.Add(blogComment); return(CreatedAtAction("GetBlogComments", new { id = blogComment.BlogId }, blogComment)); }
public ActionResult DeleteConfirmed(int id) { try { BlogComments blogComments = db.BlogComments.Find(id); db.BlogComments.Remove(blogComments); db.SaveChanges(); TempData["Notice_Delete_Success"] = true; } catch (Exception) { TempData["Notice_Delete_Fail"] = true; } return(RedirectToAction("Index")); }
// GET: Admin/BlogComments/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BlogComments blogComments = db.BlogComments.Find(id); Blogs blogs = db.Blogs.Find(blogComments.BlogID); ViewBag.Blog = blogs.BlogName; if (blogComments == null) { return(HttpNotFound()); } return(View(blogComments)); }
public ActionResult BlogComment(BlogComments blog, int Id) { int userId = GetLoggedInUserId(); if (userId > 0) { var _blog = _context.BlogComments.FirstOrDefault(o => o.BlogId == blog.BlogId && o.UserId == userId); if (_blog == null) { blog.UserId = userId; _context.BlogComments.Add(blog); _context.SaveChanges(); } return(RedirectToAction("Detail", "Blog", new { id = blog.BlogId })); } return(RedirectToAction("LogIn", "User", new { blogId = blog.BlogId })); }
public IActionResult detail(BlogsModel model) { var setupValues = _setupRepo.getQueryable().ToList(); ViewBag.setup = setupValues; var notice = _noticeRepo.getQueryable().Where(n => n.notice_expiry_date >= DateTime.Now && n.is_closed == false).Take(5).ToList(); ViewBag.notices = notice; try { var blogDetails = _blogRepo.getBySlug(model.slug); //Blog model.blog_id = blogDetails.blog_id; model.artical_by = blogDetails.artical_by; model.description = blogDetails.description; model.image_name = blogDetails.image_name; model.posted_on = blogDetails.posted_on;; model.title = blogDetails.title; model.is_enabled = blogDetails.is_enabled; model.slug = blogDetails.slug; var blogcomments = _blogCommentRepo.getQueryable().Where(a => a.blog_id == model.blog_id).ToList(); List <BlogComments> blogComments = new List <BlogComments>(); foreach (var comment in blogcomments) { BlogComments blogcomment = new BlogComments(); blogcomment.comments = comment.comments; blogcomment.comment_by = comment.comment_by; blogcomment.comment_date = comment.comment_date; blogcomment.email = comment.email; blogComments.Add(blogcomment); } model.blog_comments = blogComments; } catch (Exception ex) { AlertHelper.setMessage(this, ex.Message, messageType.error); } return(View(model)); }
public IActionResult Comment(CommentViewModel model) { if (ModelState.IsValid) { var Comment = new BlogComments() { UserName = model.UserName, UserId = userManager.GetUserId(User), BlogPostId = model.PostId, Body = model.Comment, TimeOfComment = DateTime.Now, UserPicture = model.ProfilePicture, }; _commentRepository.Comment(Comment); _blogPostRepository.GetBlogPost(model.PostId).NumberOfComments = context.BlogComments.Where(x => x.BlogPostId == model.PostId).Count(); context.SaveChanges(); return(RedirectToAction("Details", new { id = Comment.BlogPostId })); } return(View()); }
public ActionResult AddComment(string txtFullName, string txtPhone, string txtEmail, string txaComment, int?BlogID) { if (BlogID == null) { return(RedirectToAction("Error", "Home")); } if (txtFullName == null || txtPhone == null || txtEmail == null || txaComment == null) { ViewBag.ErrorMessage = "Please complete the form before submitting"; return(RedirectToAction("BlogDetail", "Blog", new { id = BlogID })); } var cmt = new BlogComments(); cmt.FullName = txtFullName; cmt.Phone = txtPhone; cmt.Email = txtEmail; cmt.Comment = txaComment; cmt.BlogID = BlogID; var blogComment = new BlogCommentDAO(); bool isValid = false; try { isValid = blogComment.Insert(cmt); } catch (Exception) { ViewBag.ErrorMessage = "Please complete the form before submitting"; return(RedirectToAction("BlogDetail", "Blog", new { id = BlogID })); } if (isValid == true) { TempData["Notice_Submit_Success"] = true; return(RedirectToAction("BlogDetail", "Blog", new { id = cmt.BlogID })); } return(RedirectToAction("BlogDetail", "Blog", new { id = cmt.BlogID })); }
public IHttpActionResult InsertComments(string Message, int Post_id, int UserId) { try { using (DunkeyContext ctx = new DunkeyContext()) { if (UserId == 0) { UserId = ctx.Users.FirstOrDefault(x => x.Email == DunkeyDelivery.Utility.GuestEmail).Id; } BlogComments Comment = new BlogComments { Message = Message, PostedDate = DateTime.Now, CreatedDate = DateTime.Now, User_Id = UserId, Post_Id = Post_id }; var BlogData = ctx.BlogPosts.Where(x => x.Id == Post_id).FirstOrDefault(); BlogData.BlogComments.Add(Comment); ctx.SaveChanges(); CustomResponse <BlogComments> response = new CustomResponse <BlogComments> { Message = DunkeyDelivery.Global.SuccessMessage, StatusCode = (int)HttpStatusCode.OK, Result = Comment }; return(Ok(response)); } } catch (Exception ex) { return(StatusCode(DunkeyDelivery.Utility.LogError(ex))); } }