public async Task <ActionResult> Category(int id, [Optional] OrderBy?orderBy, int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 15) { page = Math.Max(1, page); var cat = await CategoryService.GetByIdAsync(id) ?? throw new NotFoundException("文章分类未找到"); var cids = cat.Flatten().Select(c => c.Id).ToArray(); var h24 = DateTime.Today.AddDays(-1); var posts = orderBy switch { OrderBy.Trending => await PostService.GetQuery(PostBaseWhere().And(p => cids.Contains(p.CategoryId) && p.Status == Status.Published)).OrderByDescending(p => p.PostVisitRecordStats.Where(e => e.Date >= h24).Sum(e => e.Count)).ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig), _ => await PostService.GetQuery(PostBaseWhere().And(p => cids.Contains(p.CategoryId) && p.Status == Status.Published)).OrderBy($"{nameof(PostDto.IsFixedTop)} desc,{(orderBy ?? OrderBy.ModifyDate).GetDisplay()} desc").ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig) }; var viewModel = await GetIndexPageViewModel(); viewModel.Posts = posts; ViewBag.Category = cat; viewModel.PageParams = new Pagination(page, size, posts.TotalCount, orderBy); viewModel.SidebarAds = AdsService.GetsByWeightedPrice(2, AdvertiseType.SideBar, Request.Location(), id); viewModel.ListAdvertisement = AdsService.GetByWeightedPrice(AdvertiseType.ListItem, Request.Location(), id); PostService.SolvePostsCategory(posts.Data); foreach (var item in posts.Data) { item.ModifyDate = item.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); } return(View(viewModel)); }
public async Task <IActionResult> Save(AdvertisementDto model) { model.CategoryIds = model.CategoryIds?.Replace("null", ""); var b = await AdsService.AddOrUpdateSavedAsync(a => a.Id, model.Mapper <Advertisement>()) > 0; return(ResultData(null, b, b ? "保存成功" : "保存失败")); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_download_song); GoogleAnalyticsService.Instance.Initialize(this); GoogleAnalyticsService.Instance.TrackAppPage("Download Song"); video = SearchSongs.getSelectedVideo(); videoName = FindViewById <TextView>(Resource.Id.videoName); channelName = FindViewById <TextView>(Resource.Id.channelName); videoImg = FindViewById <ImageView>(Resource.Id.videoImg); progressBar = FindViewById <ProgressBar>(Resource.Id.downloadingProgressBar); downloadBtn = FindViewById <Button>(Resource.Id.downloadBtn); downloadBtn.SetBackgroundColor(new Color(ContextCompat.GetColor(this, Resource.Color.darkassets))); DownloadWatcher.onDownloaded += (sender, e) => TogglePlay(); DownloadWatcher.onDownloadFailed += (sender, e) => ToggelDownload(); if (AdsService.DownloadSongAd == null) { AdsService.DownloadSongAd = FindViewById <AdView>(Resource.Id.adView); AdsService.LoadBanner(AdsService.DownloadSongAd); } UpdateView(); }
public ActionResult Index(int id, [Optional] OrderBy?orderBy, int page = 1, int size = 15) { IList <Post> posts; var s = SeminarService.GetById(id) ?? throw new NotFoundException("文章未找到"); var temp = PostService.GetQuery(p => p.Seminar.Any(x => x.SeminarId == id) && (p.Status == Status.Pended || CurrentUser.IsAdmin)).OrderByDescending(p => p.IsFixedTop); switch (orderBy) { case OrderBy.CommentCount: posts = temp.ThenByDescending(p => p.Comment.Count).Skip(size * (page - 1)).Take(size).ToList(); break; case OrderBy.PostDate: posts = temp.ThenByDescending(p => p.PostDate).Skip(size * (page - 1)).Take(size).ToList(); break; case OrderBy.ViewCount: posts = temp.ThenByDescending(p => p.TotalViewCount).Skip(size * (page - 1)).Take(size).ToList(); break; case OrderBy.VoteCount: posts = temp.ThenByDescending(p => p.VoteUpCount).Skip(size * (page - 1)).Take(size).ToList(); break; default: posts = temp.ThenByDescending(p => p.ModifyDate).Skip(size * (page - 1)).Take(size).ToList(); break; } ViewBag.Total = temp.Count(); ViewBag.Title = s.Title; ViewBag.Desc = s.Description; ViewBag.SubTitle = s.SubTitle; ViewBag.Ads = AdsService.GetByWeightedPrice(AdvertiseType.PostList); return(View(posts.Mapper <IList <PostOutputDto> >())); }
public async Task <ActionResult> Tag(string tag, [Optional] OrderBy?orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")] int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 15) { if (string.IsNullOrWhiteSpace(tag)) { throw new NotFoundException(""); } var where = PostBaseWhere().And(p => p.Status == Status.Published); var queryable = PostService.GetQuery(tag.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).Aggregate(where, (current, s) => current.And(p => Regex.IsMatch(p.Label, s)))); var h24 = DateTime.Today.AddDays(-1); var posts = orderBy switch { OrderBy.Trending => await queryable.OrderByDescending(p => p.PostVisitRecordStats.Where(e => e.Date >= h24).Sum(e => e.Count)).ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig), _ => await queryable.OrderBy($"{nameof(PostDto.IsFixedTop)} desc,{(orderBy ?? OrderBy.ModifyDate).GetDisplay()} desc").ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig) }; var viewModel = await GetIndexPageViewModel(); ViewBag.Tag = tag; viewModel.Posts = posts; viewModel.PageParams = new Pagination(page, size, posts.TotalCount, orderBy); viewModel.SidebarAds = AdsService.GetsByWeightedPrice(2, AdvertiseType.SideBar, Request.Location()); viewModel.ListAdvertisement = AdsService.GetByWeightedPrice(AdvertiseType.ListItem, Request.Location()); foreach (var item in posts.Data) { item.ModifyDate = item.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); } return(View(viewModel)); }
public async Task <IActionResult> Save([FromBodyOrDefault] AdvertisementDto model) { var entity = AdsService[model.Id] ?? new Advertisement(); model.CategoryIds = model.CategoryIds?.Replace("null", ""); model.Regions = Regex.Replace(model.Regions ?? "", @"(\p{P}|\p{Z}|\p{S})+", "|"); if (model.RegionMode == RegionLimitMode.All) { model.Regions = null; } if (model.Types.Contains(AdvertiseType.Banner.ToString("D")) && string.IsNullOrEmpty(model.ImageUrl)) { return(ResultData(null, false, "宣传大图不能为空")); } if (model.Types.Length > 3 && string.IsNullOrEmpty(model.ThumbImgUrl)) { return(ResultData(null, false, "宣传小图不能为空")); } Mapper.Map(model, entity); var b = await AdsService.AddOrUpdateSavedAsync(a => a.Id, entity) > 0; return(ResultData(null, b, b ? "保存成功" : "保存失败")); }
public async Task <ActionResult> Index([FromServices] IFastShareService fastShareService) { var banners = AdsService.GetsByWeightedPrice(8, AdvertiseType.Banner, Request.Location()).OrderByRandom().ToList(); var fastShares = await fastShareService.GetAllFromCacheAsync(s => s.Sort); var postsQuery = PostService.GetQuery(PostBaseWhere().And(p => p.Status == Status.Published)); //准备文章的查询 var posts = await postsQuery.Where(p => !p.IsFixedTop).OrderBy(OrderBy.ModifyDate.GetDisplay() + " desc").ToCachedPagedListAsync <Post, PostDto>(1, 15, MapperConfig); posts.Data.InsertRange(0, postsQuery.Where(p => p.IsFixedTop).OrderByDescending(p => p.ModifyDate).ProjectTo <PostDto>(MapperConfig).Cacheable().ToList()); var viewModel = await GetIndexPageViewModel(); viewModel.Banner = banners; viewModel.Posts = posts; ViewBag.FastShare = fastShares; viewModel.PageParams = new Pagination(1, 15, posts.TotalCount, OrderBy.ModifyDate); viewModel.SidebarAds = AdsService.GetsByWeightedPrice(2, AdvertiseType.SideBar, Request.Location()); viewModel.ListAdvertisement = AdsService.GetByWeightedPrice(AdvertiseType.ListItem, Request.Location()); PostService.SolvePostsCategory(posts.Data); foreach (var item in posts.Data) { item.ModifyDate = item.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); } return(View(viewModel)); }
public IHttpActionResult Index() { try { var ad = new AdsService(); var adverts = ad.DisplayAllAds().ToList(); List <AdvertisementViewModel> advertisements = new List <AdvertisementViewModel>(); foreach (var item in adverts) { advertisements.Add(new AdvertisementViewModel() { Id = item.Id, Title = item.Title, Description = item.Description, Location = item.Location, MinSellingPrice = item.MinSellingPrice, MaxSellingPrice = item.MaxSellingPrice, CreationDate = item.CreationDate, ExpirationDate = item.ExpirationDate }); } if (advertisements != null) { return(Ok(advertisements)); } } catch (Exception ex) { throw new OnlineAdsAppException("The ads cannot be displayed"); } return(InternalServerError()); }
void Start() { if (DataScript.isGameModeEndless == 1) { highScore = PlayerPrefs.GetInt("highScore", highScore); } else { highScore = PlayerPrefs.GetInt("LevelHighScore", highScore); } ads = FindObjectOfType(typeof(AdsService)) as AdsService; highScorePoint.gameObject.SetActive(false); highScoreText.gameObject.SetActive(false); pointCounterText.gameObject.SetActive(false); restartButton.gameObject.SetActive(false); secondChance.gameObject.SetActive(false); advertiseTimer.gameObject.SetActive(false); countDown.gameObject.SetActive(false); skip.gameObject.SetActive(false); skipButton.gameObject.SetActive(false); NextLevelPanel.SetActive(false); audioSource = GetComponent <AudioSource>(); skipPressed = false; }
public async Task <ActionResult> Details(int id, string kw) { var post = await PostService.GetAsync(p => p.Id == id && (p.Status == Status.Published || CurrentUser.IsAdmin)) ?? throw new NotFoundException("文章未找到"); ViewBag.Keyword = post.Keyword + "," + post.Label; var modifyDate = post.ModifyDate; ViewBag.Next = PostService.GetFromCache <DateTime, PostModelBase>(p => p.ModifyDate > modifyDate && (p.Status == Status.Published || CurrentUser.IsAdmin), p => p.ModifyDate); ViewBag.Prev = PostService.GetFromCache <DateTime, PostModelBase>(p => p.ModifyDate < modifyDate && (p.Status == Status.Published || CurrentUser.IsAdmin), p => p.ModifyDate, false); if (!string.IsNullOrEmpty(kw)) { ViewData["keywords"] = post.Content.Contains(kw) ? $"['{kw}']" : SearchEngine.LuceneIndexSearcher.CutKeywords(kw).ToJsonString(); } ViewBag.Ads = AdsService.GetByWeightedPrice(AdvertiseType.InPage, post.CategoryId); var related = PostService.ScoreSearch(1, 11, string.IsNullOrWhiteSpace(post.Keyword + post.Label) ? post.Title : post.Keyword + post.Label); related.RemoveAll(p => p.Id == id); ViewBag.Related = related; if (CurrentUser.IsAdmin) { return(View("Details_Admin", post)); } if (!HttpContext.Request.IsRobot() && string.IsNullOrEmpty(HttpContext.Session.Get <string>("post" + id))) { HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.RecordPostVisit), args: id); HttpContext.Session.Set("post" + id, id.ToString()); } return(View(post)); }
public async Task <ActionResult> Author(string author, [Optional] OrderBy?orderBy, int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 15) { page = Math.Max(1, page); Expression <Func <Post, bool> > where = p => p.Author.Equals(author) || p.Modifier.Equals(author) || p.Email.Equals(author) || p.PostHistoryVersion.Any(v => v.Modifier.Equals(author) || v.ModifierEmail.Equals(author)); where = where.And(p => p.Status == Status.Published).And(PostBaseWhere()); var h24 = DateTime.Today.AddDays(-1); var posts = orderBy switch { OrderBy.Trending => await PostService.GetQuery(where).OrderByDescending(p => p.PostVisitRecordStats.Where(e => e.Date >= h24).Sum(e => e.Count)).ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig), _ => await PostService.GetQuery(where).OrderBy($"{nameof(PostDto.IsFixedTop)} desc,{(orderBy ?? OrderBy.ModifyDate).GetDisplay()} desc").ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig) }; var viewModel = await GetIndexPageViewModel(); ViewBag.Author = author; viewModel.Posts = posts; viewModel.PageParams = new Pagination(page, size, posts.TotalCount, orderBy); viewModel.SidebarAds = AdsService.GetsByWeightedPrice(2, AdvertiseType.SideBar, Request.Location()); viewModel.ListAdvertisement = AdsService.GetByWeightedPrice(AdvertiseType.ListItem, Request.Location()); PostService.SolvePostsCategory(posts.Data); foreach (var item in posts.Data) { item.ModifyDate = item.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); } return(View(viewModel)); }
public async Task <ActionResult> Donate() { ViewBag.Ads = AdsService.GetsByWeightedPrice(2, AdvertiseType.InPage); var text = await System.IO.File.ReadAllTextAsync(Path.Combine(HostEnvironment.WebRootPath, "template", "donate.html")); return(CurrentUser.IsAdmin ? View("Donate_Admin", text) : View(model: text)); }
private void Awake() { LastTrainPos = transform.position; _achievementsService = ServiceLocator.GetService <AchievementsService>(); _audioService = ServiceLocator.GetService <AudioService>(); _levelService = ServiceLocator.GetService <LevelService>(); _adsService = ServiceLocator.GetService <AdsService>(); _skinService = ServiceLocator.GetService <SkinService>(); _gameDataService = ServiceLocator.GetService <GameDataService>(); _uiService = ServiceLocator.GetService <UIService>(); _poolService = ServiceLocator.GetService <PoolService>(); Trains = new List <TrainController>(); spriteRenderer = GetComponent <SpriteRenderer>(); TargetPointList = TargetRail.WayPoints; TargetPoint = TargetPointList[0].localPosition; Trains.Add(this); InputManager.Swipe += InputManagerOnSwipe; _adsService.TrainRevive += ReviveTrain; _uiService.GameRestart += ResetTrain; _skinService.UpdateSkin(spriteRenderer); UpdateTrainPoints(); LockControlls = _uiService.IsFirstTime; IsFirstTime = _uiService.IsFirstTime; }
public async Task <ActionResult> Archieve([Range(2010, 2099)] int yyyy, [Range(1, 12)] int mm, [Range(1, 31)] int dd, [Optional] OrderBy?orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")] int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 15, string mode = nameof(Models.Entity.Post.ModifyDate)) { if (!DateTime.TryParse(yyyy + "-" + mm + "-" + dd, out var date)) { date = DateTime.Today; } var where = PostBaseWhere().And(p => p.Status == Status.Published); where = mode switch { nameof(Models.Entity.Post.PostDate) => where.And(p => p.PostDate.Date == date), _ => where.And(p => p.ModifyDate.Date == date), }; var queryable = PostService.GetQuery(where); var h24 = DateTime.Today.AddDays(-1); var posts = orderBy switch { OrderBy.Trending => await queryable.OrderByDescending(p => p.PostVisitRecordStats.Where(e => e.Date >= h24).Sum(e => e.Count)).ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig), _ => await queryable.OrderBy($"{nameof(PostDto.IsFixedTop)} desc,{(orderBy ?? OrderBy.ModifyDate).GetDisplay()} desc").ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig) }; var viewModel = await GetIndexPageViewModel(); viewModel.Posts = posts; viewModel.PageParams = new Pagination(page, size, posts.TotalCount, orderBy); viewModel.SidebarAds = AdsService.GetsByWeightedPrice(2, AdvertiseType.SideBar, Request.Location()); viewModel.ListAdvertisement = AdsService.GetByWeightedPrice(AdvertiseType.ListItem, Request.Location()); foreach (var item in posts.Data) { item.ModifyDate = item.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); } return(View(viewModel)); }
public async Task <ActionResult> Index(int id, [Optional] OrderBy?orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")] int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 15) { var s = await SeminarService.GetByIdAsync(id) ?? throw new NotFoundException("专题未找到"); var h24 = DateTime.Today.AddDays(-1); var posts = orderBy switch { OrderBy.Trending => await PostService.GetQuery(PostBaseWhere().And(p => p.Seminar.Any(x => x.Id == id) && p.Status == Status.Published)).OrderByDescending(p => p.PostVisitRecordStats.Where(e => e.Date >= h24).Sum(e => e.Count)).ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig), _ => await PostService.GetQuery(PostBaseWhere().And(p => p.Seminar.Any(x => x.Id == id) && p.Status == Status.Published)).OrderBy($"{nameof(Post.IsFixedTop)} desc,{(orderBy ?? OrderBy.ModifyDate).GetDisplay()} desc").ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig) }; ViewBag.Id = s.Id; ViewBag.Title = s.Title; ViewBag.Desc = s.Description; ViewBag.SubTitle = s.SubTitle; ViewBag.Ads = AdsService.GetByWeightedPrice(AdvertiseType.ListItem, Request.Location(), keywords: s.Title); ViewData["page"] = new Pagination(page, size, posts.TotalCount, orderBy); PostService.SolvePostsCategory(posts.Data); foreach (var item in posts.Data) { item.PostDate = item.PostDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); item.ModifyDate = item.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); } return(View(posts)); }
public async Task <ActionResult> Post([Optional] OrderBy?orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")] int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 15) { var viewModel = await GetIndexPageViewModel(); var postsQuery = PostService.GetQuery(PostBaseWhere().And(p => p.Status == Status.Published)); //准备文章的查询 var h24 = DateTime.Today.AddDays(-1); var posts = orderBy switch { OrderBy.Trending => await postsQuery.Where(p => !p.IsFixedTop).OrderByDescending(p => p.PostVisitRecordStats.Where(e => e.Date >= h24).Sum(t => t.Count)).ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig), _ => await postsQuery.Where(p => !p.IsFixedTop).OrderBy((orderBy ?? OrderBy.ModifyDate).GetDisplay() + " desc").ToCachedPagedListAsync <Post, PostDto>(page, size, MapperConfig) }; if (page == 1) { posts.Data.InsertRange(0, postsQuery.Where(p => p.IsFixedTop).OrderByDescending(p => p.ModifyDate).ProjectTo <PostDto>(MapperConfig).ToList()); } viewModel.Posts = posts; viewModel.PageParams = new Pagination(page, size, posts.TotalCount, orderBy); viewModel.SidebarAds = AdsService.GetsByWeightedPrice(2, AdvertiseType.SideBar, Request.Location()); viewModel.ListAdvertisement = AdsService.GetByWeightedPrice(AdvertiseType.ListItem, Request.Location()); foreach (var item in posts.Data) { item.ModifyDate = item.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); } return(View(viewModel)); }
public ActionResult ChangeState(int id) { var ad = AdsService.GetById(id) ?? throw new NotFoundException("广告不存在!"); ad.Status = ad.Status == Status.Available ? Status.Unavailable : Status.Available; return(ResultData(null, AdsService.SaveChanges() > 0, ad.Status == Status.Available ? $"【{ad.Title}】已上架!" : $"【{ad.Title}】已下架!")); }
public async Task <ActionResult> Index([FromServices] IWebHostEnvironment hostEnvironment) { var list = await LinksService.GetQueryFromCacheAsync <bool, LinksDto>(l => l.Status == Status.Available, l => l.Recommend, false); ViewBag.Html = await new FileInfo(Path.Combine(hostEnvironment.WebRootPath, "template", "links.html")).ShareReadWrite().ReadAllTextAsync(Encoding.UTF8); ViewBag.Ads = AdsService.GetByWeightedPrice(AdvertiseType.InPage, Request.Location()); return(CurrentUser.IsAdmin ? View("Index_Admin", list) : View(list)); }
public async Task <ActionResult> SetCategories(int id, [FromBodyOrDefault] string cids) { var entity = await AdsService.GetByIdAsync(id) ?? throw new NotFoundException("广告未找到"); entity.CategoryIds = cids; await AdsService.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult> Index() { var list = await LinksService.GetQueryFromCacheAsync <bool, LinksDto>(l => l.Status == Status.Available, l => l.Recommend, false); ViewBag.Html = await System.IO.File.ReadAllTextAsync(Path.Combine(HostEnvironment.WebRootPath, "template", "links.html")); ViewBag.Ads = AdsService.GetByWeightedPrice(AdvertiseType.InPage); return(CurrentUser.IsAdmin ? View("Index_Admin", list) : View(list)); }
public AdsServiceTest() { IConfiguration configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); _pictureRepository = new PicturesRepository(new InMemoryPersistence <PictureVO>()); _adRepository = new AdsRepository(new InMemoryPersistence <AdVO>()); _calculator = new RuleCalculator(_pictureRepository); _service = new AdsService(_adRepository, _pictureRepository, _calculator, configuration); }
public ActionResult HistoryVersion(int id, int hid) { var post = PostHistoryVersionService.Get(v => v.Id == hid) ?? throw new NotFoundException("文章未找到"); ViewBag.Next = PostHistoryVersionService.Get(p => p.PostId == id && p.ModifyDate > post.ModifyDate, p => p.ModifyDate); ViewBag.Prev = PostHistoryVersionService.Get(p => p.PostId == id && p.ModifyDate < post.ModifyDate, p => p.ModifyDate, false); ViewBag.Ads = AdsService.GetByWeightedPrice(AdvertiseType.InPage, post.CategoryId); return(CurrentUser.IsAdmin ? View("HistoryVersion_Admin", post) : View(post)); }
public async Task browse_async_should_invoke_get_all_async() { var userRepository = new Mock <IUserRepository>(); var mapper = new Mock <IMapper>(); var adService = new AdsService(userRepository.Object, mapper.Object); var users = await adService.BrowseAsync(); userRepository.Verify(x => x.GetAllAsync(), Times.Once); }
public async Task <ActionResult> History(int id, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")] int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 20) { var post = await PostService.GetAsync(p => p.Id == id && (p.Status == Status.Published || CurrentUser.IsAdmin)) ?? throw new NotFoundException("文章未找到"); ViewBag.Primary = post; var list = PostHistoryVersionService.GetPages(page, size, v => v.PostId == id, v => v.ModifyDate, false); ViewBag.Ads = AdsService.GetByWeightedPrice(AdvertiseType.InPage, post.CategoryId); return(View(list)); }
public ActionResult ChangeState(int id) { var ad = AdsService.GetById(id); if (ad != null) { ad.Status = ad.Status == Status.Available ? Status.Unavailable : Status.Available; return ResultData(null, AdsService.SaveChanges() > 0, ad.Status == Status.Available ? $"【{ad.Title}】已上架!" : $"【{ad.Title}】已下架!"); } return ResultData(null, false, "广告不存在"); }
public ActionResult Index(int id, [Optional] OrderBy?orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")] int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")] int size = 15) { var s = SeminarService.GetById(id) ?? throw new NotFoundException("文章未找到"); var posts = PostService.GetQuery <PostDto>(p => p.Seminar.Any(x => x.SeminarId == id) && (p.Status == Status.Pended || CurrentUser.IsAdmin)).OrderBy($"{nameof(Post.IsFixedTop)} desc,{(orderBy ?? OrderBy.ModifyDate).GetDisplay()} desc").ToPagedList(page, size); ViewBag.Title = s.Title; ViewBag.Desc = s.Description; ViewBag.SubTitle = s.SubTitle; ViewBag.Ads = AdsService.GetByWeightedPrice(AdvertiseType.PostList); ViewData["page"] = new Pagination(page, size, posts.TotalCount, orderBy); return(View(posts)); }
public ActionResult Index() { ViewBag.Total = PostService.Count(p => p.Status == Status.Pended || CurrentUser.IsAdmin); var banners = AdsService.GetsByWeightedPrice(8, AdvertiseType.Banner).OrderBy(a => Guid.NewGuid()).ToList(); var fastShares = FastShareService.GetAllFromCache(s => s.Sort).ToList(); ViewBag.FastShare = fastShares; var viewModel = GetIndexPageViewModel(1, 15, OrderBy.ModifyDate, CurrentUser); viewModel.Banner = banners; return(View(viewModel)); }
public async Task<IActionResult> Redirect(int id) { var ad = AdsService.GetById(id) ?? throw new NotFoundException("广告不存在"); if (!HttpContext.Request.IsRobot() && string.IsNullOrEmpty(HttpContext.Session.Get<string>("ads" + id))) { HttpContext.Session.Set("ads" + id, id.ToString()); ad.ViewCount++; await AdsService.SaveChangesAsync(); } return RedirectPermanent(ad.Url); }
public ActionResult GetPageData(int page = 1, [Range(1, int.MaxValue, ErrorMessage = "页大小必须大于0")] int size = 10, string kw = "") { Expression <Func <Advertisement, bool> > where = p => true; if (!string.IsNullOrEmpty(kw)) { where = where.And(p => p.Title.Contains(kw) || p.Description.Contains(kw) || p.Url.Contains(kw)); } var list = AdsService.GetQuery(where).OrderByDescending(p => p.Status == Status.Available).ThenByDescending(a => a.Price).ThenByDescending(a => a.Id).ProjectTo <AdvertisementViewModel>(MapperConfig).NotCacheable().ToPagedList(page, size); return(Ok(list)); }
public ActionResult History(int id, int page = 1, int size = 20) { var post = PostService.Get(p => p.Id == id && (p.Status == Status.Pended || CurrentUser.IsAdmin)).Mapper <PostOutputDto>() ?? throw new NotFoundException("文章未找到"); ViewBag.Primary = post; var list = PostHistoryVersionService.GetPages(page, size, out int total, v => v.PostId == id, v => v.ModifyDate, false).ToList(); ViewBag.Total = total; ViewBag.PageCount = Math.Ceiling(total * 1.0 / size).ToInt32(); ViewBag.Ads = AdsService.GetByWeightedPrice(AdvertiseType.InPage, post.CategoryId); return(View(list)); }
public HomeController(ProjectService projectService, ProjectTypeService projectTypeService, AreaService areaService, PriceService priceService, NewsService newsService, AdsService adsService, ContractorServices contractorServices) { _ProjectService = projectService; _ProjectTypeService = projectTypeService; _AreaService = areaService; _PriceService = priceService; _NewsService = newsService; _AdsService = adsService; _ContractorServices = contractorServices; }