예제 #1
0
        //// POST: votecomment/{commentId}/{typeOfVote}
        //[HttpPost]
        //[Authorize]
        //[VoatValidateAntiForgeryToken]
        //public async Task<JsonResult> VoteComment(int commentId, int typeOfVote)
        //{
        //    var cmd = new CommentVoteCommand(commentId, typeOfVote, IpHash.CreateHash(UserHelper.UserIpAddress(this.Request)));
        //    var result = await cmd.Execute();
        //    return Json(result);
        //}



        // GET: Renders Primary Submission Comments Page
        public async Task <ActionResult> Comments(int?submissionID, string subverseName, int?commentID, string sort, int?context)
        {
            #region Validation

            if (submissionID == null)
            {
                return(ErrorView(new ErrorViewModel()
                {
                    Description = "Can not find what was requested because input is not valid"
                }));
            }

            var q = new QuerySubmission(submissionID.Value, true).SetUserContext(User);

            var submission = await q.ExecuteAsync().ConfigureAwait(false);

            if (submission == null)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            // make sure that the combination of selected subverse and submission subverse are linked
            if (!submission.Subverse.IsEqual(subverseName))
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            var subverse = DataCache.Subverse.Retrieve(subverseName);

            if (subverse == null)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            if (subverse.IsAdminDisabled.HasValue && subverse.IsAdminDisabled.Value)
            {
                ViewBag.Subverse = subverse.Name;
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseDisabled)));
            }

            #endregion

            if (commentID != null)
            {
                ViewBag.StartingCommentId  = commentID;
                ViewBag.CommentToHighLight = commentID;
            }

            #region Set ViewBag
            ViewBag.Subverse   = subverse;
            ViewBag.Submission = submission;
            //This is a required view bag property in _Layout.cshtml - Update: hmmm, don't think so but too lazy to look
            ViewBag.SelectedSubverse = subverse.Name;

            var sortingMode = GetSortMode(sort);

            ViewBag.SortingMode = sortingMode;

            #endregion

            var cmd = new LogVisitCommand(null, submissionID.Value, Request.RemoteAddress()).SetUserContext(User);
            cmd.Execute();

            CommentSegment model = null;
            if (commentID != null)
            {
                ViewBag.CommentToHighLight = commentID.Value;
                model = await GetCommentContext(submission.ID, commentID.Value, context, sortingMode);
            }
            else
            {
                model = await GetCommentSegment(submission.ID, null, 0, sortingMode);
            }

            var q2 = new QuerySubverseModerators(subverseName).SetUserContext(User);
            ViewBag.ModeratorList = await q2.ExecuteAsync();



            ViewBag.NavigationViewModel = new NavigationViewModel()
            {
                Description = "Subverse",
                Name        = subverseName,
                MenuType    = MenuType.Subverse,
                BasePath    = VoatUrlFormatter.BasePath(new DomainReference(DomainType.Subverse, subverseName)),
                Sort        = null
            };

            return(View("~/Views/Home/Comments.cshtml", model));
        }
        private void SetMenuNavigationModel(string name, MenuType menuType, string subverse = null)
        {
            string suffix = "/messages";

            ViewBag.NavigationViewModel = new NavigationViewModel()
            {
                Description = (String.IsNullOrEmpty(subverse) ? "Messages" : String.Format("v/{0} Smail", subverse)),
                Name        = name,
                MenuType    = menuType,
                BasePath    = (String.IsNullOrEmpty(subverse) ? suffix : String.Format("{0}/about{1}", VoatUrlFormatter.BasePath(new DomainReference(DomainType.Subverse, subverse)), suffix)),
                Sort        = null
            };
        }
예제 #3
0
        public async Task <ActionResult> Details(string name)
        {
            //TODO: Implement Command/Query - Remove direct Repository access
            using (var repo = new Repository(User))
            {
                var domainReference = DomainReference.Parse(name, DomainType.Set);
                var set             = repo.GetSet(domainReference.Name, domainReference.OwnerName);
                if (set == null)
                {
                    //Since system sets are not created until needed we show a slightly better error message for front/blocked.
                    if (name.IsEqual(SetType.Front.ToString()))
                    {
                        ViewBag.NavigationViewModel = new Models.ViewModels.NavigationViewModel()
                        {
                            Description = "Discover Search",
                            Name        = "No Idea",
                            MenuType    = Models.ViewModels.MenuType.Discovery,
                            BasePath    = VoatUrlFormatter.BasePath(domainReference),
                            Sort        = null
                        };
                        return(ErrorView(new ErrorViewModel()
                        {
                            Title = "No Subscriptions!", Description = "You don't have any subscriptions so we have to show you this instead", Footer = "Subscribe to a subverse you silly goat"
                        }));
                    }
                    else if (name.IsEqual(SetType.Blocked.ToString()))
                    {
                        ViewBag.NavigationViewModel = new Models.ViewModels.NavigationViewModel()
                        {
                            Description = "Discover Search",
                            Name        = "No Idea",
                            MenuType    = Models.ViewModels.MenuType.Discovery,
                            BasePath    = VoatUrlFormatter.BasePath(domainReference),
                            Sort        = null
                        };
                        return(ErrorView(new ErrorViewModel()
                        {
                            Title = "No Blocked Subs!", Description = "You don't have any blocked subs. Golf clap.", Footer = "Block some subs and this page will magically change!"
                        }));
                    }
                    else
                    {
                        return(ErrorView(new ErrorViewModel()
                        {
                            Title = "Can't find this set", Description = "Maybe it's gone?", Footer = "Probably yeah"
                        }));
                    }
                }

                var perms = SetPermission.GetPermissions(set.Map(), User.Identity);

                if (!perms.View)
                {
                    return(ErrorView(new ErrorViewModel()
                    {
                        Title = "Set is Private", Description = "This set doesn't allow the viewing of its properties", Footer = "It's ok, I can't see it either"
                    }));
                }

                var options = new SearchOptions(Request.QueryString.Value);
                options.Count = 50;

                var setList = await repo.GetSetListDescription(set.ID, options.Page);

                var model = new SetViewModel();
                model.Permissions    = perms;
                model.Set            = set.Map();
                model.List           = new PaginatedList <Domain.Models.SubverseSubscriptionDetail>(setList, options.Page, options.Count);
                model.List.RouteName = "SetDetails";

                ViewBag.NavigationViewModel = new NavigationViewModel()
                {
                    Name        = domainReference.FullName,
                    Description = set.Description,
                    BasePath    = VoatUrlFormatter.BasePath(domainReference),
                    MenuType    = (set.Type == (int)SetType.Front || set.Type == (int)SetType.Blocked ?  MenuType.Discovery : MenuType.Set)
                };
                return(View("Details", model));
            }
        }