Example #1
0
        public ActionResult AddComment(AddCommentViewModel Model)
        {
            Comment parent = repository.Comments.FirstOrDefault(c => c.CommentID == Model.ParentCommentID);

            Comment comment = new Comment()
            {
                Date = DateTime.Now,
                IsRead = 0,
                Level = parent != null ? parent.Level + 1 : 0,
                ParentComment = parent,
                ProblemID = Model.ProblemID,
                Public = 0,
                TournamentID = Model.TournamentID,
                UserID = WebSecurity.CurrentUserId,
                Value = Model.Value.Replace("\n", "<br />")
            };

            int commentID = repository.AddComment(comment);

            if (parent != null && parent.IsRead == 0)
            {
                parent.IsRead = 1;
                repository.AddComment(parent);
            }

            string url = UrlHelper.GenerateUrl(
                null, "Comments", "Problem", null, null, "Comment-" + commentID,
                new RouteValueDictionary(new { ProblemID = Model.ProblemID, TournamentID = Model.TournamentID }),
                Url.RouteCollection, Url.RequestContext, false);

            return Redirect(url);//RedirectToAction("Comments", new { ProblemID = Model.ProblemID, TournamentID = Model.TournamentID });
        }
 public void Init()
 {
     this.sanitizeService = new HtmlSanitizerAdapter();
     this.commentsService = ObjectFactory.GetCommentService();
     this.userService = ObjectFactory.GetUserService();
     this.model = new AddCommentViewModel();
     this.controller = new CommentController(this.userService, this.commentsService, this.sanitizeService);
     this.controller.CurrentUser = this.userService.GetUser("test");
 }
Example #3
0
        public PartialViewResult AddComment(int ProblemID, int TournamentID = -1)
        {
            AddCommentViewModel viewModel = new AddCommentViewModel()
            {
                ProblemID = ProblemID,
                TournamentID = TournamentID
            };

            return PartialView(viewModel);
        }
        public ActionResult AddComment(AddCommentViewModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var comment = Mapper.Map<Comment>(model);
                comment.UserId = this.CurrentUser.Id;

                if (model.HomeId != null)
                {
                    var home = this.homes
                    .GetHomeById(model.HomeId)
                    .FirstOrDefault();

                    if (home == null)
                    {
                        throw new HttpException(404, GlobalConstants.PageNotFound);
                    }

                    home.Comments.Add(comment);
                    this.homes.Update();
                }

                if (model.NeedId != null)
                {
                    var need = this.needs.GetById(model.NeedId);

                    if (need == null)
                    {
                        throw new HttpException(404, GlobalConstants.PageNotFound);
                    }

                    need.Comments.Add(comment);
                    this.needs.Update(need);
                }

                var viewModel = Mapper.Map<CommentViewModel>(comment);

                return this.PartialView(GlobalConstants.SingleCommentPartial, viewModel);
            }

            throw new HttpException(400, GlobalConstants.InvalidComment);
        }
        public async Task<ActionResult> AddComment(AddCommentViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                model.Replay = this.sanitizeService.Sanitize(model.Replay);

                var comment = Mapper.Map<Comment>(model);
                comment.UserId = this.CurrentUser.Id;

                comment = await this.commentsService.AddNew(comment);

                var viewModel = Mapper.Map<CommentsViewModel>(comment);
                viewModel.Avatar = this.CurrentUser.Avatar;
                viewModel.UserName = this.CurrentUser.UserName;

                return this.PartialView("~/Areas/Private/Views/Comment/_SingleCommentPartial.cshtml", viewModel);
            }

            throw new HttpException(400, "Invalid Comment");
        }
        public ActionResult AddComment(AddCommentViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var comment = Mapper.Map<Comment>(model);
                comment.AuthorId = this.CurrentUser.Id;

                var page = this.data.Pages.Find(model.PageId);
                if (page == null)
                {
                    throw new HttpException(404, GlobalConstants.PageNotFound);
                }

                page.Comments.Add(comment);
                this.data.SaveChanges();

                var viewModel = Mapper.Map<CommentViewModel>(comment);

                return this.PartialView(GlobalConstants.SingleCommentPartialPrivate, viewModel);
            }

            throw new HttpException(400, GlobalConstants.InvalidComment);
        }
