Ejemplo n.º 1
0
 /// <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)
     });
 }
Ejemplo n.º 2
0
        /// <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);
        }