Esempio n. 1
0
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            int  code = 0;
            bool res  = int.TryParse(txtTopicCode.Text, out code);

            if (res == false)
            {
                error.InnerText = "Invalid code.";
            }
            else
            {
                _topicService.CloseTopic(code);
                error.InnerText = "";
                error.Style.Add("display", "none");
            }
        }
Esempio n. 2
0
        public async Task <RedirectToActionResult> ToggleClosed(int id)
        {
            var topic = await _topicService.Get(id);

            if (topic == null)
            {
                throw new Exception($"Topic with ID {id} not found. Can't open/close.");
            }
            var user = _userRetrievalShim.GetUser();

            if (topic.IsClosed)
            {
                await _topicService.OpenTopic(topic, user);
            }
            else
            {
                await _topicService.CloseTopic(topic, user);
            }
            return(RedirectToAction("Topic", "Forum", new { id = topic.UrlName }));
        }
        public RedirectToRouteResult ToggleClosed(int id)
        {
            var topic = _topicService.Get(id);

            if (topic == null)
            {
                throw new Exception(String.Format("Topic with ID {0} not found. Can't open/close.", id));
            }
            var user = this.CurrentUser();

            if (topic.IsClosed)
            {
                _topicService.OpenTopic(topic, user);
            }
            else
            {
                _topicService.CloseTopic(topic, user);
            }
            return(RedirectToAction("Topic", "Forum", new { id = topic.UrlName }));
        }
Esempio n. 4
0
        // TODO: test validation [ValidateInput(false)]
        public JsonResult PostReply(NewPost newPost)
        {
            var user = _userRetrievalShim.GetUser(HttpContext);

            if (user == null)
            {
                return(Json(new BasicJsonMessage {
                    Message = Resources.LoginToPost, Result = false
                }));
            }
            ForumPermissionContext permissionContext;
            var topic = _topicService.Get(newPost.ItemID);

            if (topic == null)
            {
                return(Json(new BasicJsonMessage {
                    Message = Resources.TopicNotExist, Result = false
                }));
            }
            if (topic.IsClosed)
            {
                return(Json(new BasicJsonMessage {
                    Message = Resources.Closed, Result = false
                }));
            }
            GetForumByIdWithPermissionContext(topic.ForumID, out permissionContext);
            if (!permissionContext.UserCanView)
            {
                return(Json(new BasicJsonMessage {
                    Message = Resources.ForumNoView, Result = false
                }));
            }
            if (!permissionContext.UserCanPost)
            {
                return(Json(new BasicJsonMessage {
                    Message = Resources.ForumNoPost, Result = false
                }));
            }
            if (_postService.IsNewPostDupeOrInTimeLimit(newPost, user))
            {
                return(Json(new BasicJsonMessage {
                    Message = String.Format(Resources.PostWait, _settingsManager.Current.MinimumSecondsBetweenPosts), Result = false
                }));
            }
            if (String.IsNullOrEmpty(newPost.FullText))
            {
                return(Json(new BasicJsonMessage {
                    Message = Resources.PostEmpty, Result = false
                }));
            }
            if (newPost.ParentPostID != 0)
            {
                var parentPost = _postService.Get(newPost.ParentPostID);
                if (parentPost == null || parentPost.TopicID != topic.TopicID)
                {
                    return(Json(new BasicJsonMessage {
                        Message = "This reply attempt is being made to a post in another topic", Result = false
                    }));
                }
            }

            var topicLink = this.FullUrlHelper("GoToNewestPost", Name, new { id = topic.TopicID });
            Func <User, string> unsubscribeLinkGenerator =
                u => this.FullUrlHelper("Unsubscribe", SubscriptionController.Name, new { topicID = topic.TopicID, authKey = u.AuthorizationKey });
            var helper         = Url;
            var userProfileUrl = helper.Action("ViewProfile", "Account", new { id = user.UserID });
            Func <Post, string> postLinkGenerator = p => helper.Action("PostLink", "Forum", new { id = p.PostID });
            var post = _topicService.PostReply(topic, user, newPost.ParentPostID, HttpContext.Connection.RemoteIpAddress.ToString(), false, newPost, DateTime.UtcNow, topicLink, unsubscribeLinkGenerator, userProfileUrl, postLinkGenerator);

            _topicViewCountService.SetViewedTopic(topic, HttpContext);
            if (newPost.CloseOnReply && user.IsInRole(PermanentRoles.Moderator))
            {
                _topicService.CloseTopic(topic, user);
            }
            var urlHelper = Url;

            return(Json(new BasicJsonMessage {
                Result = true, Redirect = urlHelper.RouteUrl(new { controller = "Forum", action = "PostLink", id = post.PostID })
            }));
        }