Exemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString.Get("Id")))
        {
            _id = Convert.ToInt32(Request.QueryString.Get("Id"));
        }

        if (!Page.IsPostBack && _id > -1)
        {
            ViewForum viewForum = (from f in myEntities.ForumReplies
                                   join v in myEntities.ViewForums on f.ViewForumId equals v.Id
                                   where f.Id == _id
                                   select v).Single();
            ForumReply forumReply = myEntities.ForumReplies.Where(f => f.Id == _id).Single();
            if (viewForum != null)
            {
                TitleLinkButton.Text = viewForum.Title;

                EditTitleTextBox.Text = viewForum.Title;   //编辑框内显示待编辑的标题
            }
            if (forumReply != null)
            {
                EditContentTextBox.Text = forumReply.ReplyContent;
            }
        }
    }
Exemplo n.º 2
0
        public async Task <Result> SendUpdatePost(ForumReply forumReplyEntity)
        {
            var result = new Result();

            try
            {
                var form = new MultipartFormDataContent
                {
                    { new StringContent("updatepost"), "action" },
                    { new StringContent(forumReplyEntity.PostId.ToString()), "postid" },
                    { new StringContent(HtmlEncode(forumReplyEntity.Message)), "message" },
                    { new StringContent(forumReplyEntity.ParseUrl.ToString()), "parseurl" },
                    { new StringContent(forumReplyEntity.Bookmark), "bookmark" },
                    { new StringContent("2097152"), "MAX_FILE_SIZE" },
                    { new StringContent("Save Changes"), "submit" }
                };
                result = await _webManager.PostFormData(EndPoints.EditPost, form);

                return(result);
            }
            catch (Exception)
            {
                return(result);
            }
        }
Exemplo n.º 3
0
        public async Task <Post> CreatePreviewPostAsync(ForumReply forumReplyEntity, CancellationToken token = default)
        {
            if (forumReplyEntity == null)
            {
                throw new ArgumentNullException(nameof(forumReplyEntity));
            }

            using var form = new MultipartFormDataContent
                  {
                      { new StringContent("postreply"), "action" },
                      { new StringContent(forumReplyEntity.ThreadId), "threadid" },
                      { new StringContent(forumReplyEntity.FormKey), "formkey" },
                      { new StringContent(forumReplyEntity.FormCookie), "form_cookie" },
                      { new StringContent(HtmlHelpers.HtmlEncode(forumReplyEntity.Message)), "message" },
                      { new StringContent(forumReplyEntity.ParseUrl.ToString()), "parseurl" },
                      { new StringContent("2097152"), "MAX_FILE_SIZE" },
                      { new StringContent("Submit Reply"), "submit" },
                      { new StringContent("Preview Reply"), "preview" },
                  };

            // We post to SA the same way we would for a normal reply, but instead of getting a redirect back to the
            // thread, we'll get redirected to back to the reply screen with the preview message on it.
            // From here we can parse that preview and return it to the user.
            var result = await this.webManager.PostFormDataAsync(EndPoints.NewReply, form).ConfigureAwait(false);

            var document = await this.webManager.Parser.ParseDocumentAsync(result.ResultHtml, token).ConfigureAwait(false);

            return(new Post {
                PostHtml = document.QuerySelector(".postbody").InnerHtml
            });
        }
Exemplo n.º 4
0
        public async Task <Result> SendPost(ForumReply forumReplyEntity)
        {
            var result = new Result();

            try
            {
                var form = new MultipartFormDataContent
                {
                    { new StringContent("postreply"), "action" },
                    { new StringContent(forumReplyEntity.ThreadId), "threadid" },
                    { new StringContent(forumReplyEntity.FormKey), "formkey" },
                    { new StringContent(forumReplyEntity.FormCookie), "form_cookie" },
                    { new StringContent(HtmlEncode(forumReplyEntity.Message)), "message" },
                    { new StringContent(forumReplyEntity.ParseUrl.ToString()), "parseurl" },
                    { new StringContent("2097152"), "MAX_FILE_SIZE" },
                    { new StringContent("Submit Reply"), "submit" }
                };
                result = await _webManager.PostFormData(EndPoints.NewReply, form);

                return(result);
            }
            catch (Exception)
            {
                return(result);
            }
        }
        public async Task Init(ThreadReply parameter)
        {
            if (WebManager == null)
            {
                LoginUser();
            }

            _replyManager = new ReplyManager(WebManager);

            Selected = parameter;

            if (Selected.IsEdit)
            {
                Title       = "Edit - " + Selected.Thread.Name;
                _forumReply = await _replyManager.GetReplyCookiesForEditAsync(Selected.QuoteId);

                ReplyBox.Text = _forumReply.Quote;
            }
            else if (Selected.QuoteId > 0)
            {
                Title       = "Quote - " + Selected.Thread.Name;
                _forumReply = await _replyManager.GetReplyCookiesAsync(0, Selected.QuoteId);

                ReplyBox.Text = _forumReply.Quote;
            }
            else
            {
                Title       = "Reply - " + Selected.Thread.Name;
                _forumReply = await _replyManager.GetReplyCookiesAsync(Selected.Thread.ThreadId);
            }
        }
