Пример #1
0
        public override async Task <IViewProviderResult> BuildDisplayAsync(UserIndex userIndex, IViewProviderContext context)
        {
            // Get user
            var user = await _platoUserStore.GetByIdAsync(userIndex.Id);

            if (user == null)
            {
                return(await BuildIndexAsync(userIndex, context));
            }


            // Get index view model from context
            var indexViewModel = context.Controller.HttpContext.Items[typeof(EntityIndexViewModel <Question>)] as EntityIndexViewModel <Question>;

            if (indexViewModel == null)
            {
                throw new Exception($"A view model of type {typeof(EntityIndexViewModel<Question>).ToString()} has not been registered on the HttpContext!");
            }

            // Build feature entities model
            var featureEntityMetrics = new FeatureEntityCounts()
            {
                Features = await _featureEntityCountService
                           .ConfigureQuery(q =>
                {
                    q.CreatedUserId.Equals(user.Id);
                    q.HideSpam.True();
                    q.HideHidden.True();
                    q.HideDeleted.True();
                    q.HidePrivate.True();
                })
                           .GetResultsAsync()
            };

            // Build view model
            var userDisplayViewModel = new UserDisplayViewModel <Question>()
            {
                User           = user,
                IndexViewModel = indexViewModel,
                Counts         = featureEntityMetrics
            };

            // Build view
            return(Views(
                       View <UserDisplayViewModel>("User.Index.Header", model => userDisplayViewModel).Zone("header"),
                       View <UserDisplayViewModel <Question> >("User.Index.Content", model => userDisplayViewModel).Zone("content"),
                       View <UserDisplayViewModel>("User.Entities.Display.Sidebar", model => userDisplayViewModel).Zone("content-right")
                       ));
        }
Пример #2
0
        public async Task OnActionExecutingAsync(ResultExecutingContext context)
        {
            // The controller action didn't return a view result so no need to continue execution
            if (!(context.Result is ViewResult result))
            {
                return;
            }

            // Check early to ensure we are working with a LayoutViewModel
            if (!(result.Model is LayoutViewModel model))
            {
                return;
            }

            // We need route values to check
            if (context.RouteData?.Values == null)
            {
                return;
            }

            // We need an area
            if (!context.RouteData.Values.ContainsKey("area"))
            {
                return;
            }

            // We need a controller
            if (!context.RouteData.Values.ContainsKey("controller"))
            {
                return;
            }

            // We need an action
            if (!context.RouteData.Values.ContainsKey("action"))
            {
                return;
            }

            // Plato.Core?
            var isArea = context.RouteData.Values["area"].ToString()
                         .Equals("Plato.Core", StringComparison.OrdinalIgnoreCase);

            // Not area
            if (!isArea)
            {
                return;
            }

            // Home controller?
            var isController = context.RouteData.Values["controller"].ToString()
                               .Equals("Home", StringComparison.OrdinalIgnoreCase);

            // Not controller
            if (!isController)
            {
                return;
            }

            // Index action?
            var isAction = context.RouteData.Values["action"].ToString()
                           .Equals("Index", StringComparison.OrdinalIgnoreCase);

            // Not action
            if (!isAction)
            {
                return;
            }

            // We are on the homepage, register metrics on context
            context.HttpContext.Items[typeof(FeatureEntityCounts)] = new FeatureEntityCounts()
            {
                Features = await _featureEntityCountService
                           .ConfigureQuery(async q =>
                {
                    // Hide private?
                    if (!await _authorizationService.AuthorizeAsync(context.HttpContext.User,
                                                                    Permissions.ViewPrivateEntities))
                    {
                        q.HidePrivate.True();
                    }

                    // Hide hidden?
                    if (!await _authorizationService.AuthorizeAsync(context.HttpContext.User,
                                                                    Permissions.ViewHiddenEntities))
                    {
                        q.HideHidden.True();
                    }

                    // Hide spam?
                    if (!await _authorizationService.AuthorizeAsync(context.HttpContext.User,
                                                                    Permissions.ViewSpamEntities))
                    {
                        q.HideSpam.True();
                    }

                    // Hide deleted?
                    if (!await _authorizationService.AuthorizeAsync(context.HttpContext.User,
                                                                    Permissions.ViewDeletedEntities))
                    {
                        q.HideDeleted.True();
                    }
                })
                           .GetResultsAsync(null)
            };
        }
