Exemplo n.º 1
0
        public async Task <ContestAdded> ExecuteAsync(
            ContestAdd contestAdd)
        {
            var contest =
                _mapper.Map(contestAdd, new Contest());

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

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

            contest.Status    = ContestStatus.Ready;
            contest.StartDate = null;
            contest.EndDate   = null;

            contest =
                await _contestRepository.AddAsync(
                    contest);

            var contestAdded =
                _mapper.Map(contest, new ContestAdded());

            return(contestAdded);
        }
Exemplo n.º 2
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);
        }