/// <summary> /// 创建 <see cref="ArticleController" /> /// </summary> /// <param name="mqChannel"> /// <see cref="IModel" /> /// </param> /// <param name="coupon"> /// <see cref="CouponProvider" /> /// </param> /// <param name="dbContext"> /// <see cref="KeylolDbContext" /> /// </param> /// <param name="userManager"> /// <see cref="KeylolUserManager" /> /// </param> /// <param name="cachedData"><see cref="CachedDataProvider"/></param> public ArticleController(IModel mqChannel, CouponProvider coupon, KeylolDbContext dbContext, KeylolUserManager userManager, CachedDataProvider cachedData) { _mqChannel = mqChannel; _coupon = coupon; _dbContext = dbContext; _userManager = userManager; _cachedData = cachedData; }
/// <summary> /// 创建 <see cref="LikeController" /> /// </summary> /// <param name="coupon"> /// <see cref="CouponProvider" /> /// </param> /// <param name="dbContext"> /// <see cref="KeylolDbContext" /> /// </param> /// <param name="userManager"> /// <see cref="KeylolUserManager" /> /// </param> /// <param name="cachedData"> /// <see cref="CachedDataProvider"/> /// </param> /// <param name="mqChannel"><see cref="IModel"/></param> public LikeController(CouponProvider coupon, KeylolDbContext dbContext, KeylolUserManager userManager, CachedDataProvider cachedData, IModel mqChannel) { _coupon = coupon; _dbContext = dbContext; _userManager = userManager; _cachedData = cachedData; _mqChannel = mqChannel; }
/// <summary> /// 创建 <see cref="UserController" /> /// </summary> /// <param name="coupon"> /// <see cref="CouponProvider" /> /// </param> /// <param name="owinContextProvider"> /// <see cref="OwinContextProvider" /> /// </param> /// <param name="dbContext"> /// <see cref="KeylolDbContext" /> /// </param> /// <param name="userManager"> /// <see cref="KeylolUserManager" /> /// </param> /// <param name="oneTimeToken"> /// <see cref="OneTimeTokenProvider" /> /// </param> /// <param name="roleManager"><see cref="KeylolRoleManager"/></param> public UserController(CouponProvider coupon, OwinContextProvider owinContextProvider, KeylolDbContext dbContext, KeylolUserManager userManager, OneTimeTokenProvider oneTimeToken, KeylolRoleManager roleManager) { _coupon = coupon; _owinContext = owinContextProvider.Current; _dbContext = dbContext; _userManager = userManager; _oneTimeToken = oneTimeToken; _roleManager = roleManager; }
/// <summary> /// 创建 <see cref="CurrentUser"/> /// </summary> /// <param name="user">用户对象</param> /// <param name="userManager"><see cref="KeylolUserManager"/></param> /// <param name="dbContext"><see cref="KeylolDbContext"/></param> /// <param name="coupon"><see cref="CouponProvider"/></param> /// <param name="cachedData"><see cref="CachedDataProvider"/></param> /// <returns><see cref="CurrentUser"/></returns> public static async Task <CurrentUser> CreateAsync(KeylolUser user, KeylolUserManager userManager, KeylolDbContext dbContext, CouponProvider coupon, CachedDataProvider cachedData) { // 每日访问奖励 if (DateTime.Now.Date > user.LastDailyRewardTime.Date) { user.LastDailyRewardTime = DateTime.Now; user.FreeLike = 5; // 免费认可重置 try { await dbContext.SaveChangesAsync(); await coupon.UpdateAsync(user, CouponEvent.每日访问); } catch (DbUpdateConcurrencyException) { } } // Steam 游戏记录更新 SteamCrawlerProvider.UpdateUserSteamGameRecords(user.Id); // Steam 好友列表更新 SteamCrawlerProvider.UpdateUserSteamFrineds(user.Id); return(new CurrentUser { Id = user.Id, UserName = user.UserName, IdCode = user.IdCode, Roles = (await userManager.GetRolesAsync(user.Id)).ToList(), AvatarImage = user.AvatarImage, MessageCount = await cachedData.Messages.GetUserUnreadMessageCountAsync(user.Id), Coupon = user.Coupon, PreferredPointName = user.PreferredPointName, OpenInNewWindow = user.OpenInNewWindow }); }
/// <summary> /// 创建 <see cref="StorePage"/> /// </summary> /// <param name="currentUserId">当前登录用户 ID</param> /// <param name="dbContext"><see cref="KeylolDbContext"/></param> /// <param name="cachedData"><see cref="CachedDataProvider"/></param> /// <param name="userManager"><see cref="KeylolUserManager"/></param> /// <param name="coupon"></param> /// <returns><see cref="StorePage"/></returns> public static async Task <StorePage> CreateAsync(string currentUserId, [Injected] KeylolDbContext dbContext, [Injected] CachedDataProvider cachedData, [Injected] KeylolUserManager userManager, [Injected] CouponProvider coupon) { return(new StorePage { Gifts = await CouponGiftList.CreateAsync(currentUserId, dbContext, cachedData, userManager, coupon) }); }
/// <summary> /// 获取文券商店页面 /// </summary> /// <param name="dbContext"><see cref="KeylolDbContext"/></param> /// <param name="cachedData"><see cref="CachedDataProvider"/></param> /// <param name="userManager"></param> /// <param name="coupon"></param> /// <returns><see cref="StorePage"/></returns> public static async Task <StorePage> Get([Injected] KeylolDbContext dbContext, [Injected] CachedDataProvider cachedData, [Injected] KeylolUserManager userManager, [Injected] CouponProvider coupon) { return(await CreateAsync(StateTreeHelper.GetCurrentUserId(), dbContext, cachedData, userManager, coupon)); }
/// <summary> /// 获取新的完整状态树 /// </summary> /// <param name="state">当前 UI 状态</param> /// <param name="userManager"><see cref="KeylolUserManager"/></param> /// <param name="dbContext"><see cref="KeylolDbContext"/></param> /// <param name="coupon"><see cref="CouponProvider"/></param> /// <param name="cachedData"><see cref="CachedDataProvider"/></param> /// <param name="pointIdCode">据点识别码</param> /// <param name="authorIdCode">作者识别码</param> /// <param name="userIdCode">用户识别码</param> /// <param name="sidForAuthor">文章在作者名下的序号</param> /// <param name="keyword">搜索关键字</param> /// <returns>完整状态树</returns> public static async Task <Root> Locate(string state, [Injected] KeylolUserManager userManager, [Injected] KeylolDbContext dbContext, [Injected] CouponProvider coupon, [Injected] CachedDataProvider cachedData, string pointIdCode = null, string authorIdCode = null, string userIdCode = null, int sidForAuthor = 0, string keyword = null) { var root = new Root(); var currentUserId = StateTreeHelper.GetCurrentUserId(); var isOperator = StateTreeHelper.GetCurrentUser().IsInRole(KeylolRoles.Operator); if (await StateTreeHelper.CanAccessAsync <Root>(nameof(CurrentUser))) { var user = await userManager.FindByIdAsync(currentUserId); root.CurrentUser = await CurrentUser.CreateAsync(user, userManager, dbContext, coupon, cachedData); } switch (state) { case "entrance": root.Entrance = await EntranceLevel.CreateAsync(currentUserId, States.Entrance.EntrancePage.Auto, dbContext, cachedData); break; case "entrance.discovery": root.Entrance = await EntranceLevel.CreateAsync(currentUserId, States.Entrance.EntrancePage.Discovery, dbContext, cachedData); break; case "entrance.points": root.Entrance = await EntranceLevel.CreateAsync(currentUserId, States.Entrance.EntrancePage.Points, dbContext, cachedData); break; case "entrance.timeline": root.Entrance = await EntranceLevel.CreateAsync(currentUserId, States.Entrance.EntrancePage.Timeline, dbContext, cachedData); break; case "aggregation.point": root.Aggregation = new AggregationLevel { Point = await PointLevel.CreateAsync(currentUserId, pointIdCode, States.Aggregation.Point.EntrancePage.Auto, dbContext, cachedData) }; break; case "aggregation.point.frontpage": root.Aggregation = new AggregationLevel { Point = await PointLevel.CreateAsync(currentUserId, pointIdCode, States.Aggregation.Point.EntrancePage.Frontpage, dbContext, cachedData) }; break; case "aggregation.point.intel": root.Aggregation = new AggregationLevel { Point = await PointLevel.CreateAsync(currentUserId, pointIdCode, States.Aggregation.Point.EntrancePage.Intel, dbContext, cachedData) }; break; case "aggregation.point.product": root.Aggregation = new AggregationLevel { Point = await PointLevel.CreateAsync(currentUserId, pointIdCode, States.Aggregation.Point.EntrancePage.Product, dbContext, cachedData) }; break; case "aggregation.point.timeline": root.Aggregation = new AggregationLevel { Point = await PointLevel.CreateAsync(currentUserId, pointIdCode, States.Aggregation.Point.EntrancePage.Timeline, dbContext, cachedData) }; break; case "aggregation.point.edit.info": root.Aggregation = new AggregationLevel { Point = await PointLevel.CreateAsync(currentUserId, pointIdCode, States.Aggregation.Point.EntrancePage.EditInfo, dbContext, cachedData) }; break; case "aggregation.point.edit.style": root.Aggregation = new AggregationLevel { Point = await PointLevel.CreateAsync(currentUserId, pointIdCode, States.Aggregation.Point.EntrancePage.EditStyle, dbContext, cachedData) }; break; case "aggregation.user": root.Aggregation = new AggregationLevel { User = await UserLevel.CreateAsync(currentUserId, userIdCode, EntrancePage.Auto, dbContext, cachedData, userManager) }; break; case "aggregation.user.dossier": root.Aggregation = new AggregationLevel { User = await UserLevel.CreateAsync(currentUserId, userIdCode, EntrancePage.Dossier, dbContext, cachedData, userManager) }; break; case "aggregation.user.people": root.Aggregation = new AggregationLevel { User = await UserLevel.CreateAsync(currentUserId, userIdCode, EntrancePage.People, dbContext, cachedData, userManager) }; break; case "aggregation.user.timeline": root.Aggregation = new AggregationLevel { User = await UserLevel.CreateAsync(currentUserId, userIdCode, EntrancePage.Timeline, dbContext, cachedData, userManager) }; break; case "aggregation.user.edit": root.Aggregation = new AggregationLevel { User = await UserLevel.CreateAsync(currentUserId, userIdCode, EntrancePage.Edit, dbContext, cachedData, userManager) }; break; case "content.article": root.Content = new ContentLevel { Article = await States.Content.Article.ArticlePage.CreateAsync(authorIdCode, sidForAuthor, currentUserId, isOperator, dbContext, cachedData, userManager) }; break; case "content.activity": root.Content = new ContentLevel { Activity = await ActivityPage.CreateAsync(authorIdCode, sidForAuthor, currentUserId, isOperator, dbContext, cachedData, userManager) }; break; case "post-office.unread": if (await StateTreeHelper.CanAccessAsync <Root>(nameof(PostOffice))) { root.PostOffice = new PostOfficeLevel { Unread = await UnreadPage.CreateAsync(currentUserId, dbContext, cachedData) } } ; break; case "post-office.social-activity.comment": if (await StateTreeHelper.CanAccessAsync <Root>(nameof(PostOffice))) { root.PostOffice = new PostOfficeLevel { SocialActivity = new SocialActivityLevel { Comment = await CommentPage.CreateAsync(currentUserId, dbContext, cachedData) } } } ; break; case "post-office.social-activity.like": if (await StateTreeHelper.CanAccessAsync <Root>(nameof(PostOffice))) { root.PostOffice = new PostOfficeLevel { SocialActivity = new SocialActivityLevel { Like = await LikePage.CreateAsync(currentUserId, dbContext, cachedData) } } } ; break; case "post-office.social-activity.subscriber": if (await StateTreeHelper.CanAccessAsync <Root>(nameof(PostOffice))) { root.PostOffice = new PostOfficeLevel { SocialActivity = new SocialActivityLevel { Subscriber = await SubscriberPage.CreateAsync(currentUserId, dbContext, cachedData) } } } ; break; case "post-office.missive": if (await StateTreeHelper.CanAccessAsync <Root>(nameof(PostOffice))) { root.PostOffice = new PostOfficeLevel { Missive = await MissivePage.CreateAsync(currentUserId, dbContext, cachedData) } } ; break; case "coupon.detail": if (await StateTreeHelper.CanAccessAsync <Root>(nameof(Coupon))) { root.Coupon = new CouponLevel { Detail = await DetailPage.CreateAsync(currentUserId, dbContext, userManager) } } ; break; case "coupon.store": if (await StateTreeHelper.CanAccessAsync <Root>(nameof(Coupon))) { root.Coupon = new CouponLevel { Store = await StorePage.CreateAsync(currentUserId, dbContext, cachedData, userManager, coupon) } } ; break; case "coupon.ranking": if (await StateTreeHelper.CanAccessAsync <Root>(nameof(Coupon))) { root.Coupon = new CouponLevel { Ranking = await RankingPage.CreateAsync(currentUserId, dbContext, cachedData) } } ; break; case "search.point": root.Search = new SearchLevel { Point = await PointPage.CreateAsync(currentUserId, keyword, dbContext, cachedData) }; break; case "search.article": root.Search = new SearchLevel { Article = await ArticlePage.CreateAsync(keyword, dbContext, cachedData) }; break; case "search.user": root.Search = new SearchLevel { User = await UserPage.CreateAsync(currentUserId, keyword, dbContext, cachedData) }; break; default: throw new NotSupportedException("Not supported state."); } return(root); }
/// <summary> /// 创建 <see cref="SteamCnCreditProcessor"/> /// </summary> /// <param name="dbContext"><see cref="KeylolDbContext"/></param> /// <param name="userManager"><see cref="KeylolUserManager"/></param> /// <param name="coupon"><see cref="CouponProvider"/></param> public SteamCnCreditProcessor(KeylolDbContext dbContext, KeylolUserManager userManager, CouponProvider coupon) { _dbContext = dbContext; _userManager = userManager; _coupon = coupon; }
/// <summary> /// 创建<see cref="CouponGiftOrderController"/> /// </summary> /// <param name="dbContext"><see cref="KeylolDbContext"/></param> /// <param name="userManager"><see cref="KeylolUserManager"/></param> /// <param name="coupon"><see cref="CouponProvider"/></param> public CouponGiftOrderController(KeylolDbContext dbContext, KeylolUserManager userManager, CouponProvider coupon) { _dbContext = dbContext; _userManager = userManager; _coupon = coupon; }
/// <summary> /// 创建 <see cref="CouponGiftList"/> /// </summary> /// <param name="currentUserId">当前用户Id</param> /// <param name="dbContext"><see cref="KeylolDbContext"/></param> /// <param name="cachedData"><see cref="CachedDataProvider"/></param> /// <param name="userManager"><see cref="KeylolUserManager"/></param> /// <param name="coupon"><see cref="CouponProvider"/></param> public static async Task <CouponGiftList> CreateAsync(string currentUserId, KeylolDbContext dbContext, CachedDataProvider cachedData, KeylolUserManager userManager, CouponProvider coupon) { var queryResult = await dbContext.CouponGifts.Where(g => DateTime.Now < g.EndTime) .OrderByDescending(g => g.CreateTime) .ToListAsync(); var currentUser = await userManager.FindByIdAsync(currentUserId); var result = new CouponGiftList(queryResult.Count); foreach (var g in queryResult) { GiftProcessor processor; switch (g.Type) { case CouponGiftType.Custom: processor = new CustomProcessor(); break; case CouponGiftType.SteamCnCredit: processor = new SteamCnCreditProcessor(dbContext, userManager, coupon); break; case CouponGiftType.SteamGiftCard: processor = new SteamGiftCardProcessor(dbContext, coupon); break; default: throw new ArgumentOutOfRangeException(); } var stateTreeGift = new CouponGift { Id = g.Id, Name = g.Name, Descriptions = Helpers.SafeDeserialize <List <string> >(g.Descriptions), Price = g.Price, ThumbnailImage = g.ThumbnailImage, Type = g.Type }; processor.Initialize(currentUser, g); await processor.FillPropertiesAsync(stateTreeGift); result.Add(stateTreeGift); } return(result); }
/// <summary> /// 创建 <see cref="SteamGiftCardProcessor"/> /// </summary> /// <param name="dbContext"><see cref="KeylolDbContext"/></param> /// <param name="coupon"><see cref="CouponProvider"/></param> public SteamGiftCardProcessor(KeylolDbContext dbContext, CouponProvider coupon) { _dbContext = dbContext; _coupon = coupon; }
/// <summary> /// 创建 <see cref="CouponLogController" /> /// </summary> /// <param name="coupon"> /// <see cref="CouponProvider" /> /// </param> /// <param name="userManager"> /// <see cref="KeylolUserManager" /> /// </param> public CouponLogController(CouponProvider coupon, KeylolUserManager userManager) { _coupon = coupon; _userManager = userManager; }