Exemplo n.º 6
0
        public async Task <ForumReply> GetReplyCookiesAsync(long threadId = 0, long postId = 0, CancellationToken token = default)
        {
            if (threadId == 0 && postId == 0)
            {
                throw new FormatException(Awful.Core.Resources.ExceptionMessages.ThreadAndPostIdMissing);
            }

            string url;

            url = threadId > 0 ? string.Format(CultureInfo.InvariantCulture, EndPoints.ReplyBase, threadId) : string.Format(CultureInfo.InvariantCulture, EndPoints.QuoteBase, postId);
            var result = await this.webManager.GetDataAsync(url, token).ConfigureAwait(false);

            var document = await this.webManager.Parser.ParseDocumentAsync(result.ResultHtml, token).ConfigureAwait(false);

            var    inputs           = document.QuerySelectorAll("input");
            var    posts            = ThreadHandler.ParsePreviousPosts(document);
            var    forumReplyEntity = new ForumReply();
            string quote            = System.Net.WebUtility.HtmlDecode(document.QuerySelector("textarea").TextContent);

            forumReplyEntity.MapThreadInformation(
                inputs["formkey"].GetAttribute("value"),
                inputs["form_cookie"].GetAttribute("value"),
                quote,
                inputs["threadid"].GetAttribute("value"));
            forumReplyEntity.ForumPosts.AddRange(posts);
            return(forumReplyEntity);
        }
Exemplo n.º 7
0
        public async Task <ForumReply> GetReplyCookiesAsync(long threadId = 0, long postId = 0)
        {
            if (threadId == 0 && postId == 0)
            {
                return(new ForumReply());
            }
            string url;

            url = threadId > 0 ? string.Format(EndPoints.ReplyBase, threadId) : string.Format(EndPoints.QuoteBase, postId);
            var result = await _webManager.GetDataAsync(url);

            var    document         = _webManager.Parser.Parse(result.ResultHtml);
            var    inputs           = document.QuerySelectorAll("input");
            var    posts            = ThreadHandler.ParsePreviousPosts(document);
            var    forumReplyEntity = new ForumReply();
            string quote            = System.Net.WebUtility.HtmlDecode(document.QuerySelector("textarea").TextContent);

            forumReplyEntity.MapThreadInformation(
                inputs["formkey"].GetAttribute("value"),
                inputs["form_cookie"].GetAttribute("value"),
                quote,
                inputs["threadid"].GetAttribute("value")
                );
            forumReplyEntity.ForumPosts = posts;
            return(forumReplyEntity);
        }
