public async Task <IActionResult> Index(DisplayUserOptions opts) { if (opts == null) { opts = new DisplayUserOptions(); } var user = opts.Id > 0 ? await _platoUserStore.GetByIdAsync(opts.Id) : await _contextFacade.GetAuthenticatedUserAsync(); if (user == null) { return(NotFound()); } // Build page title _pageTitleBuilder.AddSegment(S[user.DisplayName], int.MaxValue); // Breadcrumb _breadCrumbManager.Configure(builder => { builder.Add(S["Home"], home => home .Action("Index", "Home", "Plato.Core") .LocalNav() ).Add(S["Users"], discuss => discuss .Action("Index", "Home", "Plato.Users") .LocalNav() ).Add(S[user.DisplayName], discuss => discuss .Action("Display", "Home", "Plato.Users", new RouteValueDictionary() { ["opts.id"] = user.Id, ["opts.alias"] = user.Alias }) .LocalNav() ).Add(S["Badges"]); }); // Return view return(View((LayoutViewModel)await _userBadgeViewProvider.ProvideIndexAsync(new UserBadge() { UserId = user.Id }, this))); }
public async Task <IActionResult> Index(EntityIndexOptions opts, PagerOptions pager) { // Build options if (opts == null) { opts = new EntityIndexOptions(); } // Build pager if (pager == null) { pager = new PagerOptions(); } // Get category var category = await _categoryStore.GetByIdAsync(opts.CategoryId); // If supplied ensure category exists if (category == null && opts.CategoryId > 0) { return(NotFound()); } // Get default options var defaultViewOptions = new EntityIndexOptions(); var defaultPagerOptions = new PagerOptions(); // Add non default route data for pagination purposes if (opts.Search != defaultViewOptions.Search) { this.RouteData.Values.Add("opts.search", opts.Search); } if (opts.Sort != defaultViewOptions.Sort) { this.RouteData.Values.Add("opts.sort", opts.Sort); } if (opts.Order != defaultViewOptions.Order) { this.RouteData.Values.Add("opts.order", opts.Order); } if (opts.Filter != defaultViewOptions.Filter) { this.RouteData.Values.Add("opts.filter", opts.Filter); } if (pager.Page != defaultPagerOptions.Page) { this.RouteData.Values.Add("pager.page", pager.Page); } if (pager.Size != defaultPagerOptions.Size) { this.RouteData.Values.Add("pager.size", pager.Size); } // Build view model var viewModel = await GetIndexViewModelAsync(category, opts, pager); // Add view model to context HttpContext.Items[typeof(EntityIndexViewModel <Topic>)] = viewModel; // If we have a pager.page querystring value return paged results if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page)) { if (page > 0 && !pager.Enabled) { return(View("GetTopics", viewModel)); } } // Return Url for authentication purposes ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Discuss.Categories", ["controller"] = "Home", ["action"] = "Index", ["opts.categoryId"] = category != null ? category.Id.ToString() : "", ["opts.alias"] = category != null ? category.Alias.ToString() : "" }); // Build page title if (category != null) { _pageTitleBuilder.AddSegment(S[category.Name], int.MaxValue); } // Build breadcrumb _breadCrumbManager.Configure(async builder => { builder.Add(S["Home"], home => home .Action("Index", "Home", "Plato.Core") .LocalNav() ).Add(S["Discuss"], home => home .Action("Index", "Home", "Plato.Discuss") .LocalNav() ); // Build breadcrumb var parents = category != null ? await _categoryStore.GetParentsByIdAsync(category.Id) : null; if (parents == null) { builder.Add(S["Categories"]); } else { builder.Add(S["Categories"], c => c .Action("Index", "Home", "Plato.Discuss.Categories", new RouteValueDictionary() { ["opts.categoryId"] = null, ["opts.alias"] = null }) .LocalNav() ); foreach (var parent in parents) { if (parent.Id != category.Id) { builder.Add(S[parent.Name], channel => channel .Action("Index", "Home", "Plato.Discuss.Categories", new RouteValueDictionary { ["opts.categoryId"] = parent.Id, ["opts.alias"] = parent.Alias, }) .LocalNav() ); } else { builder.Add(S[parent.Name]); } } } }); // Return view return(View((LayoutViewModel)await _categoryViewProvider.ProvideIndexAsync(category, this))); }
public async Task <IActionResult> Index(EntityIndexOptions opts, PagerOptions pager) { // Default options if (opts == null) { opts = new EntityIndexOptions(); } // Default pager if (pager == null) { pager = new PagerOptions(); } // Get user var user = await _platoUserStore.GetByIdAsync(opts.CreatedByUserId); // Ensure user exists if (user == null) { return(NotFound()); } // Get default options var defaultViewOptions = new EntityIndexOptions(); var defaultPagerOptions = new PagerOptions(); // Add non default route data for pagination purposes if (opts.Search != defaultViewOptions.Search) { this.RouteData.Values.Add("opts.search", opts.Search); } if (opts.Sort != defaultViewOptions.Sort) { this.RouteData.Values.Add("opts.sort", opts.Sort); } if (opts.Order != defaultViewOptions.Order) { this.RouteData.Values.Add("opts.order", opts.Order); } if (opts.Filter != defaultViewOptions.Filter) { this.RouteData.Values.Add("opts.filter", opts.Filter); } if (pager.Page != defaultPagerOptions.Page) { this.RouteData.Values.Add("pager.page", pager.Page); } if (pager.Size != defaultPagerOptions.Size) { this.RouteData.Values.Add("pager.size", pager.Size); } // Build view model var viewModel = await GetIndexViewModelAsync(opts, pager); // Add view model to context HttpContext.Items[typeof(EntityIndexViewModel <Article>)] = viewModel; // If we have a pager.page querystring value return paged results if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page)) { if (page > 0) { return(View("GetArticles", viewModel)); } } // Build page title _pageTitleBuilder .AddSegment(S["Users"]) .AddSegment(S[user.DisplayName]) .AddSegment(S["Articles"]); // Build breadcrumb _breadCrumbManager.Configure(builder => { builder.Add(S["Home"], home => home .Action("Index", "Home", "Plato.Core") .LocalNav() ).Add(S["Users"], users => users .Action("Index", "Home", "Plato.Users") .LocalNav() ).Add(S[user.DisplayName], name => name .Action("Display", "Home", "Plato.Users", new RouteValueDictionary() { ["opts.id"] = user.Id, ["opts.alias"] = user.Alias }) .LocalNav() ).Add(S["Articles"]); }); //// Return view return(View((LayoutViewModel)await _userViewProvider.ProvideDisplayAsync(new UserIndex() { Id = user.Id }, this))); }
public async Task <IActionResult> Display(EntityIndexOptions opts, PagerOptions pager) { // Get label var label = await _labelStore.GetByIdAsync(opts.LabelId); // Ensure label exists if (label == null) { return(NotFound()); } // Get default options var defaultViewOptions = new EntityIndexOptions(); var defaultPagerOptions = new PagerOptions(); // Add non default route data for pagination purposes if (opts.Search != defaultViewOptions.Search && !this.RouteData.Values.ContainsKey("opts.search")) { this.RouteData.Values.Add("opts.search", opts.Search); } if (opts.Sort != defaultViewOptions.Sort && !this.RouteData.Values.ContainsKey("opts.sort")) { this.RouteData.Values.Add("opts.sort", opts.Sort); } if (opts.Order != defaultViewOptions.Order && !this.RouteData.Values.ContainsKey("opts.order")) { this.RouteData.Values.Add("opts.order", opts.Order); } if (pager.Page != defaultPagerOptions.Page && !this.RouteData.Values.ContainsKey("pager.page")) { this.RouteData.Values.Add("pager.page", pager.Page); } if (pager.Size != defaultPagerOptions.Size && !this.RouteData.Values.ContainsKey("pager.size")) { this.RouteData.Values.Add("pager.size", pager.Size); } // Build view model var viewModel = await GetDisplayViewModelAsync(opts, pager); // Add view model to context this.HttpContext.Items[typeof(EntityIndexViewModel <Issue>)] = viewModel; // If we have a pager.page querystring value return paged results if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page)) { if (page > 0 && !pager.Enabled) { return(View("GetIssues", viewModel)); } } // Return Url for authentication purposes ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Issues.Labels", ["controller"] = "Home", ["action"] = "Display", ["opts.labelId"] = label != null ? label.Id.ToString() : "", ["opts.alias"] = label != null ? label.Alias.ToString() : "" }); // Build page title _pageTitleBuilder.AddSegment(S[label.Name], int.MaxValue); // Build breadcrumb _breadCrumbManager.Configure(builder => { builder.Add(S["Home"], home => home .Action("Index", "Home", "Plato.Core") .LocalNav() ).Add(S["Issues"], issues => issues .Action("Index", "Home", "Plato.Issues") .LocalNav() ).Add(S["Labels"], labels => labels .Action("Index", "Home", "Plato.Issues.Labels") .LocalNav() ).Add(S[label.Name]); }); // Return view return(View((LayoutViewModel)await _labelViewProvider.ProvideDisplayAsync(label, this))); }
public async Task <IActionResult> Display(EntityIndexOptions opts, PagerOptions pager) { // Default options if (opts == null) { opts = new EntityIndexOptions(); } // Default pager if (pager == null) { pager = new PagerOptions(); } // Get tag var tag = await _tagStore.GetByIdAsync(opts.TagId); // Ensure tag exists if (tag == null) { return(NotFound()); } // Get default options var defaultViewOptions = new EntityIndexOptions(); var defaultPagerOptions = new PagerOptions(); // Add non default route data for pagination purposes if (opts.Search != defaultViewOptions.Search) { this.RouteData.Values.Add("opts.search", opts.Search); } if (opts.Sort != defaultViewOptions.Sort) { this.RouteData.Values.Add("opts.sort", opts.Sort); } if (opts.Order != defaultViewOptions.Order) { this.RouteData.Values.Add("opts.order", opts.Order); } if (opts.Filter != defaultViewOptions.Filter) { this.RouteData.Values.Add("opts.filter", opts.Filter); } if (pager.Page != defaultPagerOptions.Page) { this.RouteData.Values.Add("pager.page", pager.Page); } if (pager.Size != defaultPagerOptions.Size) { this.RouteData.Values.Add("pager.size", pager.Size); } // Build view model var viewModel = await GetDisplayViewModelAsync(opts, pager); // Add view model to context HttpContext.Items[typeof(EntityIndexViewModel <Topic>)] = viewModel; // If we have a pager.page querystring value return paged results if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page)) { if (page > 0) { return(View("GetTopics", viewModel)); } } // Return Url for authentication purposes ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Discuss.Tags", ["controller"] = "Home", ["action"] = "Display", ["opts.tagId"] = tag != null ? tag.Id.ToString() : "", ["opts.alias"] = tag != null ? tag.Alias.ToString() : "" }); // Build page title _pageTitleBuilder.AddSegment(S[tag.Name], int.MaxValue); // Breadcrumb _breadCrumbManager.Configure(builder => { builder.Add(S["Home"], home => home .Action("Index", "Home", "Plato.Core") .LocalNav() ).Add(S["Discuss"], discuss => discuss .Action("Index", "Home", "Plato.Discuss") .LocalNav() ).Add(S["Tags"], tags => tags .Action("Index", "Home", "Plato.Discuss.Tags") .LocalNav() ).Add(S[tag.Name]); }); // Return view return(View((LayoutViewModel)await _tagViewProvider.ProvideDisplayAsync(new Tag(tag), this))); }
public async Task <IActionResult> Display(EntityIndexOptions opts, PagerOptions pager) { // Default options if (opts == null) { opts = new EntityIndexOptions(); } // Default pager if (pager == null) { pager = new PagerOptions(); } // Get tag var tag = await _tagStore.GetByIdAsync(opts.TagId); // Ensure tag exists if (tag == null) { return(NotFound()); } // Get default options var defaultViewOptions = new EntityIndexOptions(); var defaultPagerOptions = new PagerOptions(); // Add non default route data for pagination purposes if (opts.Search != defaultViewOptions.Search) { this.RouteData.Values.Add("opts.search", opts.Search); } if (opts.Sort != defaultViewOptions.Sort) { this.RouteData.Values.Add("opts.sort", opts.Sort); } if (opts.Order != defaultViewOptions.Order) { this.RouteData.Values.Add("opts.order", opts.Order); } if (opts.Filter != defaultViewOptions.Filter) { this.RouteData.Values.Add("opts.filter", opts.Filter); } if (pager.Page != defaultPagerOptions.Page) { this.RouteData.Values.Add("pager.page", pager.Page); } if (pager.Size != defaultPagerOptions.Size) { this.RouteData.Values.Add("pager.size", pager.Size); } // Build view model var viewModel = await GetDisplayViewModelAsync(opts, pager); // Add view model to context HttpContext.Items[typeof(EntityIndexViewModel <Question>)] = viewModel; // If we have a pager.page querystring value return paged results if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page)) { if (page > 0) { return(View("GetQuestions", viewModel)); } } // Build page title _pageTitleBuilder.AddSegment(S[tag.Name], int.MaxValue); // Breadcrumb _breadCrumbManager.Configure(builder => { builder.Add(S["Home"], home => home .Action("Index", "Home", "Plato.Core") .LocalNav() ).Add(S["Questions"], questions => questions .Action("Index", "Home", "Plato.Questions") .LocalNav() ).Add(S["Tags"], labels => labels .Action("Index", "Home", "Plato.Questions.Tags") .LocalNav() ).Add(S[tag.Name]); }); // Return view return(View((LayoutViewModel)await _tagViewProvider.ProvideDisplayAsync(new Tag(tag), this))); }
// ----------------- // Display User // ----------------- public async Task <IActionResult> Display(DisplayUserOptions opts) { // Ensure we have permission if (!await _authorizationService.AuthorizeAsync(User, Permissions.ViewProfiles)) { return(Unauthorized()); } // Get user to display var user = opts.Id > 0 ? await _platoUserStore.GetByIdAsync(opts.Id) : await _contextFacade.GetAuthenticatedUserAsync(); if (user == null) { return(NotFound()); } // Ensure we have permission to view unconfirmed accounts if (!user.EmailConfirmed) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ViewUnconfirmedUsers)) { return(Unauthorized()); } } // Ensure we have permission to view users flagged as SPAM if (user.IsSpam) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ViewSpamUsers)) { return(Unauthorized()); } } // Ensure we have permission to view banned users if (user.IsBanned) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ViewBannedUsers)) { return(Unauthorized()); } } // Return Url for authentication & canonical url purposes ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = user != null ? user.Id.ToString() : "", ["opts.alias"] = user != null ? user.Alias : "" });; // Build page title _pageTitleBuilder.AddSegment(S[user.DisplayName], int.MaxValue); // Build breadcrumb _breadCrumbManager.Configure(builder => { builder.Add(S["Home"], home => home .Action("Index", "Home", "Plato.Core") .LocalNav() ).Add(S["Users"], discuss => discuss .Action("Index", "Home", "Plato.Users") .LocalNav() ).Add(S[user.DisplayName]); }); // Add user to context HttpContext.Items[typeof(User)] = user; // Build view model var viewModel = new ProfilePage() { Id = user.Id }; // Return view return(View((LayoutViewModel)await _viewProvider.ProvideDisplayAsync(viewModel, this))); }
public async Task <IActionResult> Index(FeatureIndexOptions opts) { // Ensure we have permission if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageFeatures)) { return(Unauthorized()); } if (opts == null) { opts = new FeatureIndexOptions(); } var category = await GetCategoriesNameAsync(opts.Category); // Ensure the supplied category is valid if (string.IsNullOrEmpty(category)) { return(NotFound()); } if (category.ToLower() != "all") { // Build page title _pageTitleBuilder.AddSegment(S[category], int.MaxValue); // Build breadcrumb _breadCrumbManager.Configure(builder => { builder .Add(S["Home"], home => home .Action("Index", "Admin", "Plato.Admin") .LocalNav()) .Add(S["Features"], features => features .Action("Index", "Admin", "Plato.Features", new RouteValueDictionary() { ["opts.category"] = "" }) .LocalNav()) .Add(S[category]); }); } else { _breadCrumbManager.Configure(builder => { builder.Add(S["Home"], home => home .Action("Index", "Admin", "Plato.Admin") .LocalNav() ).Add(S["Features"]); }); } opts.Category = category; var model = new FeaturesIndexViewModel() { Options = opts }; return(View((LayoutViewModel)await _viewProvider.ProvideIndexAsync(model, this))); }