Esempio n. 1
0
        public ActionResult PrivateIndex(ActivitiesQueryInput activityInput, PagingInput pagingInput)
        {
            var profiler = MiniProfiler.Current;

            using (profiler.Step("Check if user is authenticated"))
            {
                if (!_userContext.IsUserAuthenticated())
                {
                    return(RedirectToAction("PublicIndex"));
                }
            }

            dynamic viewModel = new ExpandoObject();

            using (profiler.Step("Build private index view model"))
            {
                var userResult = _documentSession
                                 .Query <All_Users.Result, All_Users>()
                                 .AsProjection <All_Users.Result>()
                                 .Where(x => x.UserId == _userContext.GetAuthenticatedUserId())
                                 .First();

                viewModel.User = _userViewModelQuery.BuildUser(_userContext.GetAuthenticatedUserId());
                using (profiler.Step("Build timeline items (ActivityViewModelQuery.BuildHomeActivityList)"))
                {
                    viewModel.Activities = _activityViewModelQuery.BuildHomeActivityList(_userContext.GetAuthenticatedUserId(), activityInput, pagingInput);
                }
                viewModel.ShowUserWelcome = userResult.User.CallsToAction.Contains("user-welcome");
                viewModel.ShowActivities  = true;
            }

            return(RestfulResult(
                       viewModel,
                       "home",
                       "privateindex"));
        }
        public ActionResult Sightings(string id, SightingsQueryInput queryInput)
        {
            string userId = VerbosifyId <User>(id);

            if (!_permissionManager.DoesExist <User>(userId))
            {
                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() != "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 userResult = _documentSession
                             .Query <All_Users.Result, All_Users>()
                             .Where(x => x.UserId == userId)
                             .First();

            dynamic viewModel = new ExpandoObject();

            viewModel.User      = _userViewModelQuery.BuildUser(userId);
            viewModel.Sightings = _sightingViewModelQuery.BuildGroupSightingList(userResult.User.UserProject.Id, queryInput);
            viewModel.SightingCountDescription     = "Sighting" + (userResult.SightingCount == 1 ? string.Empty : "s");
            viewModel.ProjectCountDescription      = "Project" + (userResult.Projects.Count() == 1 ? string.Empty : "s");
            viewModel.OrganisationCountDescription = "Organisation" + (userResult.Organisations.Count() == 1 ? string.Empty : "s");
            viewModel.CategorySelectList           = Categories.GetSelectList(queryInput.Category);
            viewModel.Query = new
            {
                Id = userId,
                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,
                       "users",
                       "sightings"));
        }