Exemplo n.º 8
0
        public async Task SeedAsync(ApplicationDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext.ForumThreads.Any())
            {
                return;
            }

            var userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();

            var reply = new ForumReply
            {
                Content    = "Today was Sunday for me and I played poker all day and boy it was rough! I took a swing down to -$234 and then fought my way back to -$35.63 over 10k hands at Zoom 25M... My poker bankroll re - build is going OK. I'm saving all my Stars coins for rainy day to convert into cash if needed.  <br><br>Anyway, I just got this PokerStars mods called \"HM Classic Theme\" from pokergrahics and It includes card mods in the package deal.I just tried it out today and it was much easier on the eyes than the stock themes which allowed me to play longer and to see better so I highly recommend this mods in case you wanna chase loss all day long like I did. <br><br><img src = \"https://imagizer.imageshack.us/v2/800x600q90/923/zkktje.png\" alt = \"\" class=\"customerPost-Images\"><br><br><img src = \"https://imagizer.imageshack.us/v2/800x600q90/924/S6FGuy.png\" alt=\"\" class=\"customerPost-Images\">",
                CreatedOn  = DateTime.UtcNow,
                PostedById = "THEveryBESTadminID",
            };

            var replies = new List <ForumReply>();

            replies.Add(reply);

            await dbContext.ForumThreads.AddAsync(new ForumThread
            {
                Title      = "Hello fans of Stud8!",
                PostedBy   = userManager.Users.Where(x => x.UserName == "*****@*****.**").FirstOrDefault(),
                Content    = "Hi, I recently started playing online poker again trying to re - build my bankroll from money I already had(about $500) which I wasn't using at PokerStars. <br><br>I'm sure that everyone on PokerStars plays the card match gig for little cash but in 67K hands over the last 10 days I have never won more than $2 at a time.  So, that's what it takes to win $10 on that thing!! <br><br><img src = \"https://imagizer.imageshack.us/v2/800x600q90/924/T5E9Bh.png\" alt = \"\" class=\"customerPost-Images\"><br><img src = \"https://imagizer.imageshack.us/v2/800x600q90/924/EYgRyV.png\" alt=\"\" class=\"customerPost - Images\">",
                CategoryId = 1,
                Replies    = replies,
            });


            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 9
0
        //添加回帖
        bool AddReply(ReplyModel rm)
        {
            //查询主贴
            var host = adb.ForumHosts.Where(a => a.Id == rm.fid).FirstOrDefault();

            //修改主贴的回复数量(没回复一条增加1)
            host.replyCount += 1;
            dbm.updateHost(host);


            int id = Convert.ToInt32(host.Smalltype);
            //根据小类型编号查找对应大类型
            var        big = adb.SmallTypes.Where(a => a.Id == id).FirstOrDefault().BigType;
            ForumReply fr  = new ForumReply
            {
                Fid       = rm.fid,
                Rcontent  = rm.Rcontent,
                RDate     = System.DateTime.Now.ToString(),
                Uid       = User.Identity.Name,
                Id        = BackIdService <ForumReply> .Instance.NewId(),
                Smalltype = host.Smalltype,
                Bigtype   = big
            };

            bool r = dbm.AddReply(fr);

            if (r)
            {
                ViewBag.msg2 = "添加成功";
            }
            ReplyShow(rm.fid);
            return(r);
        }
Exemplo n.º 10
0
    protected void InsertButton_Click(object sender, EventArgs e)
    {
        if (_id > -1)
        {
            ViewForum viewForum = new ViewForum();

            viewForum.ForumId  = _id;
            viewForum.Title    = TitleTextBox.Text;
            viewForum.UserName = User.Identity.Name;
            myEntities.ViewForums.Add(viewForum);
            myEntities.SaveChanges();


            ForumReply forumReply = new ForumReply();

            forumReply.ViewForumId    = viewForum.Id;
            forumReply.ReplyContent   = ReplyContentTextBox.Text;
            forumReply.CreateDateTime = DateTime.Now;
            forumReply.UpdateDateTime = DateTime.Now;
            forumReply.UserName       = User.Identity.Name;
            myEntities.ForumReplies.Add(forumReply);
            myEntities.SaveChanges();
            Response.Redirect(string.Format("~/Forums/ViewTopic.aspx?Id={0}", viewForum.Id));
        }
    }
Exemplo n.º 11
0
        public async Task <Result> CreatePreviewEditPost(ForumReply forumReplyEntity)
        {
            var result = new Result();

            try
            {
                var form = new MultipartFormDataContent
                {
                    { new StringContent("updatepost"), "action" },
                    { new StringContent(forumReplyEntity.PostId.ToString()), "postid" },
                    { new StringContent(HtmlEncode(forumReplyEntity.Message)), "message" },
                    { new StringContent(forumReplyEntity.ParseUrl.ToString()), "parseurl" },
                    { new StringContent("2097152"), "MAX_FILE_SIZE" },
                    { new StringContent("Preview Post"), "preview" }
                };
                result = await _webManager.PostFormData(EndPoints.EditPost, form);

                var doc = new HtmlDocument();
                doc.LoadHtml(result.ResultHtml);
                HtmlNode[] replyNodes = doc.DocumentNode.Descendants("div").ToArray();

                HtmlNode previewNode =
                    replyNodes.First(node => node.GetAttributeValue("class", "").Equals("inner postbody"));
                var post = new Post {
                    PostHtml = previewNode.OuterHtml
                };
                result.ResultJson = JsonConvert.SerializeObject(post);
                return(result);
            }
            catch (Exception)
            {
                return(result);
            }
        }
        public ActionResult EditComment(int id)
        {
            string     query         = "select * from ForumReplies where ReplyID = @id";
            var        parameter     = new SqlParameter("@id", id);
            ForumReply selectedreply = db.ForumReplies.SqlQuery(query, parameter).FirstOrDefault();

            return(View(selectedreply));
        }
