/// <param name="guid"> guid </param> public Comment Fetch(Guid guid) { using (IDataReader reader = DBComments.GetOne(guid)) { if (reader.Read()) { Comment comment = new Comment(); comment.Guid = new Guid(reader["Guid"].ToString()); comment.ParentGuid = new Guid(reader["ParentGuid"].ToString()); comment.SiteGuid = new Guid(reader["SiteGuid"].ToString()); comment.FeatureGuid = new Guid(reader["FeatureGuid"].ToString()); comment.ModuleGuid = new Guid(reader["ModuleGuid"].ToString()); comment.ContentGuid = new Guid(reader["ContentGuid"].ToString()); comment.UserGuid = new Guid(reader["UserGuid"].ToString()); comment.Title = reader["Title"].ToString(); comment.UserComment = reader["UserComment"].ToString(); comment.UserName = reader["UserName"].ToString(); comment.UserEmail = reader["UserEmail"].ToString(); comment.UserUrl = reader["UserUrl"].ToString(); comment.UserIp = reader["UserIp"].ToString(); comment.CreatedUtc = Convert.ToDateTime(reader["CreatedUtc"]); comment.LastModUtc = Convert.ToDateTime(reader["LastModUtc"]); comment.ModerationStatus = Convert.ToByte(reader["ModerationStatus"]); comment.ModeratedBy = new Guid(reader["ModeratedBy"].ToString()); comment.ModerationReason = reader["ModerationReason"].ToString(); //external properties not stored in mp_Comments comment.UserId = Convert.ToInt32(reader["UserID"]); comment.PostAuthor = reader["PostAuthor"].ToString(); if (comment.PostAuthor.Length == 0) { comment.PostAuthor = comment.UserName; } comment.AuthorEmail = reader["AuthorEmail"].ToString(); if (comment.AuthorEmail.Length == 0) { comment.AuthorEmail = comment.UserEmail; } comment.UserRevenue = Convert.ToDecimal(reader["UserRevenue"]); comment.Trusted = Convert.ToBoolean(reader["Trusted"]); comment.PostAuthorAvatar = reader["PostAuthorAvatar"].ToString(); comment.PostAuthorWebSiteUrl = reader["PostAuthorWebSiteUrl"].ToString(); if (comment.PostAuthorWebSiteUrl.Length == 0) { comment.PostAuthorWebSiteUrl = comment.UserUrl; } return comment; } } return null; }
private void LoadSettings() { pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId); moduleId = WebUtils.ParseInt32FromQueryString("mid", moduleId); itemId = WebUtils.ParseInt32FromQueryString("ItemID", itemId); commentGuid = WebUtils.ParseGuidFromQueryString("c", commentGuid); if (commentGuid == Guid.Empty) { return; } module = GetModule(moduleId, CommentsConfiguration.FeatureGuid); if (module == null) { return; } commentRepository = new CommentRepository(); comment = commentRepository.Fetch(commentGuid); if ((comment.ContentGuid != module.ModuleGuid) || (comment.ModuleGuid != module.ModuleGuid)) { module = null; return; } moduleSettings = ModuleSettings.GetModuleSettings(moduleId); config = new CommentsConfiguration(moduleSettings); currentUser = SiteUtils.GetCurrentSiteUser(); userCanEdit = UserCanEditComment(); commentEditor.SiteGuid = CurrentSite.SiteGuid; commentEditor.SiteId = CurrentSite.SiteId; commentEditor.SiteRoot = SiteRoot; commentEditor.CommentsClosed = !config.AllowComments; //commentEditor.CommentUrl = Request.RawUrl; commentEditor.ContentGuid = module.ModuleGuid; //commentEditor.DefaultCommentTitle = defaultCommentTitle; commentEditor.FeatureGuid = CommentsConfiguration.FeatureGuid; commentEditor.ModuleGuid = module.ModuleGuid; //commentEditor.NotificationAddresses = notificationAddresses; //commentEditor.NotificationTemplateName = notificationTemplateName; commentEditor.RequireCaptcha = false; commentEditor.UserCanModerate = userCanEdit; //commentEditor.Visible = !commentsClosed; commentEditor.CurrentUser = currentUser; commentEditor.UserComment = comment; commentEditor.ShowRememberMe = false; commentEditor.UseCommentTitle = config.AllowCommentTitle; commentEditor.ShowUserUrl = config.AllowWebSiteUrlForComments; //commentEditor.IncludeIpAddressInNotification = includeIpAddressInNotification; //commentEditor.ContainerControl = this; }
private void btnPostComment_Click(object sender, EventArgs e) { if (commentsClosed) { WebUtils.SetupRedirect(this, Request.RawUrl); return; } //string title = txtCommentTitle.Text; //string commentText = edComment.Text; //string userName = txtName.Text; //string userEmail = txtEmail.Text; //string userUrl = txtURL.Text; if (!IsValidComment()) { //PopulateControls(); if (containerControl != null) { containerControl.RefreshAfterPostback(); } //txtCommentTitle.Text = title; //edComment.Text = commentText; //txtName.Text = userName; //txtEmail.Text = userEmail; //txtURL.Text = userUrl; return; } //if (blog == null) { return; } //if (blog.AllowCommentsForDays < 0) //{ // WebUtils.SetupRedirect(this, Request.RawUrl); // return; //} //DateTime endDate = blog.StartDate.AddDays((double)blog.AllowCommentsForDays); //if ((endDate < DateTime.UtcNow) && (blog.AllowCommentsForDays > 0)) return; if (this.chkRememberMe.Checked) { SetCookies(); } Comment comment; if (userComment != null) { comment = userComment; } else { comment = new Comment(); } comment.SiteGuid = SiteGuid; comment.FeatureGuid = FeatureGuid; comment.ModuleGuid = ModuleGuid; comment.ContentGuid = ContentGuid; comment.Title = txtCommentTitle.Text; comment.UserComment = edComment.Text; comment.UserName = txtName.Text; comment.UserUrl = txtURL.Text; comment.UserEmail = txtEmail.Text; if (currentUser != null) { comment.UserGuid = currentUser.UserGuid; comment.UserName = currentUser.Name; comment.UserEmail = currentUser.Email; } comment.UserIp = SiteUtils.GetIP4Address(); if (requireModeration) { comment.ModerationStatus = Comment.ModerationPending; } else { comment.ModerationStatus = Comment.ModerationApproved; } repository.Save(comment); if (comment.ModerationStatus == Comment.ModerationApproved) { if (updateContainerControl != null) { int commentCount = repository.GetCount(comment.ContentGuid, Comment.ModerationApproved); updateContainerControl.UpdateCommentStats( comment.ContentGuid, commentCount); } } if (notificationAddresses.Count > 0) { SendCommentNotificationEmail(); } WebUtils.SetupRedirect(this, Request.RawUrl); //Response.Redirect(CommentUrl, true); //ScriptManager.RegisterStartupScript(this, // this.GetType(), // "blog" + moduleGuid.ToString().Replace("-",string.Empty), // "location.href = '" + Request.RawUrl + "'", // true); }
///// <summary> ///// Gets an IList with page of instances of Comment. ///// </summary> ///// <param name="pageNumber">The page number.</param> ///// <param name="pageSize">Size of the page.</param> ///// <param name="totalPages">total pages</param> //public List<Comment> GetPage(int pageNumber, int pageSize, out int totalPages) //{ // totalPages = 1; // IDataReader reader = DBComment.GetPage(pageNumber, pageSize, out totalPages); // return LoadListFromReader(reader); //} private List <Comment> LoadListFromReader(IDataReader reader) { List <Comment> commentList = new List <Comment>(); try { while (reader.Read()) { Comment comment = new Comment(); comment.Guid = new Guid(reader["Guid"].ToString()); comment.ParentGuid = new Guid(reader["ParentGuid"].ToString()); comment.SiteGuid = new Guid(reader["SiteGuid"].ToString()); comment.FeatureGuid = new Guid(reader["FeatureGuid"].ToString()); comment.ModuleGuid = new Guid(reader["ModuleGuid"].ToString()); comment.ContentGuid = new Guid(reader["ContentGuid"].ToString()); comment.UserGuid = new Guid(reader["UserGuid"].ToString()); comment.Title = reader["Title"].ToString(); comment.UserComment = reader["UserComment"].ToString(); comment.UserName = reader["UserName"].ToString(); comment.UserEmail = reader["UserEmail"].ToString(); comment.UserUrl = reader["UserUrl"].ToString(); comment.UserIp = reader["UserIp"].ToString(); comment.CreatedUtc = Convert.ToDateTime(reader["CreatedUtc"]); comment.LastModUtc = Convert.ToDateTime(reader["LastModUtc"]); comment.ModerationStatus = Convert.ToByte(reader["ModerationStatus"]); comment.ModeratedBy = new Guid(reader["ModeratedBy"].ToString()); comment.ModerationReason = reader["ModerationReason"].ToString(); //external properties not stored in mp_Comments comment.UserId = Convert.ToInt32(reader["UserID"]); comment.PostAuthor = reader["PostAuthor"].ToString(); if (comment.PostAuthor.Length == 0) { comment.PostAuthor = comment.UserName; } comment.AuthorEmail = reader["AuthorEmail"].ToString(); if (comment.AuthorEmail.Length == 0) { comment.AuthorEmail = comment.UserEmail; } comment.UserRevenue = Convert.ToDecimal(reader["UserRevenue"]); comment.Trusted = Convert.ToBoolean(reader["Trusted"]); comment.PostAuthorAvatar = reader["PostAuthorAvatar"].ToString(); comment.PostAuthorWebSiteUrl = reader["PostAuthorWebSiteUrl"].ToString(); if (comment.PostAuthorWebSiteUrl.Length == 0) { comment.PostAuthorWebSiteUrl = comment.UserUrl; } commentList.Add(comment); } } finally { reader.Close(); } return(commentList); }
///// <summary> ///// Gets an IList with page of instances of Comment. ///// </summary> ///// <param name="pageNumber">The page number.</param> ///// <param name="pageSize">Size of the page.</param> ///// <param name="totalPages">total pages</param> //public List<Comment> GetPage(int pageNumber, int pageSize, out int totalPages) //{ // totalPages = 1; // IDataReader reader = DBComment.GetPage(pageNumber, pageSize, out totalPages); // return LoadListFromReader(reader); //} private List<Comment> LoadListFromReader(IDataReader reader) { List<Comment> commentList = new List<Comment>(); try { while (reader.Read()) { Comment comment = new Comment(); comment.Guid = new Guid(reader["Guid"].ToString()); comment.ParentGuid = new Guid(reader["ParentGuid"].ToString()); comment.SiteGuid = new Guid(reader["SiteGuid"].ToString()); comment.FeatureGuid = new Guid(reader["FeatureGuid"].ToString()); comment.ModuleGuid = new Guid(reader["ModuleGuid"].ToString()); comment.ContentGuid = new Guid(reader["ContentGuid"].ToString()); comment.UserGuid = new Guid(reader["UserGuid"].ToString()); comment.Title = reader["Title"].ToString(); comment.UserComment = reader["UserComment"].ToString(); comment.UserName = reader["UserName"].ToString(); comment.UserEmail = reader["UserEmail"].ToString(); comment.UserUrl = reader["UserUrl"].ToString(); comment.UserIp = reader["UserIp"].ToString(); comment.CreatedUtc = Convert.ToDateTime(reader["CreatedUtc"]); comment.LastModUtc = Convert.ToDateTime(reader["LastModUtc"]); comment.ModerationStatus = Convert.ToByte(reader["ModerationStatus"]); comment.ModeratedBy = new Guid(reader["ModeratedBy"].ToString()); comment.ModerationReason = reader["ModerationReason"].ToString(); //external properties not stored in mp_Comments comment.UserId = Convert.ToInt32(reader["UserID"]); comment.PostAuthor = reader["PostAuthor"].ToString(); if (comment.PostAuthor.Length == 0) { comment.PostAuthor = comment.UserName; } comment.AuthorEmail = reader["AuthorEmail"].ToString(); if (comment.AuthorEmail.Length == 0) { comment.AuthorEmail = comment.UserEmail; } comment.UserRevenue = Convert.ToDecimal(reader["UserRevenue"]); comment.Trusted = Convert.ToBoolean(reader["Trusted"]); comment.PostAuthorAvatar = reader["PostAuthorAvatar"].ToString(); comment.PostAuthorWebSiteUrl = reader["PostAuthorWebSiteUrl"].ToString(); if (comment.PostAuthorWebSiteUrl.Length == 0) { comment.PostAuthorWebSiteUrl = comment.UserUrl; } commentList.Add(comment); } } finally { reader.Close(); } return commentList; }
/// <summary> /// Persists a new instance of Comment. /// </summary> /// <returns></returns> public void Save(Comment comment) { if (comment == null) { return; } if (comment.Guid == Guid.Empty) { comment.Guid = Guid.NewGuid(); DBComments.Create( comment.Guid, comment.ParentGuid, comment.SiteGuid, comment.FeatureGuid, comment.ModuleGuid, comment.ContentGuid, comment.UserGuid, comment.Title, comment.UserComment, comment.UserName, comment.UserEmail, comment.UserUrl, comment.UserIp, comment.CreatedUtc, comment.ModerationStatus, comment.ModeratedBy, comment.ModerationReason); } else { DBComments.Update( comment.Guid, comment.UserGuid, comment.Title, comment.UserComment, comment.UserName, comment.UserEmail, comment.UserUrl, comment.UserIp, comment.LastModUtc, comment.ModerationStatus, comment.ModeratedBy, comment.ModerationReason); } }