Esempio n. 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 });
        }
Esempio n. 2
0
        public void DeleteComment(Comment Comment)
        {
            context.Entry(Comment).State = EntityState.Deleted;

            context.SaveChanges();

            return;
        }
Esempio n. 3
0
        public int AddComment(Comment Comment)
        {
            if (Comment.CommentID == 0)
            {
                context.Comments.Add(Comment);
            }
            else
            {
                context.Entry(Comment).State = EntityState.Modified;
            }
            context.SaveChanges();
            context.Entry(Comment).Reload();

            return Comment.CommentID;
        }