Exemplo n.º 13
0
 protected void EditButton_Click(object sender, EventArgs e)
 {
     if (_id > -1)
     {
         ForumReply forumReply = myEntities.ForumReplies.Where(f => f.Id == _id).Single();
         forumReply.UpdateDateTime = DateTime.Now;
         forumReply.ReplyContent   = EditContentText.Text;
         myEntities.SaveChanges();
         Response.Redirect(string.Format("~/Forums/ViewTopic.aspx?Id={0}", forumReply.ViewForumId.ToString()));
     }
 }
Exemplo n.º 14
0
 public static ForumReplyModel ConvertToThreadReplyModel(this ForumReply reply, bool returnContent)
 {
     return(new ForumReplyModel()
     {
         CreatedBy = reply.UserProfile.UserName,
         CreatedById = reply.UserProfile.UserId,
         CreatedOn = reply.CreatedOn.ToShortDateString() + " " + reply.CreatedOn.ToShortTimeString(),
         ModifiedOn = reply.ModifiedOn.HasValue ? reply.ModifiedOn.Value.ToShortDateString() + " " + reply.ModifiedOn.Value.ToShortTimeString() : "",
         ReplyContent = returnContent ? reply.ReplyContent : "",
         ReplyId = reply.ReplyId
     });
 }
Exemplo n.º 15
0
        public void SaveCommentReply(int commentID, string reply)
        {
            int        participantID = (int)Session["User"];
            ForumReply fr            = new ForumReply()
            {
                Reply          = reply,
                ForumCommentID = commentID,
                ParticipantID  = participantID,
                PostedOn       = DateTime.Now
            };

            dBEntities.ForumReplies.Add(fr);
            dBEntities.SaveChanges();
        }
Exemplo n.º 16
0
    protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        ForumReply forumReply = (ForumReply)e.Item.DataItem;
        string     userName   = forumReply.UserName;

        int[]  RepliesIdList     = myEntities.ForumReplies.Where(f => f.ViewForumId == _id).Select(f => f.Id).ToArray();
        int    c                 = Array.IndexOf(RepliesIdList, forumReply.Id) + 1;
        Button editButton        = e.Item.FindControl("EditButton") as Button;
        Button editTopicButton   = e.Item.FindControl("EditTopicButton") as Button;
        Button deleteButton      = e.Item.FindControl("DeleteButton") as Button;
        Button deleteTopicButton = e.Item.FindControl("DeleteTopicButton") as Button;
        Button quoteButton       = e.Item.FindControl("QuoteButton") as Button;

        switch (e.Item.ItemType)
        {
        case ListViewItemType.DataItem:
            if (c == 1 && (Roles.IsUserInRole("CHD") || User.Identity.Name == userName))
            {
                if (editTopicButton != null)
                {
                    editTopicButton.Visible = true;
                }

                if (deleteTopicButton != null)
                {
                    deleteTopicButton.Visible = true;
                }
            }
            else if (c != 1 && (Roles.IsUserInRole("CHD") || User.Identity.Name == userName))
            {
                if (editButton != null)
                {
                    editButton.Visible = true;
                }
                if (deleteButton != null)
                {
                    deleteButton.Visible = true;
                }
            }
            if (Request.IsAuthenticated)
            {
                if (quoteButton != null)
                {
                    quoteButton.Visible = true;
                }
            }
            break;
        }
    }
