Esempio n. 1
0
        /// <summary>
        /// 商品兑换
        /// </summary>
        public override async Task RedeemAsync()
        {
            if (await GetCreditAsync() < Gift.Value)
            {
                throw new Exception(Errors.NotEnoughCredit);
            }

            if (await _userManager.GetSteamCnUidAsync(User.Id) == null)
            {
                throw new Exception(Errors.SteamCnAccountNotBound);
            }

            throw new NotImplementedException();

/*
 *          _dbContext.CouponGiftOrders.Add(new Models.CouponGiftOrder
 *          {
 *              UserId = User.Id,
 *              GiftId = Gift.Id,
 *              RedeemPrice = Gift.Price,
 *              Finished = true
 *          });
 *          await _dbContext.SaveChangesAsync();
 *          await _coupon.UpdateAsync(User, CouponEvent.兑换商品, -Gift.Price, new { CouponGiftId = Gift.Id });
 */
        }
Esempio n. 2
0
        /// <summary>
        /// 创建 <see cref="UserBasicInfo"/>
        /// </summary>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="user">用户对象</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <param name="userManager"><see cref="KeylolUserManager"/></param>
        /// <returns><see cref="UserBasicInfo"/></returns>
        public static async Task <UserBasicInfo> CreateAsync(string currentUserId, KeylolUser user,
                                                             KeylolDbContext dbContext, CachedDataProvider cachedData, KeylolUserManager userManager)
        {
            var basicInfo = new UserBasicInfo
            {
                Id           = user.Id,
                IdCode       = user.IdCode,
                HeaderImage  = user.HeaderImage,
                AvatarImage  = user.AvatarImage,
                UserName     = user.UserName,
                GamerTag     = user.GamerTag,
                RegisterTime = user.RegisterTime,
                IsFriend     = string.IsNullOrWhiteSpace(currentUserId)
                    ? (bool?)null
                    : await cachedData.Users.IsFriendAsync(currentUserId, user.Id),
                Subscribed = string.IsNullOrWhiteSpace(currentUserId)
                    ? (bool?)null
                    : await cachedData.Subscriptions.IsSubscribedAsync(currentUserId, user.Id,
                                                                       SubscriptionTargetType.User),
                FriendCount         = await cachedData.Subscriptions.GetFriendCountAsync(user.Id),
                SubscribedUserCount = await cachedData.Subscriptions.GetSubscribedUserCountAsync(user.Id),
                SubscriberCount     =
                    await cachedData.Subscriptions.GetSubscriberCountAsync(user.Id, SubscriptionTargetType.User),
                ThemeColor      = user.ThemeColor,
                LightThemeColor = user.LightThemeColor,
                SteamId         = await userManager.GetSteamIdAsync(user.Id)
            };

            if (!string.IsNullOrWhiteSpace(basicInfo.SteamId))
            {
                basicInfo.SteamProfileName = user.SteamProfileName;
            }
            int steamCnUid;

            if (int.TryParse(await userManager.GetSteamCnUidAsync(user.Id), out steamCnUid))
            {
                basicInfo.SteamCnUid      = steamCnUid;
                basicInfo.SteamCnUserName = user.SteamCnUserName;
            }
            return(basicInfo);
        }