public ActionResult Posts(string id, PostsQueryInput queryInput)
        {
            string organisationId = VerbosifyId<Organisation>(id);

            if (!_permissionManager.DoesExist<Organisation>(organisationId))
            {
                return HttpNotFound();
            }

            queryInput.PageSize = 10;

            if (string.IsNullOrWhiteSpace(queryInput.Sort) ||
                (queryInput.Sort.ToLower() != "newest" &&
                queryInput.Sort.ToLower() != "oldest" &&
                queryInput.Sort.ToLower() != "a-z" &&
                queryInput.Sort.ToLower() != "z-a"))
            {
                queryInput.Sort = "newest";
            }

            queryInput.Query = queryInput.Query ?? string.Empty;
            queryInput.Field = queryInput.Field ?? string.Empty;

            var organisationResult = _documentSession
                .Query<All_Groups.Result, All_Groups>()
                .AsProjection<All_Groups.Result>()
                .First(x => x.GroupId == organisationId);

            dynamic viewModel = new ExpandoObject();
            viewModel.Organisation = _organisationViewModelQuery.BuildOrganisation(organisationId);
            viewModel.Posts = _postViewModelQuery.BuildGroupPostList(organisationId, queryInput);
            viewModel.UserCountDescription = "Member" + (organisationResult.UserCount == 1 ? string.Empty : "s");
            viewModel.PostCountDescription = "Post" + (organisationResult.PostCount == 1 ? string.Empty : "s");
            viewModel.Query = new
            {
                Id = organisationId,
                queryInput.Page,
                queryInput.PageSize,
                queryInput.Sort,
                queryInput.Query,
                queryInput.Field
            };
            viewModel.ShowPosts = true;
            viewModel.FieldSelectList = new[]
                {
                    new
                        {
                            Text = "Title",
                            Value = "title",
                            Selected = queryInput.Field.ToLower() == "title"
                        },
                    new
                        {
                            Text = "Body",
                            Value = "body",
                            Selected = queryInput.Field.ToLower() == "body"
                        }
                };

            return RestfulResult(
                viewModel,
                "organisations",
                "posts");
        }
Exemplo n.º 2
0
        public ActionResult Posts(PostsQueryInput queryInput)
        {
            queryInput.PageSize = 10;

            if (string.IsNullOrWhiteSpace(queryInput.Sort) ||
                (queryInput.Sort.ToLower() != "newest" &&
                queryInput.Sort.ToLower() != "oldest" &&
                queryInput.Sort.ToLower() != "a-z" &&
                queryInput.Sort.ToLower() != "z-a"))
            {
                queryInput.Sort = "newest";
            }

            queryInput.Query = queryInput.Query ?? string.Empty;
            queryInput.Field = queryInput.Field ?? string.Empty;

            dynamic viewModel = new ExpandoObject();
            viewModel.User = _userViewModelQuery.BuildUser(_userContext.GetAuthenticatedUserId());
            viewModel.Posts = _postViewModelQuery.BuildHomePostList(_userContext.GetAuthenticatedUserId(), queryInput);
            viewModel.Query = new
            {
                Id = "home", // We set the id to home, so that the mustache sightings list creates correct sorting URL
                queryInput.Page,
                queryInput.PageSize,
                queryInput.Sort,
                queryInput.Query,
                queryInput.Field
            };
            viewModel.ShowPosts = true;
            viewModel.FieldSelectList = new[]
                {
                    new
                        {
                            Text = "Title",
                            Value = "title",
                            Selected = queryInput.Field.ToLower() == "title"
                        },
                    new
                        {
                            Text = "Body",
                            Value = "descriptions",
                            Selected = queryInput.Field.ToLower() == "descriptions"
                        }
                };

            return RestfulResult(
                viewModel,
                "home",
                "posts");
        }