Exemplo n.º 17
0
        public ActionResult ViewThread(ForumReplyModel model)
        {
            ViewThreadModel viewThreadModel = new ViewThreadModel()
            {
                Replies = new List <ForumReplyModel>()
            };

            using (CGWebEntities entities = new CGWebEntities())
            {
                UserProfile currentUserProfile = entities.UserProfiles.Where(P => P.UserName.Equals(User.Identity.Name)).Single();

                ForumReply newReply = new ForumReply()
                {
                    CreatedBy      = currentUserProfile.UserId,
                    CreatedOn      = DateTime.UtcNow,
                    ModifiedOn     = null,
                    ParentThreadId = model.ThreadId,
                    ReplyContent   = model.ReplyContent,
                    ReplyId        = Guid.NewGuid()
                };

                entities.ForumReplies.Add(newReply);
                entities.SaveChanges();
                ModelState.Clear();

                ForumThread currentThread = entities.ForumThreads.Where(FT => FT.ThreadId.Equals(model.ThreadId)).Single();

                viewThreadModel.ParentTopic = currentThread.ParentForumTopic.ConvertToForumTopicModel();

                if (!currentThread.ParentForumTopic.IsPublic && !Request.IsAuthenticated)
                {
                    return(RedirectToAction("Login", "Account"));
                }

                int currentPagingLimit = Convert.ToInt32(ConfigurationManager.AppSettings["ForumReplyPagingLimit"]);
                viewThreadModel.MaxPages    = (int)Math.Ceiling((double)currentThread.ForumReplies.Count / (double)currentPagingLimit);
                viewThreadModel.CurrentPage = viewThreadModel.MaxPages - 1;

                viewThreadModel.CurrentThread = currentThread.ConvertToForumThreadModel(true);

                foreach (ForumReply reply in currentThread.ForumReplies.OrderBy(FR => FR.CreatedOn).Skip(viewThreadModel.CurrentPage * currentPagingLimit).Take(currentPagingLimit))
                {
                    viewThreadModel.Replies.Add(reply.ConvertToThreadReplyModel(true));
                }
            }

            return(View(viewThreadModel));
        }
Exemplo n.º 18
0
        public async Task AddReply(string userId, int threadId, string content)
        {
            var user = await this.userManager.FindByIdAsync(userId);

            var thread = this.threadService.GetById(threadId);

            var reply = new ForumReply
            {
                Thread    = thread,
                Content   = content,
                CreatedOn = DateTime.UtcNow,
                PostedBy  = user,
            };

            await this.threadService.AddReply(reply);
        }
Exemplo n.º 19
0
        public async Task <ForumReply> GetReplyCookiesForEditAsync(long postId)
        {
            string url    = string.Format(EndPoints.EditBase, postId);
            var    result = await _webManager.GetDataAsync(url);

            var    document         = _webManager.Parser.Parse(result.ResultHtml);
            var    inputs           = document.QuerySelectorAll("input");
            var    forumReplyEntity = new ForumReply();
            var    bookmarks        = inputs["bookmark"].HasAttribute("checked") ? "yes" : "no";
            string quote            = System.Net.WebUtility.HtmlDecode(document.QuerySelector("textarea").TextContent);

            forumReplyEntity.MapEditPostInformation(
                quote,
                postId,
                bookmarks
                );
            return(forumReplyEntity);
        }
Exemplo n.º 20
0
 public void DetailsView1_InsertItem()
 {
     if (_id > -1)
     {
         ForumReply forumReply = new ForumReply();
         TryUpdateModel(forumReply);
         if (ModelState.IsValid)
         {
             forumReply.ViewForumId    = _id;
             forumReply.CreateDateTime = DateTime.Now;
             forumReply.UpdateDateTime = DateTime.Now;
             forumReply.UserName       = User.Identity.Name;
             myEntities.ForumReplies.Add(forumReply);
             myEntities.SaveChanges();
             Response.Redirect(string.Format("ViewTopic.aspx?Id={0}", forumReply.ViewForumId.ToString()));
         }
     }
 }
Exemplo n.º 21
0
        public async Task <Post> CreatePreviewEditPostAsync(ForumReply forumReplyEntity)
        {
            var form = new MultipartFormDataContent
            {
                { new StringContent("updatepost"), "action" },
                { new StringContent(forumReplyEntity.PostId.ToString()), "postid" },
                { new StringContent(HtmlHelpers.HtmlEncode(forumReplyEntity.Message)), "message" },
                { new StringContent(forumReplyEntity.ParseUrl.ToString()), "parseurl" },
                { new StringContent("2097152"), "MAX_FILE_SIZE" },
                { new StringContent("Preview Post"), "preview" }
            };
            var result = await _webManager.PostFormDataAsync(EndPoints.EditPost, form);

            var document = _webManager.Parser.Parse(result.ResultHtml);

            return(new Post {
                PostHtml = document.QuerySelector(".postbody").InnerHtml
            });
        }
