public ActionResult Index(string id)
        {
            string observationId = VerbosifyId <Observation>(id);

            if (!_permissionManager.DoesExist <Observation>(observationId))
            {
                return(HttpNotFound());
            }

            dynamic viewModel = new ExpandoObject();

            viewModel.Observation = _sightingViewModelQuery.BuildSighting(observationId);

            return(RestfulResult(
                       viewModel,
                       "observations",
                       "index"));
        }
Exemplo n.º 2
0
        public ActionResult Index(string id)
        {
            string postId = VerbosifyId <Post>(id);

            if (!_permissionManager.DoesExist <Post>(postId))
            {
                return(HttpNotFound());
            }

            dynamic viewModel = new ExpandoObject();

            viewModel.Post = _postViewModelQuery.BuildPost(postId);

            return(RestfulResult(
                       viewModel,
                       "posts",
                       "index"));
        }
Exemplo n.º 3
0
        public ActionResult Index(string id)
        {
            string recordId = VerbosifyId <Record>(id);

            if (!_permissionManager.DoesExist <Record>(recordId))
            {
                return(HttpNotFound());
            }

            var viewModel = new
            {
                Record = _sightingViewModelQuery.BuildSighting(recordId)
            };

            return(RestfulResult(
                       viewModel,
                       "records",
                       "index"));
        }
        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"));
        }
        public ActionResult Sightings(string id, SightingsQueryInput queryInput)
        {
            string projectId = VerbosifyId <Project>(id);

            if (!_permissionManager.DoesExist <Project>(projectId))
            {
                return(HttpNotFound());
            }

            if (queryInput.View.ToLower() == "thumbnails")
            {
                queryInput.PageSize = 15;
            }

            if (queryInput.View.ToLower() == "details")
            {
                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.Category = queryInput.Category ?? string.Empty;
            if (!string.IsNullOrWhiteSpace(queryInput.Category) && !Categories.IsValidCategory(queryInput.Category))
            {
                queryInput.Category = string.Empty;
            }

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

            queryInput.Taxonomy = queryInput.Taxonomy ?? string.Empty;

            var projectResult = _documentSession
                                .Query <All_Groups.Result, All_Groups>()
                                .AsProjection <All_Groups.Result>()
                                .Where(x => x.GroupId == projectId)
                                .First();

            dynamic viewModel = new ExpandoObject();

            viewModel.Project                  = _projectViewModelQuery.BuildProject(projectId);
            viewModel.Sightings                = _sightingViewModelQuery.BuildGroupSightingList(projectId, queryInput);
            viewModel.UserCountDescription     = "Member" + (projectResult.UserCount == 1 ? string.Empty : "s");
            viewModel.SightingCountDescription = "Sighting" + (projectResult.SightingCount == 1 ? string.Empty : "s");
            viewModel.PostCountDescription     = "Post" + (projectResult.PostCount == 1 ? string.Empty : "s");
            viewModel.CategorySelectList       = Categories.GetSelectList(queryInput.Category);
            viewModel.Categories               = Categories.GetAll();
            viewModel.Query = new
            {
                Id = projectId,
                queryInput.Page,
                queryInput.PageSize,
                queryInput.Sort,
                queryInput.View,
                queryInput.Category,
                queryInput.NeedsId,
                queryInput.Query,
                queryInput.Field,
                queryInput.Taxonomy,
                IsThumbnailsView = queryInput.View == "thumbnails",
                IsDetailsView    = queryInput.View == "details",
                IsMapView        = queryInput.View == "map"
            };
            viewModel.ShowSightings   = true;
            viewModel.FieldSelectList = new[]
            {
                new
                {
                    Text     = "Sighting Title",
                    Value    = "title",
                    Selected = queryInput.Field.ToLower() == "title"
                },
                new
                {
                    Text     = "Descriptions",
                    Value    = "descriptions",
                    Selected = queryInput.Field.ToLower() == "descriptions"
                },
                new
                {
                    Text     = "Tags",
                    Value    = "tags",
                    Selected = queryInput.Field.ToLower() == "tags"
                },
                new
                {
                    Text     = "Scientific Name",
                    Value    = "scientificname",
                    Selected = queryInput.Field.ToLower() == "scientificname"
                },
                new
                {
                    Text     = "Common Name",
                    Value    = "commonname",
                    Selected = queryInput.Field.ToLower() == "commonname"
                }
            };

            return(RestfulResult(
                       viewModel,
                       "projects",
                       "sightings"));
        }