示例#1
0
        public ActionResult PublicIndex()
        {
            var sightingQueryInput = new SightingsQueryInput
            {
                Sort     = "popular",
                Page     = 1,
                PageSize = 20
            };

            dynamic viewModel = new ExpandoObject();

            viewModel.HomeHeader = true;
            viewModel.Sightings  = viewModel.Sightings = _sightingViewModelQuery.BuildSightingList(sightingQueryInput);

            return(RestfulResult(
                       viewModel,
                       "home",
                       "publicindex"));
        }
        public ActionResult List(SightingsQueryInput queryInput)
        {
            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;

            dynamic viewModel = new ExpandoObject();

            viewModel.Sightings          = _sightingViewModelQuery.BuildSightingList(queryInput);
            viewModel.CategorySelectList = Categories.GetSelectList(queryInput.Category);
            viewModel.Categories         = Categories.GetAll();
            viewModel.Query = new
            {
                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,
                       "sightings",
                       "list"));
        }