public ActionResult List(int?id, int page = 1, string sort = "") { var topics = _db.Topics.Include(t => t.tag); if (id.HasValue && id.Value > 0) { if (_catUtil.GetCategoryList().Find(l => l.CategoryID == id.Value) == null) { return(NotFound()); } topics = topics.Where(b => b.CategoryID == id); } SearchModel model = new SearchModel { Sort = sort }; ViewBag.SearchModel = model; topics = BlogHelper.getSortedQuery(_db, topics, sort); if (Request.IsAjaxRequest()) { return(PartialView(topics.ToPagedList(page, listpagesize))); } return(View(topics.ToPagedList(page, listpagesize))); }
public IActionResult List() { IEnumerable <Models.Category> list = categoryUtil_.GetCategoryList(); if (!User.Identity.IsAuthenticated) { list = categoryUtil_.GetCategoryList().Where(c => c.ParentCategoryID == null); } return(Json(list.Select(c => new Models.App.Category { Id = c.CategoryID, Name = c.CategoryName, ParentId = c.ParentCategoryID }))); }
public async Task <ActionResult> Manage(string context) { AdminViewModel model = new AdminViewModel(); switch (context) { case "Category": model.allCategory = _catUtil.GetCategoryList(); model.allHanGroup = _db.HanGroups.Include("members").ToList(); ViewBag.HgMsg = TempData["HgMsg"]; ViewBag.CategoryMsg = TempData["CategoryMsg"]; break; case "Users": model.Admins = getAdmins(_udb); model.Writers = (await _userManager.GetUsersInRoleAsync("Writers")).ToList(); model.Auditors = getAuditors(_udb); model.BannedUsers = getBannedUsers(_udb); break; case "AdManage": model.AllAds = _db.Advertisments.ToList(); break; case "Parameter": model.appsettings = _appSettings; model.datasettings = _dataSettings; model.harmonyblogcount = _db.Blogs.Count(b => b.isHarmony); break; case "Register": model.registersettings = _regSettings; break; case "Background": model.backgroundsetting = _bgSettings; break; default: context = "Data"; model.harmonyblogcount = _db.Blogs.Count(b => b.isHarmony); model.auditcount = _db.Blogs.Where(b => b.isApproved == null && b.BlogID > 0).Count(); model.bannedusercount = (await _userManager.GetUsersInRoleAsync("Banned")).Count; model.todaynewitem = _db.Blogs.Where(b => DbFunctions.DiffDays(b.BlogDate, DateTime.Now) == 0).Count(); model.yesterdaynewitem = _db.Blogs.Where(b => DbFunctions.DiffDays(b.BlogDate, DateTime.Now) == 1).Count(); model.totalauditcount = _db.Blogs.Count(); model.totalusercount = _udb.Users.Count(); ViewBag.AdminLogs = GetLog(1); break; } ViewBag.Context = context; if (Request.IsAjaxRequest()) { return(PartialView(context + "Partial", model)); } return(View("Manage", model)); }
public async Task <ActionResult> List([FromServices] ISearchProvider searchProvider, int?id, SearchModel search, int page = 1) { int pagesize = ListPageSize; search = search ?? new SearchModel(); if (id.HasValue && id.Value > 0) { if (!_catUtil.GetCategoryList().Any(l => l.CategoryID == id.Value)) { return(NotFound()); } search.CurrentCategory = id; ViewBag.CategoryId = id; } if (IsHarmony) { search.Harmony = IsHarmony; } ViewBag.CurrentSort = search.SortOptions(); ViewBag.SearchModel = search; var cache = _cache.Get <ConcurrentDictionary <string, Task <SearchBlogResult> > > (CacheService.BlogListCacheKey); Func <string, object, ActionResult> Result = View; if (Request.IsAjaxRequest()) { Result = PartialView; } SearchBlogResult result; if (search.Cacheable()) { var cachekey = search.CacheKey(page, pagesize); cache = cache ?? new ConcurrentDictionary <string, Task <SearchBlogResult> >(); result = await cache.GetOrAdd(cachekey, (s) => { _cache.Set(CacheService.BlogListCacheKey, cache, new MemoryCacheEntryOptions() { Priority = CacheItemPriority.NeverRemove }); return(searchProvider.SearchBlogAsync(search, page, pagesize)); }); if (result.HasError) { cache.TryRemove(cachekey, out var removed); throw new TimeoutException("查询搜索服务器失败,请刷新重试"); } } else { result = await searchProvider.SearchBlogAsync(search, page, pagesize); } return(Result("List", result)); }
public IViewComponentResult Invoke() { List <Category> categories = _catUtil.GetCategoryList(); Dictionary <int, HeaderDisplay> model = _cache.Get <Dictionary <int, HeaderDisplay> >("HomeHeader"); if (model == null) { model = new Dictionary <int, HeaderDisplay>(categories.Count); var counts = _db.Blogs.Where(b => b.isApproved == true && DbFunctions.DiffDays(b.BlogDate, DateTime.Now) <= 1) .GroupBy(b => b.CategoryID) .Select(b => new { CategoryID = b.Key, newItems = b.Count() }) .ToList(); foreach (var c in categories) { int count = counts.Where(i => i.CategoryID == c.CategoryID).Sum(i => i.newItems); model.Add(c.CategoryID, new HeaderDisplay { category = c, newItems = count }); } int CalculateTotalItems(Category c) { if (c == null) { return(0); } if (c.SubCategories != null) { foreach (var subcat in c.SubCategories) { int count = CalculateTotalItems(subcat); model[c.CategoryID].newItems += count; } } return(model[c.CategoryID].newItems); } foreach (var main in model.Values.Where(h => !h.category.ParentCategoryID.HasValue)) { CalculateTotalItems(main.category); } _cache.Set("HomeHeader", model, TimeSpan.FromMinutes(10)); } if (_appSetting.Value.HarmonySettings.Harmony && !User.Identity.IsAuthenticated) { model = model.Where(p => !_appSetting.Value.HarmonySettings.BlacklistCategories.Contains(p.Key)).ToDictionary(p => p.Key, p => p.Value); } return(View(model)); }
public async Task <PartialViewResult> HPSetting(HPSettingsModel model) { string option, tagBlacklist = null; var allCategories = _catUtil.GetCategoryList(); var categories = model.GetCategoryOptions(); if (categories.SelectedIds.Count == 0 || (allCategories.Count == categories.SelectedIds.Count)) { option = string.Empty; } else { option = JsonConvert.SerializeObject(categories.SelectedIds); } if (!string.IsNullOrWhiteSpace(model.BlacklistTagNames)) { var taglist = TagUtil.SplitTags(model.BlacklistTagNames); if (taglist != null && taglist.Length > 0) { var tags = await _bdb.Tags.Where(t => taglist.Contains(t.TagName)).ToDictionaryAsync(t => t.TagName.ToLower(), t => t.TagID); var notfound = taglist.Where(n => !tags.ContainsKey(n.ToLower())); if (notfound.Any()) { ViewBag.NotFoundTags = string.Join(",", notfound); ViewBag.Success = false; return(PartialView("_HPSettingPartial", model)); } tagBlacklist = JsonConvert.SerializeObject(tags.Values.AsEnumerable()); } } UserProfile user = _db.Users.Include("option").SingleOrDefault(u => u.UserName == User.Identity.Name); if (user.option == null) { user.option = new UserOption(); } user.option.homepageCategories = option; user.option.homepageHideHarmony = model.HideHarmony; user.option.homepageTagBlacklist = tagBlacklist; _blogUtil.CacheUserOption(user.option, User.Identity.Name); await _db.SaveChangesAsync(); ViewBag.Success = true; return(PartialView("_HPSettingPartial", model)); }