Пример #1
0
        public async Task <ContestStarted> ExecuteAsync(
            ContestStart contestStart)
        {
            var contest =
                await _contestRepository.FetchByIdAsync(
                    contestStart.Id);

            contest.Status = ContestStatus.InProgress;

            if (!contest.StartDate.HasValue)
            {
                contest.StartDate = DateTime.UtcNow;
            }

            contest =
                await _contestRepository.UpdateByIdAsync(
                    contest.Id,
                    contest);

            var contestStarted =
                _mapper.Map(contest, new ContestStarted());

            await _eventPublisher.PublishAsync("contest.started", contestStarted);

            return(contestStarted);
        }
        public async Task <ContestNumberOfLearnersUpdated> ExecuteAsync(
            ContestNumberOfLearnersUpdate contestNumberOfLearnersUpdate)
        {
            var contest =
                await _contestRepository.FetchByIdAsync(
                    contestNumberOfLearnersUpdate.ContestId);

            var contestLearners =
                await _contestLearnerRepository.FetchListAsync(
                    contestNumberOfLearnersUpdate.ContestId);

            contest.NumberOfLearners =
                contestLearners.Count();

            await _contestRepository.UpdateByIdAsync(
                contestNumberOfLearnersUpdate.ContestId,
                contest);

            var contestNumberOfLearnersUpdated =
                new ContestNumberOfLearnersUpdated
            {
                NumberOfLearners = contestLearners.Count()
            };

            return(contestNumberOfLearnersUpdated);
        }
Пример #3
0
        public async Task <ContestUpdated> ExecuteAsync(
            ContestUpdate contestUpdate)
        {
            var contest =
                await _contestRepository.FetchByIdAsync(
                    contestUpdate.Id);

            _mapper.Map(contestUpdate, contest);

            if (!string.IsNullOrWhiteSpace(contestUpdate.Prizes))
            {
                contest.HasPrizes = true;
            }

            if (contest.Type == ContestType.Leaderboard)
            {
                contest.TargetValue = null;
            }

            if (contest.Status == ContestStatus.InProgress &&
                contest.StartDate == null)
            {
                contest.StartDate = DateTime.UtcNow;
            }

            if (contest.Status == ContestStatus.Ended &&
                contest.EndDate == null)
            {
                contest.EndDate = DateTime.UtcNow;
            }

            contest =
                await _contestRepository.UpdateByIdAsync(
                    contestUpdate.Id,
                    contest);

            var contestUpdated =
                _mapper.Map(contest, new ContestUpdated());

            await _eventPublisher.PublishAsync("contest.updated", contestUpdated);

            return(contestUpdated);
        }
Пример #4
0
        public async Task <ContestProgressUpdated> ExecuteAsync(
            ContestProgressUpdate contestUpdate)
        {
            var contest =
                await _contestRepository.FetchByIdAsync(
                    contestUpdate.Id);

            if (contest.IsStatus(ContestStatus.InProgress))
            {
                var contestLearners =
                    await _contestLearnerRepository.FetchListAsync(
                        contest.Id);

                foreach (var contestLearner in contestLearners)
                {
                    var contestLearnerProgressUpdate =
                        _mapper.Map(contestLearner, new ContestLearnerProgressUpdate());

                    await _eventPublisher.PublishAsync("contestlearnerprogress.update", contestLearnerProgressUpdate);
                }

                contest.LastProgressUpdateOn =
                    DateTime.UtcNow;
                contest.NextProgressUpdateOn =
                    contest.LastProgressUpdateOn.Value.AddMinutes(contest.ProgressUpdateInterval);

                contest =
                    await _contestRepository.UpdateByIdAsync(
                        contestUpdate.Id,
                        contest);
            }

            var contestProgressUpdated =
                _mapper.Map(contest, new ContestProgressUpdated());

            return(contestProgressUpdated);
        }
Пример #5
0
        public async Task <ContestEnded> ExecuteAsync(
            ContestEnd contestEnd)
        {
            var contest =
                await _contestRepository.FetchByIdAsync(
                    contestEnd.Id);

            contest.Status = ContestStatus.Ended;

            if (!contest.EndDate.HasValue)
            {
                contest.EndDate = DateTime.UtcNow;
            }

            contest =
                await _contestRepository.UpdateByIdAsync(
                    contest.Id,
                    contest);

            var contestEnded =
                _mapper.Map(contest, new ContestEnded());

            return(contestEnded);
        }