Beispiel #1
0
        public virtual ActionResult AddCommentComment(CommentView model, EmbedModel embed)
        {
            if (!IsAjaxRequest)
            {
                return(RedirectToAction(MVC.Idea.Details(model.EntryId, null, null)));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var comment = Service.AddNewCommentToComment(model.EntryId, model.Id, model.CommentText, embed);

                    if (IsJsonRequest)
                    {
                        return(Jsonp(comment));
                    }

                    return(Jsonp(new
                    {
                        Comment = RenderPartialViewToString(MVC.Comments.Views._CommentComment, comment),
                        Subscribe = RenderPartialViewToString(MVC.Shared.Views.Subscribe, comment.Subscribe),
                        SubscribeMain = RenderPartialViewToString(MVC.Shared.Views.Subscribe, comment.SubscribeMain)
                    }));
                }
                catch (Exception ex)
                {
                    return(ProcessError(ex));
                }
            }

            return(Jsonp(false));
        }
Beispiel #2
0
        public virtual ActionResult AddComment(CommentView model, EmbedModel embed)
        {
            if (Request.HttpMethod == "GET" || !Request.IsAjaxRequest())
            {
                return(RedirectToAction(MVC.Problem.Index()));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var comment = Service.AddNewComment(model.EntryId, model.CommentText, embed);
                    return(Json(new { Comment = RenderPartialViewToString(MVC.Comments.Views._Comment, comment),
                                      SubscribeMain = RenderPartialViewToString(MVC.Shared.Views.Subscribe, comment.SubscribeMain) }));
                }
                catch (Exception ex)
                {
                    return(ProcessError(ex));
                }
            }

            return(Json(new
            {
                error = (from v in ModelState.Values
                         from e in v.Errors
                         select e.ErrorMessage).Concatenate(";")
            }));
        }
Beispiel #3
0
 public ProblemIndexItemModel()
 {
     Categories   = new List <TextValue>();
     RelatedIdeas = new List <ProblemIdeaListModel>();
     Votes        = new VoteResultModel();
     Embed        = new EmbedModel();
 }
Beispiel #4
0
        public virtual CommentView AddNewComment(MongoObjectId id, string text, EmbedModel embed, ForAgainst forAgainst = ForAgainst.Neutral, MongoObjectId versionId = null)
        {
            var entity  = GetEntity(id);
            var comment = commentService.AddNewComment(entity, forAgainst, text, embed, versionId);

            SendCommentCommand(entity, GetAddNewCommentActionType(), comment);
            return(comment);
        }
Beispiel #5
0
        public virtual ActionResult Create(ProblemCreateEditModel model, EmbedModel embed)
        {
            if (!EnsureIsUnique())
            {
                return(RedirectToAction(MVC.Account.Details()));
            }

            if (ModelState.IsValid)
            {
                var result = Service.Insert(model, embed);
                return(Json(new { Content = RenderPartialViewToString(MVC.Problem.Views.List, new List <ProblemIndexItemModel> {
                        result
                    }), Id = result.Id }));
            }

            return(Json(false));
        }
