예제 #1
0
        public void UpdateWithDailyReward(
            IEnumerable <DailyReward> dailyRewardList, IEnumerable <QuizzOverviewModel> qoList)
        {
            var qtSpecialList = HelperUtil.GetIntArrayFromString(_currentUser.DailySpecialPointsQuizzStrList);
            var qtOwnerList   = HelperUtil.GetIntArrayFromString(_currentUser.DailyNormalPointsQuizzSelfStrList);
            var qtOthersList  = HelperUtil.GetIntArrayFromString(_currentUser.DailyNormalPointsQuizzOthersStrList);

            foreach (var item in qoList)
            {
                DailyRewardModel model = null;
                var reward             = dailyRewardList.Where(dr => dr.QuizzId == item.Id)
                                         .FirstOrDefault();

                if (reward != null)
                {
                    model = GetSpecialDailyRewardModel(qtSpecialList, reward, qtOwnerList, qtOthersList, item);
                }
                else
                {
                    model = GetNormalDailRewardModel(qtOwnerList, qtOthersList, item);
                }

                item.DailyReward = model;
            }
        }
예제 #2
0
        private void AddDailyPoints(QuizzPointsEnum type, User user, int points)
        {
            int idx = (int)type;

            int[] intArr = HelperUtil.GetIntArrayFromString(user.DailyPointsAllStrList, MaxDailyQuizzTypeCount);
            intArr[idx] += points;

            user.DailyPointsAllStrList = _currentUser.DailyPointsAllStrList = HelperUtil.GetStrFromIntArray(intArr);
        }
예제 #3
0
 public void GetUserPontsIntArray(UserPointsBase userPointsBase)
 {
     userPointsBase.TotalDailyRewardItems               = QuizzPointsService.MaxDailySpecialQuizzTake;
     userPointsBase.DailyNormalPointsQuizzSelfIntList   = HelperUtil.GetIntArrayFromString(userPointsBase.DailyNormalPointsQuizzSelfStrList);
     userPointsBase.DailyNormalPointsQuizzOthersIntList = HelperUtil.GetIntArrayFromString(userPointsBase.DailyNormalPointsQuizzOthersStrList);
     userPointsBase.DailySpecialPointsQuizzIntList      = HelperUtil.GetIntArrayFromString(userPointsBase.DailySpecialPointsQuizzStrList);
     userPointsBase.DailyPointsAllIntList               = HelperUtil.GetIntArrayFromString(userPointsBase.DailyPointsAllStrList, QuizzPointsService.MaxDailyQuizzTypeCount);
     userPointsBase.BadgeIntList = HelperUtil.GetIntArrayFromString(userPointsBase.BadgeStrList, BadgeService.MaxBadgeTypeCount);
 }
예제 #4
0
        public void SetBadge(BadgeEnum badgeEnum, bool callSaveChanges = true)
        {
            var badgeIntArr = HelperUtil.GetIntArrayFromString(_currentUser.BadgeStrList, MaxBadgeTypeCount);
            int idx         = (int)badgeEnum;

            if (badgeIntArr[idx] == 0)
            {
                badgeIntArr[idx] = 1;
                var user = _uow.Users.GetById(_currentUser.Id);
                user.BadgeStrList = _currentUser.BadgeStrList = HelperUtil.GetStrFromIntArray(badgeIntArr);

                if (callSaveChanges)
                {
                    _uow.SaveChanges();
                }
            }
        }
예제 #5
0
        private void CheckAddSpecialDailyReward(TestLogModel testLog, DailyReward reward, bool callSaveChanges)
        {
            var  rewardIdList = HelperUtil.GetIntArrayFromString(_currentUser.DailySpecialPointsQuizzStrList);
            User user         = null;

            bool qtRewardListHasId = rewardIdList.Contains(reward.Id);

            if (qtRewardListHasId == false)
            {
                if (rewardIdList.Length < QuizzPointsService.MaxDailySpecialQuizzTake)
                {
                    var points = ComputRewardPonts(testLog.Score, testLog.Total);

                    if (points != 0)
                    {
                        user = _svcContainer.QuizzPointsSvc.AddCurrentUserPoints(QuizzPointsEnum.DailySpecialQuizz, callSaveChanges);
                    }
                    else
                    {
                        user = _uow.Users.GetById(_currentUser.Id);
                    }

                    user.DailySpecialPointsQuizzStrList = _currentUser.DailySpecialPointsQuizzStrList = user.DailySpecialPointsQuizzStrList + reward.Id.ToString() + ",";
                    _uow.Users.Update(user);
                    _svcContainer.UserSvc.UpdateCurrentUserInSession();

                    if (callSaveChanges)
                    {
                        _uow.SaveChanges();
                    }
                }
                else
                {
                    CheckAddNormalDailyReward(testLog, callSaveChanges);
                }
            }
        }
예제 #6
0
        public List <QuizzOverviewModel> GetAvailableDailyRewardQuizzes()
        {
            try
            {
                var qtSpecialList = HelperUtil.GetIntArrayFromString(_currentUser.DailySpecialPointsQuizzStrList);
                List <QuizzOverviewModel> list = new List <QuizzOverviewModel>();
                if (qtSpecialList.Length < QuizzPointsService.MaxDailySpecialQuizzTake)
                {
                    var drList = _svcContainer.DailyRewardSvc.GetDailyRewards();
                    var drIds  = drList.Select(dr => dr.QuizzId)
                                 .ToArray();

                    list = _uow.Quizzes.GetAll()
                           .Where(q => drIds.Contains(q.Id))
                           .ProjectTo <QuizzOverviewModel>()
                           .ToList();

                    UpdateWithDailyReward(drList, list);

                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        if (list[i].DailyReward.IsTaken)
                        {
                            list.RemoveAt(i);
                        }
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(new List <QuizzOverviewModel>());
            }
        }