Ejemplo n.º 1
0
        public async Task <ContestFetched> ExecuteAsync(
            ContestFetch contestFetch)
        {
            var contest =
                await _contestRepository.FetchByIdAsync(
                    contestFetch.Id);

            if (contest == null)
            {
                throw new NullReferenceException($"Contest {contestFetch.Id} not found");
            }

            var contestFetched =
                _mapper.Map(contest, new ContestFetched());

            var contestLearners =
                await _contestLearnerRepository.FetchListAsync(
                    contestFetch.Id);

            contestLearners =
                contestLearners.Where(
                    x => !string.IsNullOrWhiteSpace(x.DisplayName));

            _mapper.Map(contestLearners, contestFetched.Learners);

            return(contestFetched);
        }
        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);
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <ContestLearnerListed> > ExecuteAsync(
            ContestLearnerList contestLearnerList)
        {
            var contestLearners =
                await _contestLearnerRepository.FetchListAsync(
                    contestLearnerList.ContestId);

            contestLearners =
                contestLearners.Where(
                    x => !string.IsNullOrWhiteSpace(x.DisplayName));

            var contestLearnerListed =
                contestLearners.Select(
                    x => _mapper.Map(x, new ContestLearnerListed()));

            return(contestLearnerListed);
        }
Ejemplo n.º 4
0
        public async Task <ContestCopied> ExecuteAsync(
            ContestCopy contestCopy)
        {
            var contest =
                await _contestRepository.FetchByIdAsync(
                    contestCopy.Id);

            contest.Id        = Guid.NewGuid();
            contest.Name      = contestCopy.Name;
            contest.Status    = ContestStatus.InProgress;
            contest.StartDate = null;
            contest.EndDate   = null;
            contest.CreatedOn = DateTime.UtcNow;

            contest =
                await _contestRepository.AddAsync(
                    contest);

            var contestLearners =
                await _contestLearnerRepository.FetchListAsync(
                    contestCopy.Id);

            foreach (var contestLearner in contestLearners)
            {
                contestLearner.Id        = Guid.NewGuid();
                contestLearner.ContestId = contest.Id;

                await _contestLearnerRepository.AddAsync(
                    contest.Id,
                    contestLearner);
            }

            var contestCopied =
                _mapper.Map(contest, new ContestCopied());

            return(contestCopied);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public async Task <ContestLearnerListAdded> ExecuteAsync(
            ContestLearnerListAdd contestLearnerListAdd)
        {
            var contestLearners =
                await _contestLearnerRepository.FetchListAsync(
                    contestLearnerListAdd.ContestId);

            var contestLearnerListAdded =
                new ContestLearnerListAdded
            {
                ContestId = contestLearnerListAdd.ContestId
            };

            var separators =
                new[] { Environment.NewLine, ",", ";", "|" };

            var userNames = contestLearnerListAdd.UserNames
                            .Split(separators, StringSplitOptions.RemoveEmptyEntries);

            foreach (var userName in userNames)
            {
                if (contestLearners.All(x => x.UserName != userName))
                {
                    var contestLearnerAdd =
                        new ContestLearnerAdd
                    {
                        ContestId = contestLearnerListAdd.ContestId,
                        UserName  = userName
                    };

                    await _eventPublisher.PublishAsync("contestlearner.add", contestLearnerAdd);
                }
            }

            return(contestLearnerListAdded);
        }