public void ProcessRequest(HttpContext context) { string url = string.Empty; long anchorPostId = context.Request.QueryString.Get <long>("anchorPostId"); BarPostService barPostService = new BarPostService(); BarPost post = barPostService.Get(anchorPostId); if (post == null) { WebUtility.Return404(context); } IBarUrlGetter urlGetter = BarUrlGetterFactory.Get(post.TenantTypeId); if (post != null) { int?childPostIndex = 0; if (post.ParentId != 0) { childPostIndex = barPostService.GetPageIndexForChildrenPost(post.ParentId, post.PostId); } int pageIndex = barPostService.GetPageIndexForPostInThread(post.ThreadId, anchorPostId); url = urlGetter.ThreadDetail(post.ThreadId, pageIndex: pageIndex, anchorPostId: anchorPostId, childPostIndex: childPostIndex); } context.Response.RedirectPermanent(url); }
/// <summary> /// 转换成BarPost类型 /// </summary> /// <returns></returns> public BarPost AsBarPost() { BarThread thread = new BarThreadService().Get(this.ThreadId); BarPostService service = new BarPostService(); BarPost post = null; //编辑的情况 if (this.PostId.HasValue) { post = service.Get(this.PostId ?? 0); if (post == null) { return(null); } } else { //创建的情况 post = BarPost.New(); post.AuditStatus = AuditStatus.Success; post.TenantTypeId = thread.TenantTypeId; post.ThreadId = this.ThreadId; if (UserContext.CurrentUser != null) { post.UserId = UserContext.CurrentUser.UserId; post.Author = UserContext.CurrentUser.DisplayName; } else { post.UserId = 0; post.Author = "匿名用户"; } post.OwnerId = thread == null ? 0 : thread.OwnerId; post.SectionId = thread == null ? 0 : thread.SectionId; post.ParentId = this.ParentId; } if (!string.IsNullOrEmpty(this.Body)) { post.Body = this.Body; } else { this.MultilineBody = WebUtility.HtmlEncode(this.MultilineBody); this.MultilineBody = new EmotionService().EmoticonTransforms(this.MultilineBody); post.Body = this.MultilineBody; } return(post); }
public AssociatedInfo GetAssociatedInfo(long associateId, string tenantTypeId = "") { BarPostService barPostService = new BarPostService(); BarPost barPost = barPostService.Get(associateId); if (barPost == null) { return(null); } BarThread barThread = new BarThreadService().Get(barPost.ThreadId); if (barThread != null) { IBarUrlGetter urlGetter = BarUrlGetterFactory.Get(barThread.TenantTypeId); return(new AssociatedInfo() { DetailUrl = urlGetter.ThreadDetail(barThread.ThreadId, anchorPostId: barPost.PostId), Subject = barThread.Subject }); } return(null); }