Esempio n. 1
0
        public ActionResult ReportInappropriatePost_GET(int postId, string returnUrl )
        {

            if (!_orchardServices.WorkContext.HttpContext.User.Identity.IsAuthenticated)
                return new HttpUnauthorizedResult(T("You must be logged in to report an inappropriate post.").ToString());

            if (!_orchardServices.Authorizer.Authorize(Permissions.CreateThreadsAndPosts, T("You require permission to post to the forums in order to report posts as inappropriate.")))
                return new HttpUnauthorizedResult();

            var userId = _orchardServices.WorkContext.CurrentUser.Id;

            ReportPostService.CreatePostResultEnum reportedAccepted = _reportPostService.PostReportStatus(postId, userId);

            //setup a model just in case there is more info to be added later
            ReportInappropriatePostConfirmationViewModel model = new ReportInappropriatePostConfirmationViewModel{
                ReturnUrl = returnUrl,
                PostId = postId,               
                ReportSubmittedResult = reportedAccepted
            };

            return View(model);
        }
Esempio n. 2
0
        public ActionResult ReportInappropriatePost_POST(ReportInappropriatePostConfirmationViewModel model)
        {

            if (!_orchardServices.WorkContext.HttpContext.User.Identity.IsAuthenticated)
                return new HttpUnauthorizedResult(T("You must be logged in to report an inappropriate post.").ToString());

            if (!_orchardServices.Authorizer.Authorize(Permissions.CreateThreadsAndPosts, T("You do not have permissions to post on the forums and therefore cannot report posts.")))
                return new HttpUnauthorizedResult();

            var userId = _orchardServices.WorkContext.CurrentUser.Id;
            var post = _postService.Get( model.PostId, VersionOptions.Published);

            if (model.ReasonReported.Length > 2048)
            {
                this.ModelState.AddModelError("ReasonReported", T("The reason cannot be longer than 2048 characters.  You entered {0} characters.", model.ReasonReported.Length).ToString());
                return View(model);
            }

            if (post != null)
            {
                var reportedPostRecord = new ReportedPostRecord
                {
                    PostId = model.PostId,
                    IsResolved = false,
                    PostedByUserId = post.As<CommonPart>().Owner.Id,
                    ReasonReported = model.ReasonReported,
                    ReportedByUserId = userId,
                    ResolvedByUserId = 0,
                };
                _reportPostService.CreateReport(reportedPostRecord);
            }
            return RedirectToActionPermanent("InappropriatePostReportedSuccessfully", new { returnUrl = model.ReturnUrl });
        }