コード例 #1
0
        public ActionResult <object> GetAward(string id)
        {
            var award      = _awardDefinitionService.Get(id);
            var conditions = _awardDefinitionService.GetConditions(award.AwardDefinitionID);
            var allEvents  = _eventDefinitionService.GetAll();
            var container  = new { Award = award, Conditions = conditions, AllEvents = allEvents };

            return(container);
        }
コード例 #2
0
        public ViewResult Award(string id)
        {
            var award = _awardDefinitionService.Get(id);

            if (award == null)
            {
                return(this.NotFound("NotFound", null));
            }
            var selectList = new SelectList(_eventDefinitionService.GetAll(), "EventDefinitionID", "EventDefinitionID");

            ViewBag.EventList  = selectList;
            ViewBag.Conditions = _awardDefinitionService.GetConditions(id);
            return(View(award));
        }
コード例 #3
0
        public void ProcessOneCalculation()
        {
            var nextItem = _awardCalcRepository.Dequeue();

            if (String.IsNullOrEmpty(nextItem.Key))
            {
                return;
            }
            var eventDefinition = _eventDefinitionService.GetEventDefinition(nextItem.Key);
            var user            = _userRepository.GetUser(nextItem.Value);

            if (eventDefinition == null)
            {
                _errorLog.Log(new Exception(String.Format("Event calculation attempt on nonexistent event \"{0}\"", nextItem.Key)), ErrorSeverity.Warning);
                return;
            }
            if (user == null)
            {
                _errorLog.Log(new Exception(String.Format("Event calculation attempt on nonexistent user {0}", nextItem.Value)), ErrorSeverity.Warning);
                return;
            }
            var associatedAwards = _awardDefinitionService.GetByEventDefinitionID(eventDefinition.EventDefinitionID);

            foreach (var award in associatedAwards)
            {
                if (award.IsSingleTimeAward)
                {
                    var isAwarded = _userAwardService.IsAwarded(user, award);
                    if (isAwarded)
                    {
                        continue;
                    }
                }
                var conditions    = _awardDefinitionService.GetConditions(award.AwardDefinitionID);
                var conditionsMet = 0;
                foreach (var condition in conditions)
                {
                    var eventCount = _pointLedgerRepository.GetEntryCount(user.UserID, condition.EventDefinitionID);
                    if (eventCount >= condition.EventCount)
                    {
                        conditionsMet++;
                    }
                }
                if (conditions.Count != 0 && conditionsMet == conditions.Count)
                {
                    _userAwardService.IssueAward(user, award);
                }
            }
        }
コード例 #4
0
        public async Task ProcessCalculation(string eventDefinitionID, int userID)
        {
            var eventDefinition = await _eventDefinitionService.GetEventDefinition(eventDefinitionID);

            var user = await _userRepository.GetUser(userID);

            if (eventDefinition == null)
            {
                _errorLog.Log(new Exception($"Event calculation attempt on nonexistent event \"{eventDefinitionID}\""), ErrorSeverity.Warning);
                return;
            }
            if (user == null)
            {
                _errorLog.Log(new Exception($"Event calculation attempt on nonexistent user {userID}"), ErrorSeverity.Warning);
                return;
            }
            var associatedAwards = await _awardDefinitionService.GetByEventDefinitionID(eventDefinition.EventDefinitionID);

            foreach (var award in associatedAwards)
            {
                if (award.IsSingleTimeAward)
                {
                    var isAwarded = await _userAwardService.IsAwarded(user, award);

                    if (isAwarded)
                    {
                        continue;
                    }
                }
                var conditions = await _awardDefinitionService.GetConditions(award.AwardDefinitionID);

                var conditionsMet = 0;
                foreach (var condition in conditions)
                {
                    var eventCount = await _pointLedgerRepository.GetEntryCount(user.UserID, condition.EventDefinitionID);

                    if (eventCount >= condition.EventCount)
                    {
                        conditionsMet++;
                    }
                }
                if (conditions.Count != 0 && conditionsMet == conditions.Count)
                {
                    await _userAwardService.IssueAward(user, award);
                }
            }
        }