Exemplo n.º 22
0
        public async Task <Result> SendUpdatePostAsync(ForumReply forumReplyEntity, CancellationToken token = default)
        {
            if (forumReplyEntity == null)
            {
                throw new ArgumentNullException(nameof(forumReplyEntity));
            }

            using var form = new MultipartFormDataContent
                  {
                      { new StringContent("updatepost"), "action" },
                      { new StringContent(forumReplyEntity.PostId.ToString(CultureInfo.InvariantCulture)), "postid" },
                      { new StringContent(HtmlHelpers.HtmlEncode(forumReplyEntity.Message)), "message" },
                      { new StringContent(forumReplyEntity.ParseUrl.ToString(CultureInfo.InvariantCulture)), "parseurl" },
                      { new StringContent(forumReplyEntity.Bookmark), "bookmark" },
                      { new StringContent("2097152"), "MAX_FILE_SIZE" },
                      { new StringContent("Save Changes"), "submit" },
                  };
            return(await this.webManager.PostFormDataAsync(EndPoints.EditPost, form, token).ConfigureAwait(false));
        }
Exemplo n.º 23
0
    public void ListView1_InsertItem()
    {
        var forumReply = new ForumReply();

        TryUpdateModel(forumReply);
        if (ModelState.IsValid)
        {
            // Save changes here
            forumReply.ViewForumId    = _id;
            forumReply.CreateDateTime = DateTime.Now;
            forumReply.UpdateDateTime = DateTime.Now;
            if (Request.IsAuthenticated)
            {
                forumReply.UserName = User.Identity.Name;
            }
            myEntities.ForumReplies.Add(forumReply);
        }
        myEntities.SaveChanges();
        Response.Redirect(string.Format("~/Forums/ViewTopic.aspx?Id={0}#{1}", _id, forumReply.Id));
    }
Exemplo n.º 24
0
        public async Task <Result> SendPostAsync(ForumReply forumReplyEntity, CancellationToken token = default)
        {
            if (forumReplyEntity == null)
            {
                throw new ArgumentNullException(nameof(forumReplyEntity));
            }

            using var form = new MultipartFormDataContent
                  {
                      { new StringContent("postreply"), "action" },
                      { new StringContent(forumReplyEntity.ThreadId), "threadid" },
                      { new StringContent(forumReplyEntity.FormKey), "formkey" },
                      { new StringContent(forumReplyEntity.FormCookie), "form_cookie" },
                      { new StringContent(HtmlHelpers.HtmlEncode(forumReplyEntity.Message)), "message" },
                      { new StringContent(forumReplyEntity.ParseUrl.ToString()), "parseurl" },
                      { new StringContent("2097152"), "MAX_FILE_SIZE" },
                      { new StringContent("Submit Reply"), "submit" },
                  };
            return(await this.webManager.PostFormDataAsync(EndPoints.NewReply, form, token).ConfigureAwait(false));
        }
Exemplo n.º 25
0
        public async Task <Result> CreatePreviewPost(ForumReply forumReplyEntity)
        {
            var result = new Result();

            try
            {
                var form = new MultipartFormDataContent
                {
                    { new StringContent("postreply"), "action" },
                    { new StringContent(forumReplyEntity.ThreadId), "threadid" },
                    { new StringContent(forumReplyEntity.FormKey), "formkey" },
                    { new StringContent(forumReplyEntity.FormCookie), "form_cookie" },
                    { new StringContent(HtmlEncode(forumReplyEntity.Message)), "message" },
                    { new StringContent(forumReplyEntity.ParseUrl.ToString()), "parseurl" },
                    { new StringContent("2097152"), "MAX_FILE_SIZE" },
                    { new StringContent("Submit Reply"), "submit" },
                    { new StringContent("Preview Reply"), "preview" }
                };
                // We post to SA the same way we would for a normal reply, but instead of getting a redirect back to the
                // thread, we'll get redirected to back to the reply screen with the preview message on it.
                // From here we can parse that preview and return it to the user.

                result = await _webManager.PostFormData(EndPoints.NewReply, form);

                var doc = new HtmlDocument();
                doc.LoadHtml(result.ResultHtml);
                HtmlNode[] replyNodes = doc.DocumentNode.Descendants("div").ToArray();

                HtmlNode previewNode =
                    replyNodes.First(node => node.GetAttributeValue("class", "").Equals("inner postbody"));
                var post = new Post {
                    PostHtml = previewNode.OuterHtml
                };
                result.ResultJson = JsonConvert.SerializeObject(post);
                return(result);
            }
            catch (Exception)
            {
                return(result);
            }
        }