Beispiel #6
0
        public IActionResult UploadEmbed(EmbedVideoVM model)
        {
            var uri = model.URI;

            // Allows support for varying types of Youtube URL and embed links
            string[] validAuthorities = { "https:\\/\\/www.youtube.com", "youtube.com", "www.youtube.com", "youtu.be", "www.youtu.be" };
            // Matches for Youtube Id URI
            var   YoutubeRegex   = "(?:.+?)?(?:\\/v\\/|watch\\/|\\?v=|\\&v=|youtu\\.be\\/|\\/v=|^youtu\\.be\\/)([a-zA-Z0-9_-]{11})+";
            Regex regexExtractId = new Regex(YoutubeRegex, RegexOptions.Compiled);

            try
            {
                string authority = new UriBuilder(uri).Uri.Authority.ToLower();
                //check if the url is a youtube url
                if (validAuthorities.Contains(authority))
                {
                    //and extract the id
                    var regRes = regexExtractId.Match(uri.ToString());
                    if (regRes.Success)
                    {
                        var embedLink = $"{validAuthorities[0]}/embed/{regRes.Groups[1].Value}";
                        model.URI = embedLink;
                    }

                    var entity = new EmbedModel
                    {
                        SectionId    = model.Id,
                        ResourceLink = model.URI
                    };
                    _context.Add(entity);
                    _context.SaveChanges();
                }
                return(RedirectToAction("Edit", "Author", new { id = model.CourseId, selectedSection = model.ParentSectionId }));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #7
0
        public virtual ActionResult AddComment(CommentView model, EmbedModel embed)
        {
            if (Request.HttpMethod == "GET" || !Request.IsAjaxRequest())
            {
                return(RedirectToAction(MVC.Voting.Details(model.Id, null)));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var comment = Service.AddNewComment(model.EntryId, model.CommentText, embed, model.ForAgainst);
                    if (comment.VotingStatistics != null && comment.VotingStatistics.Vote.HasValue)
                    {
                        comment.VotingStatistics.VotedString = GetVotedString(comment.VotingStatistics.Vote.Value);
                    }

                    return(Json(new
                    {
                        Comment = RenderPartialViewToString(MVC.Comments.Views._Comment, comment),
                        VotingStatistics =
                            comment.VotingStatistics != null
                                        ? RenderPartialViewToString(MVC.Voting.Views.VotingStatistics,
                                                                    comment.VotingStatistics)
                                        : null,
                        SubscribeMain = RenderPartialViewToString(MVC.Shared.Views.Subscribe, comment.SubscribeMain)
                    }));
                }
                catch (Exception ex)
                {
                    return(ProcessError(ex));
                }
            }

            return(Json(false));
        }
Beispiel #8
0
        public CommentView AddNewCommentToComment(MongoObjectId id, MongoObjectId commentId, string text, EmbedModel embed)
        {
            var entity  = GetEntity(id);
            var comment = commentService.AddNewCommentToComment(entity, commentId, text, embed);

            SendCommentCommand(entity, ActionTypes.CommentCommented, comment);
            return(comment);
        }
Beispiel #9
0
        public CommentView AddNewCommentToComment(ICommentable entity, MongoObjectId commentId, string text, EmbedModel embed)
        {
            if (CurrentUser.RequireUniqueAuthentication && !CurrentUser.IsUnique)
            {
                throw new UserNotUniqueException();
            }

            var comment = GetComment(entity, commentId);

            if (comment == null)
            {
                return(null);
            }
            comment.LastNumber++;
            var cComment = new Comment
            {
                Date         = DateTime.Now,
                Text         = text,
                UserFullName = CurrentUser.FullName,
                UserObjectId = CurrentUser.Id,
                Number       = comment.Number + comment.LastNumber
            };

            if (embed != null && !embed.IsEmpty)
            {
                cComment.Embed = new Data.MongoDB.Embed();
                cComment.Embed.InjectFrom(embed);
                cComment.Embed.Title       = cComment.Embed.Title.Sanitize();
                cComment.Embed.Description = cComment.Embed.Description.Sanitize();
            }

            comment.Comments.Add(cComment);

            UpdateEntity(entity);

            var model = GetCommentViewFromComment(entity.Id, cComment, commentId, entity.EntryType,
                                                  entity.GetRelatedVersionNumber(comment.RelatedVersionId));

            model.SubscribeMain = ActionService.Subscribe(entity.Id, CurrentUser.DbId.Value, entity.EntryType);
            model.Subscribe     = ActionService.Subscribe(comment.Id, CurrentUser.DbId.Value);

            return(model);
        }
Beispiel #10
0
        public virtual CommentView AddNewComment(ICommentable entity, ForAgainst forAgainst, string text, EmbedModel embed, MongoObjectId versionId = null)
        {
            if (CurrentUser.RequireUniqueAuthentication && !CurrentUser.IsUnique)
            {
                throw new UserNotUniqueException();
            }

            if (entity.Id == CurrentUser.Id)
            {
                forAgainst = ForAgainst.Neutral;
            }

            entity.LastNumber++;
            var comment = new Comment
            {
                Date               = DateTime.Now,
                Text               = text,
                UserFullName       = CurrentUser.FullName,
                UserObjectId       = CurrentUser.Id,
                RelatedVersionId   = versionId,
                PositiveOrNegative = forAgainst,
                Number             = entity.LastNumber.ToString() + "."
            };

            if (embed != null && !embed.IsEmpty)
            {
                comment.Embed = new Data.MongoDB.Embed();
                comment.Embed.InjectFrom(embed);

                comment.Embed.Title       = comment.Embed.Title.Sanitize();
                comment.Embed.Description = comment.Embed.Description.Sanitize();
            }
            entity.Comments.Add(comment);
            UpdateEntity(entity);

            var model = GetCommentViewFromComment(entity.Id, comment, null, entity.EntryType,
                                                  entity.GetRelatedVersionNumber(comment.RelatedVersionId));


            model.SubscribeMain = ActionService.Subscribe(entity.Id, CurrentUser.DbId.Value, entity.EntryType);
            model.Subscribe     = ActionService.Subscribe(comment.Id, CurrentUser.DbId.Value);

            return(model);
        }
Beispiel #11
0
 public CommentView()
 {
     Comments = new List <CommentView>();
     Liking   = new Liking();
     Embed    = new EmbedModel();
 }