private ForumFile SaveAttachment(ForumPost post, HtmlInputFile file) { ForumFile fFile = new ForumFile(); if(file.PostedFile==null || file.PostedFile.FileName.Trim().Length==0 || file.PostedFile.ContentLength==0) return null; string sUpDir = Server.MapPath(UrlHelper.GetApplicationPath() + "/Modules/Forum/Attach/"); string filename = file.PostedFile.FileName; if(!System.IO.Directory.Exists(sUpDir)) { System.IO.Directory.CreateDirectory(sUpDir); } int pos = filename.LastIndexOfAny(new char[]{'/','\\'}); if (pos >= 0) filename = filename.Substring(pos+1); string newfilename = String.Format("{0}{1}.{2}",sUpDir,post.Id,filename); file.PostedFile.SaveAs(newfilename); fFile.OrigFileName = filename; fFile.ForumFileName = newfilename; fFile.FileSize = file.PostedFile.ContentLength; fFile.ContentType = file.PostedFile.ContentType; try { base.ForumModule.SaveForumFile(fFile); } catch(Exception ex) { throw new Exception("Unable to save file",ex); } return fFile; }
private void btnPost_Click(object sender, System.EventArgs e) { if(this.Page.IsValid) { Cuyahoga.Core.Domain.User tUser = this.Page.User.Identity as User; HttpPostedFile postedFile = this.txtAttachment.PostedFile; ForumFile fFile; ForumPost tForumPost = new ForumPost(); tForumPost.ForumId = base.ForumModule.CurrentForumId; tForumPost.DateCreated = DateTime.Now; tForumPost.Message = TextParser.ForumCodeToHtml(this.txtMessage.Text,base.ForumModule); tForumPost.Topic = this.txtSubject.Text; if(tUser != null) { tForumPost.UserId = tUser.Id; tForumPost.UserName = tUser.UserName; } else { tForumPost.UserId = 0; tForumPost.UserName = base.GetText("GUEST"); } base.ForumModule.SaveForumPost(tForumPost); // Save attachement if(postedFile.ContentLength > 0) { try { this.CheckValidFile(this.txtAttachment); fFile = this.SaveAttachment(tForumPost,this.txtAttachment); tForumPost.AttachmentId = fFile.Id; base.ForumModule.SaveForumPost(tForumPost); } catch(Exception ex) { this.pnlUploadError.Visible = true; this.ltlUploadError.Text = ex.Message; base.ForumModule.DeleteForumPost(tForumPost); return; } } // Update number of topics and number of posts ForumForum tForumForum = base.ForumModule.GetForumById(base.ForumModule.CurrentForumId); tForumForum.NumTopics++; tForumForum.NumPosts++; tForumForum.LastPosted = DateTime.Now; tForumForum.LastPostUserName = tForumPost.UserName; tForumForum.LastPostId = tForumPost.Id; base.ForumModule.SaveForum(tForumForum); Response.Redirect(String.Format("{0}/ForumView/{1}",UrlHelper.GetUrlFromSection(base.ForumModule.Section), base.ForumModule.CurrentForumId)); } }
protected void lbtnRemove_Click(object sender, EventArgs e) { LinkButton lbtnRemoveTemp = (LinkButton)sender; if (!lbtnRemoveTemp.Parent.GetType().Equals(typeof(RepeaterItem)) ) { foreach (RepeaterItem item in this.rptForumPostRepliesList.Items) { LinkButton lbtnRemoveTemp2 = (LinkButton)item.FindControl("lbtnRemove"); ForumPost postTemp = this._module.GetForumPostById(int.Parse(lbtnRemoveTemp2.CommandArgument)); if (postTemp.AttachmentId != 0) { ForumFile fFile = this._module.GetForumFileById(postTemp.AttachmentId); this._module.DeleteForumFile(fFile); } this._module.DeleteForumPost(postTemp); } this._forumPost = this._module.GetForumPostById(this._module.CurrentForumPostId); if (this._forumPost.AttachmentId != 0) { ForumFile fFile = this._module.GetForumFileById(this._forumPost.AttachmentId); this._module.DeleteForumFile(fFile); } this._module.DeleteForumPost(this._forumPost); Response.Redirect(String.Format("{0}/ForumView/{1}", UrlHelper.GetUrlFromSection(base.ForumModule.Section), base.ForumModule.CurrentForumId)); } else { ForumPost post = this._module.GetForumPostById(int.Parse(lbtnRemoveTemp.CommandArgument)); if (post.AttachmentId != 0) { ForumFile fFile = this._module.GetForumFileById(post.AttachmentId); this._module.DeleteForumFile(fFile); } this._module.DeleteForumPost(post); Response.Redirect(String.Format("{0}/ForumViewPost/{1}/PostId/{2}", UrlHelper.GetUrlFromSection(base.ForumModule.Section), base.ForumModule.CurrentForumId, base.ForumModule.CurrentForumPostId)); } }
private void BindForumPost() { this._forumPost = this._module.GetForumPostById(this._module.CurrentForumPostId); this._forumPost.Views++; this._module.SaveForumPost(this._forumPost); this.lblTopic.Text = this._forumPost.Topic; if(this._forumPost.UserId == 0) { this.hplAuthor.Text = "Guest"; this.hplAuthor.CssClass = "forum"; this.lblUserInfo.Text = " "; } else { this.hplAuthor.Text = this._forumPost.UserName; this.hplAuthor.NavigateUrl = String.Format("{0}/ForumViewProfile/{1}",UrlHelper.GetUrlFromSection(this._module.Section), this._forumPost.UserId); this.hplAuthor.CssClass = "forum"; this.lblUserInfo.Text = " "; } string msg = this._forumPost.Message; this.lblMessages.Text = this._forumPost.Message; this.lblPostedDate.Text = TimeZoneUtil.AdjustDateToUserTimeZone(this._forumPost.DateCreated, this.Page.User.Identity).ToLongDateString() + " " +TimeZoneUtil.AdjustDateToUserTimeZone(this._forumPost.DateCreated, this.Page.User.Identity).ToLongTimeString(); if(this._forumPost.AttachmentId != 0) { ForumFile fFile = this._module.GetForumFileById(this._forumPost.AttachmentId); this.pnlAttachment.Visible = true; this.hplPostAttachment.NavigateUrl = String.Format("{0}/ForumViewPost/{1}/PostId/{2}/Download/{3}",UrlHelper.GetUrlFromSection(this._module.Section), this._forumPost.ForumId,this._forumPost.Id,this._forumPost.AttachmentId); this.hplPostAttachment.Text = fFile.OrigFileName; this.hplPostAttachment.ToolTip = String.Format("{0} - {1} bytes",fFile.OrigFileName,fFile.FileSize); this.ltlFileinfo.Text = String.Format(GetText("attachinfo"),fFile.FileSize,fFile.DlCount); } User cuyahogaUser = this.Page.User.Identity as User; if (cuyahogaUser != null) { if (cuyahogaUser.CanEdit(this._module.Section)) { this.lbtnRemove.Visible = true; } } }
public virtual void SaveForumPost(ForumPost forumpost) { ISession session = this._sessionManager.OpenSession(); NHibernate.ITransaction tx = session.BeginTransaction(); try { session.SaveOrUpdate(forumpost); tx.Commit(); session.Close(); } catch (Exception ex) { tx.Rollback(); throw new Exception("Unable to save Forum post", ex); } }
private void Page_Load(object sender, System.EventArgs e) { this._origPost = base.ForumModule.GetForumPostById(base.ForumModule.CurrentForumPostId); this._forumForum = base.ForumModule.GetForumById(base.ForumModule.CurrentForumId); base.ForumModule.CurrentForumCategoryId = this._forumForum.CategoryId; this.BindTopFooter(); base.LocalizeControls(); this.ltOrigPost.Text = this._origPost.Message; this.BindJS(); this.BindEmoticon(); if(!this.IsPostBack) { if(base.ForumModule.QuotePost == 1) { this.txtMessage.Text = "[quote]" + TextParser.HtmlToForumCode(this._origPost.Message,base.ForumModule) + "[/quote]"; } } }