Exemplo n.º 26
0
    protected void EditButton_Click(object sender, EventArgs e)
    {
        ViewForum viewForum = (from f in myEntities.ForumReplies
                               join v in myEntities.ViewForums on f.ViewForumId equals v.Id
                               where f.Id == _id
                               select v).Single();
        ForumReply forumReply = myEntities.ForumReplies.Where(f => f.Id == _id).Single();

        if ((viewForum.Title != EditTitleTextBox.Text) || (forumReply.ReplyContent != EditContentTextBox.Text))
        {
            forumReply.UpdateDateTime = DateTime.Now;

            viewForum.Title         = EditTitleTextBox.Text;
            forumReply.ReplyContent = EditContentTextBox.Text;
            EditButton.Text         = "最后编辑于 " + forumReply.UpdateDateTime.ToString();
            EditButton.Visible      = true;
        }


        myEntities.SaveChanges();
        Response.Redirect(string.Format("~/Forums/ViewTopic.aspx?Id={0}", viewForum.Id.ToString()));
    }
Exemplo n.º 27
0
        public async Task Add(ForumThread thread)
        {
            await this.threadRepository.AddAsync(thread);

            await this.threadRepository.SaveChangesAsync();

            var reply = new ForumReply
            {
                CreatedOn  = thread.CreatedOn,
                Content    = thread.Content,
                DeletedOn  = thread.DeletedOn,
                IsDeleted  = thread.IsDeleted,
                ModifiedOn = thread.ModifiedOn,
                PostedById = thread.PostedById,
                ThreadId   = thread.Id,
                PostedBy   = thread.PostedBy,
                Thread     = thread,
            };

            await this.AddReply(reply);

            await this.replyRepository.SaveChangesAsync();
        }
Exemplo n.º 28
0
        public async Task <ForumReply> GetReplyCookiesForEditAsync(long postId, CancellationToken token = default)
        {
            if (postId <= 0)
            {
                throw new FormatException(Awful.Core.Resources.ExceptionMessages.PostIdMissing);
            }

            string url    = string.Format(CultureInfo.InvariantCulture, EndPoints.EditBase, postId);
            var    result = await this.webManager.GetDataAsync(url, token).ConfigureAwait(false);

            var document = await this.webManager.Parser.ParseDocumentAsync(result.ResultHtml, token).ConfigureAwait(false);

            var    inputs           = document.QuerySelectorAll("input");
            var    forumReplyEntity = new ForumReply();
            var    bookmarks        = inputs["bookmark"].HasAttribute("checked") ? "yes" : "no";
            string quote            = System.Net.WebUtility.HtmlDecode(document.QuerySelector("textarea").TextContent);

            forumReplyEntity.MapEditPostInformation(
                quote,
                postId,
                bookmarks);
            return(forumReplyEntity);
        }
Exemplo n.º 29
0
        public async Task <Post> CreatePreviewEditPostAsync(ForumReply forumReplyEntity, CancellationToken token = default)
        {
            if (forumReplyEntity == null)
            {
                throw new ArgumentNullException(nameof(forumReplyEntity));
            }

            using var form = new MultipartFormDataContent
                  {
                      { new StringContent("updatepost"), "action" },
                      { new StringContent(forumReplyEntity.PostId.ToString(CultureInfo.InvariantCulture)), "postid" },
                      { new StringContent(HtmlHelpers.HtmlEncode(forumReplyEntity.Message)), "message" },
                      { new StringContent(forumReplyEntity.ParseUrl.ToString()), "parseurl" },
                      { new StringContent("2097152"), "MAX_FILE_SIZE" },
                      { new StringContent("Preview Post"), "preview" },
                  };
            var result = await this.webManager.PostFormDataAsync(EndPoints.EditPost, form, token).ConfigureAwait(false);

            var document = await this.webManager.Parser.ParseDocumentAsync(result.ResultHtml, token).ConfigureAwait(false);

            return(new Post {
                PostHtml = document.QuerySelector(".postbody").InnerHtml
            });
        }
Exemplo n.º 30
0
 //添加回帖
 public bool AddReply(ForumReply f)
 {
     fr.SetCtx(db);
     return(fr.Add(f));
 }