Example #7
0
        public HttpResponseMessage AddComment(AddCommentViewModel vm)
        {
            var     res      = new HttpResponseMessage();
            JObject jContent = new JObject();
            Random  ran      = new Random();

            if (vm != null)
            {
                // vm.Password = Secure.Encrypt(vm.Password);// Secure.Encrypt("TWuser@" + Convert.ToString(ran.Next(1000, 9999)));
                //  vm.ConfirmPassword = Secure.Encrypt(vm.Password);
                if (ModelState.IsValid)
                {
                    try
                    {
                        CommentsBEL objCommentBEL = new CommentsBEL();

                        objCommentBEL.userId      = vm.userId;
                        objCommentBEL.postId      = vm.postId;
                        objCommentBEL.commentText = vm.commentText;
                        objCommentBEL.avatar      = vm.Avatar;
                        // objPostBEL. = vm.Mobile;

                        UserDetailsDAL objUserDAL = new UserDetailsDAL();
                        CommentsBEL    ulvm       = new CommentsBEL(objUserDAL.AddComment(objCommentBEL));

                        if (ulvm.commentId != "0")
                        {
                            res.StatusCode = HttpStatusCode.Created;
                            jContent       = new JObject(
                                new JProperty("result",
                                              new JObject(
                                                  new JProperty("Success", true),
                                                  new JProperty("Message", "Post added successfully"),
                                                  new JProperty("CommentId", ulvm.commentId))));
                        }
                        else
                        {
                            res.StatusCode = HttpStatusCode.BadRequest;
                            jContent       = new JObject(
                                new JProperty("result",
                                              new JObject(
                                                  new JProperty("Success", false),
                                                  new JProperty("Message", ulvm.ErrorMessage),
                                                  new JProperty("ErrorMessage", ulvm.ErrorMessage),
                                                  new JProperty("CommentId", ulvm.commentId))));
                        }
                    }
                    catch (Exception ex)
                    {
                        res.StatusCode = HttpStatusCode.BadRequest;
                        jContent       = new JObject(
                            new JProperty("result",
                                          new JObject(
                                              new JProperty("Success", false),
                                              new JProperty("Message", ex.Message),
                                              new JProperty("ErrorMessage", ex.InnerException.ToString()),
                                              new JProperty("CommentId", null))));
                    }
                }
                else
                {
                    var errorList = (from item in ModelState
                                     where item.Value.Errors.Any()
                                     select item.Value.Errors[0].ErrorMessage).ToList();
                    res.StatusCode = HttpStatusCode.BadRequest;
                    jContent       = new JObject(
                        new JProperty("result",
                                      new JObject(
                                          new JProperty("Success", false),
                                          new JProperty("Message", "Invalid Input"),
                                          new JProperty("ErrorMessage", errorList),
                                          new JProperty("CommentId", null))));
                }
            }
            res.Content = new StringContent(jContent.ToString());
            return(res);
        }
Example #8
0
        public IActionResult AddComment(AddCommentViewModel addcomment)
        {
            if (!dasBlogSettings.SiteConfiguration.EnableComments)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(Comment(addcomment.TargetEntryId));
            }

            if (dasBlogSettings.SiteConfiguration.CheesySpamQ.Trim().Length > 0 &&
                dasBlogSettings.SiteConfiguration.CheesySpamA.Trim().Length > 0)
            {
                if (string.Compare(addcomment.CheesyQuestionAnswered, dasBlogSettings.SiteConfiguration.CheesySpamA,
                                   StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return(Comment(addcomment.TargetEntryId));
                }
            }

            addcomment.Content = dasBlogSettings.FilterHtml(addcomment.Content);

            var commt = mapper.Map <NBR.Comment>(addcomment);

            commt.AuthorIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
            commt.AuthorUserAgent = HttpContext.Request.Headers["User-Agent"].ToString();
            commt.CreatedUtc      = commt.ModifiedUtc = DateTime.UtcNow;
            commt.EntryId         = Guid.NewGuid().ToString();
            commt.IsPublic        = !dasBlogSettings.SiteConfiguration.CommentsRequireApproval;

            var state = blogManager.AddComment(addcomment.TargetEntryId, commt);

            if (state == NBR.CommentSaveState.Failed)
            {
                ModelState.AddModelError("", "Comment failed");
                return(StatusCode(500));
            }

            if (state == NBR.CommentSaveState.SiteCommentsDisabled)
            {
                ModelState.AddModelError("", "Comments are closed for this post");
                return(StatusCode(403));
            }

            if (state == NBR.CommentSaveState.PostCommentsDisabled)
            {
                ModelState.AddModelError("", "Comment are currently disabled");
                return(StatusCode(403));
            }

            if (state == NBR.CommentSaveState.NotFound)
            {
                ModelState.AddModelError("", "Invalid Target Post Id");
                return(NotFound());
            }

            logger.LogInformation(new EventDataItem(EventCodes.CommentAdded, null, "Comment created on: {0}", commt.TargetTitle));

            BreakSiteCache();

            return(Comment(addcomment.TargetEntryId));
        }