Пример #3
0
        public override async Task <IViewProviderResult> BuildDisplayAsync(ProfilePage profile, IViewProviderContext context)
        {
            // Get user
            var user = await _platoUserStore.GetByIdAsync(profile.Id);

            // Ensure user exists
            if (user == null)
            {
                return(await BuildIndexAsync(profile, context));
            }

            var indexOptions = new EntityIndexOptions()
            {
                CreatedByUserId = user.Id
            };


            var featureEntityMetrics = new FeatureEntityCounts()
            {
                Features = await _featureEntityCountService
                           .ConfigureQuery(async q =>
                {
                    // Hide private?
                    if (!await _authorizationService.AuthorizeAsync(context.Controller.HttpContext.User,
                                                                    Permissions.ViewPrivateEntities))
                    {
                        q.HidePrivate.True();
                    }

                    // Hide hidden?
                    if (!await _authorizationService.AuthorizeAsync(context.Controller.HttpContext.User,
                                                                    Permissions.ViewHiddenEntities))
                    {
                        q.HideHidden.True();
                    }

                    // Hide spam?
                    if (!await _authorizationService.AuthorizeAsync(context.Controller.HttpContext.User,
                                                                    Permissions.ViewSpamEntities))
                    {
                        q.HideSpam.True();
                    }

                    // Hide deleted?
                    if (!await _authorizationService.AuthorizeAsync(context.Controller.HttpContext.User,
                                                                    Permissions.ViewDeletedEntities))
                    {
                        q.HideDeleted.True();
                    }
                })
                           .GetResultsAsync(indexOptions)
            };

            var viewModel = new UserDisplayViewModel <Entity>()
            {
                User           = user,
                Counts         = featureEntityMetrics,
                IndexViewModel = new EntityIndexViewModel <Entity>()
                {
                    Options = indexOptions,
                    Pager   = new PagerOptions()
                    {
                        Page    = 1,
                        Size    = 10,
                        Enabled = false
                    }
                }
            };

            // Return view
            return(Views(
                       View <UserDisplayViewModel <Entity> >("Profile.Entities.Display.Content", model => viewModel)
                       .Zone("content")
                       .Order(int.MaxValue - 100)
                       ));
        }
Пример #4
0
        public override async Task <IViewProviderResult> BuildDisplayAsync(EntityUserIndex userIndex, IViewProviderContext context)
        {
            var user = await _platoUserStore.GetByIdAsync(userIndex.Id);

            if (user == null)
            {
                return(await BuildIndexAsync(userIndex, context));
            }

            var indexViewModel = context.Controller.HttpContext.Items[typeof(EntityIndexViewModel <Entity>)] as EntityIndexViewModel <Entity>;

            if (indexViewModel == null)
            {
                throw new Exception($"A view model of type {typeof(EntityIndexViewModel<Entity>).ToString()} has not been registered on the HttpContext!");
            }



            var featureEntityMetrics = new FeatureEntityCounts()
            {
                Features = await _featureEntityCountService
                           .ConfigureQuery(q =>
                {
                    q.CreatedUserId.Equals(user.Id);
                    q.HideSpam.True();
                    q.HideHidden.True();
                    q.HideDeleted.True();
                    q.HidePrivate.True();

                    //// Hide private?
                    //if (!await _authorizationService.AuthorizeAsync(context.Controller.HttpContext.User,
                    //    Permissions.ViewPrivateEntities))
                    //{
                    //    q.HidePrivate.True();
                    //}

                    //// Hide hidden?
                    //if (!await _authorizationService.AuthorizeAsync(context.Controller.HttpContext.User,
                    //    Permissions.ViewHiddenEntities))
                    //{
                    //    q.HideHidden.True();
                    //}

                    //// Hide spam?
                    //if (!await _authorizationService.AuthorizeAsync(context.Controller.HttpContext.User,
                    //    Permissions.ViewSpamEntities))
                    //{
                    //    q.HideSpam.True();
                    //}

                    //// Hide deleted?
                    //if (!await _authorizationService.AuthorizeAsync(context.Controller.HttpContext.User,
                    //    Permissions.ViewDeletedEntities))
                    //{
                    //    q.HideDeleted.True();
                    //}
                })
                           .GetResultsAsync()
            };

            var userDisplayViewModel = new UserDisplayViewModel <Entity>()
            {
                User           = user,
                IndexViewModel = indexViewModel,
                Counts         = featureEntityMetrics
            };

            return(Views(
                       View <UserDisplayViewModel>("User.Index.Header", model => userDisplayViewModel).Zone("header"),
                       View <UserDisplayViewModel <Entity> >("User.Index.Content", model => userDisplayViewModel).Zone("content"),
                       View <UserDisplayViewModel>("User.Entities.Display.Sidebar", model => userDisplayViewModel).Zone("sidebar")
                       ));
        }