public BlogPostCommentModel(BlogPostComment comment) { Id = comment.Id; UserName = comment.AppUser.UserName; Text = comment.Text; Time = comment.Time.ToString("dd/MM/yyyy"); }
protected void btnSubmitComment_Click( object sender, EventArgs e ) { if ( Page.IsValid ) { // save comment Rock.Services.Cms.BlogPostCommentService commentService = new Rock.Services.Cms.BlogPostCommentService(); BlogPostComment comment = new BlogPostComment(); comment.Comment = txtComment.Text; comment.CommentDate = DateTime.Now; comment.EmailAddress = txtEmail.Text; comment.PostId = postId; comment.PersonName = txtName.Text; comment.PersonId = CurrentPersonId; commentService.AddBlogPostComment( comment ); commentService.Save( comment, CurrentPersonId ); // load comments post.BlogPostComments.Add( comment ); LoadComments(); // clear out comment fields txtName.Text = ""; txtEmail.Text = ""; txtComment.Text = ""; } }
public virtual void DeleteBatch(String ids) { if (strUtil.IsNullOrEmpty(ids)) { return; } int[] arrId = cvt.ToIntArray(ids); foreach (int id in arrId) { BlogPostComment c = db.findById <BlogPostComment>(id); if (c == null) { continue; } // 删除评论 db.delete(c); // 重新统计父帖的数量 Type et = Entity.GetType(c.GetTargetType().FullName); IEntity parent = ndb.findById(et, c.RootId); if (parent == null) { continue; } String property = "Replies"; int replies = (int)parent.get(property); parent.set(property, (replies - 1)); db.update(parent, property); } }
public async Task <IActionResult> PostCommentNew(string postId, string comment) { if (!string.IsNullOrWhiteSpace(comment)) { var bp = await _blogDbService.GetBlogPostAsync(postId); if (bp != null) { var blogPostComment = new BlogPostComment { CommentId = Guid.NewGuid().ToString(), PostId = postId, CommentContent = comment, CommentAuthorId = User.Claims.FirstOrDefault(p => p.Type == ClaimTypes.NameIdentifier).Value, CommentAuthorUsername = User.Identity.Name, CommentDateCreated = DateTime.UtcNow }; await _blogDbService.CreateBlogPostCommentAsync(blogPostComment); } } return(RedirectToAction("PostView", new { postId = postId })); }
public override void Layout() { BlogApp blog = ctx.app.obj as BlogApp; blogService.AddHits(blog); set("adminUrl", to(new Admin.MyListController().Index)); bindAppInfo(blog); load("blog.UserMenu", new Users.ProfileController().UserMenu); BlogSetting s = blog.GetSettingsObj(); List <BlogCategory> categories = categoryService.GetByApp(ctx.app.Id); List <BlogPost> newBlogs = postService.GetNewBlog(ctx.app.Id, s.NewBlogCount); //List<BlogPostComment> newComments = commentService.GetNew( ctx.owner.Id, ctx.app.Id, s.NewCommentCount ); List <BlogPostComment> newComments = BlogPostComment.find("AppId=" + ctx.app.Id).list(s.NewCommentCount); List <Blogroll> blogrolls = rollService.GetByApp(ctx.app.Id, ctx.owner.obj.Id); bindBlogroll(blogrolls); bindCategories(categories); bindPostList(newBlogs); bindComments(newComments); }
public ActionResult Delete(int[] ids) { if (ids == null || !ids.Any()) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var model = new BlogPostCommentsViewModel(); model.BlogPostComments = new List <BlogPostCommentViewModel>(); foreach (int id in ids) { BlogPostComment comment = blogPostCommentService.Find(id); if (comment == null) { continue; } model.BlogPostComments.Add(new BlogPostCommentViewModel { Id = comment.Id, Name = comment.Name, }); } return(View(model)); }
public bool InsertBlogComment(BlogPostComment comment) { try { //long BlogPostId, string User, string Email, string HomePage, string Comment)); if (XmlManager.InsertBlogPostComment(Server.MapPath("~/App_Data/BlogComments.xml"), comment.BlogPostId, comment.User, comment.Email, comment.HomePage, comment.Comment)) { string Body = comment.User + " ( " + comment.Email + " ) added a comment for a Blog Post." + System.Environment.NewLine + comment.Comment; Utils.SendEmail("*****@*****.**", "*****@*****.**", "Comment Added for Blog Post: ", Body); return(true); } else { return(false); } } catch (Exception ex) { string Body = "An error was encountered: " + Environment.NewLine + ex.ToString(); Utils.SendEmail("*****@*****.**", "*****@*****.**", "error encountered", Body); return(false); } }
public virtual void UpdateCommentCount(IApp blogApp) { BlogApp blog = blogApp as BlogApp; int count = BlogPostComment.find("AppId=" + blog.Id).count(); blog.CommentCount = count; blog.update("CommentCount"); }
//-------------------------------------------------------------------------- public void AfterCommentInsert( BlogPostComment comment ) { BlogPost post = BlogPost.findById( comment.RootId ); User owner = User.findById( post.OwnerId ); int appId = post.AppId; LayoutCacher.Update( owner, appId ); }
public ActionResult DeleteConfirmed(int id) { BlogPostComment blogPostComment = db.BlogPostComments.Find(id); db.BlogPostComments.Remove(blogPostComment); db.SaveChanges(); return(RedirectToAction("Index")); }
//-------------------------------------------------------------------------- public void AfterCommentInsert(BlogPostComment comment) { BlogPost post = BlogPost.findById(comment.RootId); User owner = User.findById(post.OwnerId); int appId = post.AppId; LayoutCacher.Update(owner, appId); }
private static void updatePost( BlogPostComment comment ) { BlogPost post = BlogPost.findById( comment.RootId ); User owner = User.findById( post.OwnerId ); int appId = post.AppId; BlogLayoutViewCacher.Update( owner, appId ); }
private static void updatePost(BlogPostComment comment) { BlogPost post = BlogPost.findById(comment.RootId); User owner = User.findById(post.OwnerId); int appId = post.AppId; BlogLayoutViewCacher.Update(owner, appId); }
public IActionResult GetCommentArticle(int commentID) { BlogPostComment comment = _dbContext.BlogPostComments.Where(p => (p.BlogPostCommentId == commentID)).First(); if (comment != null) { return(Json(new { result = comment.Article })); } return(Json(new { error = "No article found" })); }
public async Task AddCommentAsync(long blogPostId, BlogPostComment comment) { BlogPost blogPost = await GetAsync(blogPostId); if (blogPost.Comments == null) { blogPost.Comments = new List <BlogPostComment>(); } blogPost.Comments.Add(comment); await _postsDbContext.SaveChangesAsync(); }
public CommentViewModel(BlogPostComment comment) { CommentId = comment.BlogPostCommentId; PostId = comment.BlogPostId; Post = comment.BlogPost; UserId = comment.UserId; User = comment.User; DatePosted = comment.DatePosted; DateEdited = comment.DateEdited; Article = comment.Article; }
//// GET: BlogPostComment //public ActionResult Index() //{ // return View(db.BlogPostComments.ToList()); //} //// GET: BlogPostComment/Details/5 //public ActionResult Details(int? id) //{ // if (id == null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } // BlogPostComment blogPostComment = db.BlogPostComments.Find(id); // if (blogPostComment == null) // { // return HttpNotFound(); // } // return View(blogPostComment); //} // GET: BlogPostComment/Create public ActionResult Create(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BlogPostComment blogPostComment = new BlogPostComment(); blogPostComment.BlogId = id; return(View(blogPostComment)); }
public ActionResult AddComment(BlogPostCommentVM model) { BlogPostComment comment = new BlogPostComment(); comment.Content = model.Content; comment.BlogPostID = model.BlogPostID; comment.EMail = model.EMail; comment.Name = model.Name; db.BlogPostComment.Add(comment); db.SaveChanges(); return(RedirectToAction("Index", "SiteBlog", new { id = model.BlogPostID })); }
public async Task CreateBlogPostCommentAsync(BlogPostComment comment) { //string str = JsonConvert.SerializeObject(comment); //dynamic obj = JsonConvert.DeserializeObject(str); var obj = new dynamic[] { comment.PostId, comment }; //var result = await _blogDbService.GetContainer("database", "container").Scripts.ExecuteStoredProcedureAsync<string>("spCreateToDoItem", new PartitionKey("Personal"), newItem); var result = await _postsContainer.Scripts.ExecuteStoredProcedureAsync <string>("createComment", new PartitionKey(comment.PostId), obj); //await this._postsContainer.CreateItemAsync<BlogPostComment>(comment, new PartitionKey(comment.PostId)); }
public ActionResult AddComment(CommentVM model) { BlogPostComment comment = new BlogPostComment(); comment.Title = model.Title; comment.Content = model.Content; comment.BlogPostID = model.BlogPostId; db.BlogPostComments.Add(comment); db.SaveChanges(); return(RedirectToAction("Index", "SiteBlog", new { id = model.BlogPostId })); }
public ActionResult Edit([Bind(Include = "Id,PostId,ContentOfComment,UserId")] BlogPostComment blogPostComment) { if (ModelState.IsValid) { db.Entry(blogPostComment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PostId = new SelectList(db.BlogPosts, "Id", "PostContent", blogPostComment.PostId); ViewBag.UserId = new SelectList(db.Customers, "Id", "Username", blogPostComment.UserId); return(View(blogPostComment)); }
public ActionResult BlogCommentAdd(int blogPostId, BlogPostModel model) { if (!_blogSettings.Enabled) { return(RedirectToAction("Index", "Home")); } var blogPost = _blogService.GetBlogPostById(blogPostId); if (blogPost == null || !blogPost.AllowComments) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { if (_workContext.CurrentCustomer.IsGuest() && !_blogSettings.AllowNotRegisteredUsersToLeaveComments) { ModelState.AddModelError(string.Empty, _localizationService.GetResource("Blog.Comments.OnlyRegisteredUsersLeaveComments")); } else { var comment = new BlogPostComment() { BlogPostId = blogPost.Id, CustomerId = _workContext.CurrentCustomer.Id, IpAddress = _webHelper.GetCurrentIpAddress(), CommentText = model.AddNewComment.CommentText, IsApproved = true, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow, }; _customerContentService.InsertCustomerContent(comment); if (_blogSettings.NotifyAboutNewBlogComments) { _workflowMessageService.SendBlogCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId); } TempData["fara.blog.addcomment.result"] = _localizationService.GetResource("Blog.Comments.SuccessfullyAdded"); return(RedirectToRoute("BlogPost", new { blogPostId = blogPost.Id, SeName = blogPost.GetSeName() })); } } PrepareBlogPostModel(model, blogPost, true); return(View(model)); }
public async Task <bool> AddComment(BlogPostComment blogPostComment) { using (var dbConnection = Connection) { dbConnection.Open(); return(await dbConnection.ExecuteAsync( "insert into BlogPostComments values(@blogPostId,@comment)", new { blogPostId = blogPostComment.BlogPostId, comment = blogPostComment.Comment }) > 0); } }
public static bool InsertBlogPostComment(string Path, long BlogPostId, string User, string Email, string HomePage, string Comment) { try { List <BlogPostComment> comments = new List <BlogPostComment>(); BlogPostComment comment = new BlogPostComment(); comment.Id = Generate.NewUniqueID; comment.BlogPostId = BlogPostId; comment.User = User; comment.Email = Email; comment.HomePage = HomePage; comment.Comment = Comment; comment.DatePublished = DateTime.Now.ToString(); comment.Active = false; System.Xml.Serialization.XmlSerializer Serializer = new System.Xml.Serialization.XmlSerializer(comments.GetType()); if (System.IO.File.Exists(Path)) { Stream PathStream = File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader objStreamReader = new StreamReader(PathStream); comments = (List <BlogPostComment>)Serializer.Deserialize(objStreamReader); objStreamReader.Close(); PathStream.Close(); PathStream.Dispose(); PathStream = File.Open(Path, FileMode.Truncate, FileAccess.Write, FileShare.Write); StreamWriter objStreamWriter = new StreamWriter(PathStream); comments.Reverse(); comments.Add(comment); Serializer.Serialize(objStreamWriter, comments); objStreamWriter.Close(); } else { comments.Add(comment); Stream PathStream = File.Open(Path, FileMode.Create, FileAccess.Write, FileShare.Write); StreamWriter objStreamWriter = new StreamWriter(PathStream); Serializer.Serialize(objStreamWriter, comments); objStreamWriter.Close(); PathStream.Close(); PathStream.Dispose(); } return(true); } catch (Exception ex) { string Body = "An error was encountered: " + Environment.NewLine + ex.ToString(); Utils.SendEmail("*****@*****.**", "*****@*****.**", "error encountered", Body); return(false); } }
public ActionResult Create([Bind(Include = "Id,PostId,ContentOfComment,UserId")] BlogPostComment blogPostComment) { if (ModelState.IsValid) { db.BlogPostComments.Add(blogPostComment); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PostId = new SelectList(db.BlogPosts, "Id", "PostContent", blogPostComment.PostId); ViewBag.UserId = db.BlogPostComments.Include(b => b.BlogPost).Include(b => b.Customer.Id).SingleOrDefault(b => b.Customer.Id == blogPostComment.UserId); //ViewBag.UserId = new SelectList(db.Customers, "Id", "Username", blogPostComment.UserId); return(View(blogPostComment)); }
// GET: BlogPostComments/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BlogPostComment blogPostComment = db.BlogPostComments.Find(id); if (blogPostComment == null) { return(HttpNotFound()); } return(View(blogPostComment)); }
public bool CreatePostComment(BlogPostComment postComment) { bool flag = false; try { _blogCommentRepository.Add(postComment); _unitOfWork.Commit(); flag = true; } catch { } return(flag); }
public async Task <IActionResult> AddComment(BlogPostComment comment) { if (comment != null && ModelState.IsValid) { var result = await _blogPostsService.AddComment(comment); Thread.Sleep(Constants.Timers.Spinner); if (result) { return(Json(JsonSerializer.Serialize(comment))); } } return(null); }
// GET: BlogPostComments/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BlogPostComment blogPostComment = db.BlogPostComments.Find(id); if (blogPostComment == null) { return(HttpNotFound()); } ViewBag.PostId = new SelectList(db.BlogPosts, "Id", "PostContent", blogPostComment.PostId); ViewBag.UserId = new SelectList(db.Customers, "Id", "Username", blogPostComment.UserId); return(View(blogPostComment)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BlogPostComment comment = blogPostCommentService.Find(id.Value); if (comment == null) { return(HttpNotFound()); } var model = Mapper.Map <BlogPostCommentAddViewModel>(comment); return(View(model)); }
public async Task <bool> AddBlogPostComment(BlogPostComment comment) { if (comment != null) { try { await _blogPostCommentRepository.CreateAsync(comment); return(true); } catch (Exception) { // TODO } } return(false); }
public IActionResult DeleteComment(int commentID) { if (ModelState.IsValid) { BlogPostComment comment = _dbContext.BlogPostComments.Where(c => c.BlogPostCommentId == commentID).FirstOrDefault(); if (comment != null) { if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin")) { _dbContext.BlogPostComments.Remove(comment); _dbContext.SaveChanges(); return(Json(new { result = true })); } return(Json(new { error = "You don't have permission to delete this comment" })); } return(Json(new { error = "No comment found" })); } return(Json(new { error = "Invalid Parameters" })); }
public async Task <ActionResult> Create([Bind(Include = "BlogPostCommentId,BlogId,Comment,CommentedUser,CommentedDateTime")] BlogPostComment blogPostComment) { BlogPost blogPost = await DocumentRepository <BlogPost> .GetItemAsync(blogPostComment.BlogId); if (ModelState.IsValid) { blogPostComment.CommentedUser = User.Identity.Name; blogPostComment.CommentedDateTime = DateTime.Now; if (blogPost.Comments == null) { blogPost.Comments = new List <BlogPostComment>(); } blogPost.Comments.Add(blogPostComment); await DocumentRepository <BlogPost> .UpdateItemAsync(blogPost.BlogId, blogPost); } return(RedirectToAction("Details", "BlogPost", new { id = blogPost.BlogId })); }
public void AfterCommentDelete( BlogPostComment comment ) { }