Esempio n. 1
0
        public async Task <CreateContestResponse> CreateAsync(CreateContestRequest contest)
        {
            var exists = await _contestRepository.FindByTopicAsync(contest.Topic);

            if (exists != null)
            {
                throw new Exception("A contest with the same Topic already exists.");
            }

            var result =
                await _contestRepository.CreateAsync(ContestMapper.MapCreateContestRequestToContestStorage(contest));

            if (contest.Current)
            {
                await _contestRepository.SetCurrentAsync(result);

                // Schedule contest closing job
                var job = new SimpleJob(async scheduledTime =>
                {
                    await UpdateAsync(result, new UpdateContestRequest
                    {
                        Closed = true
                    });
                });

                _singularity.ScheduleJob(new RunOnceSchedule(TimeSpan.FromMinutes(1)), job, false);
            }

            return(new CreateContestResponse {
                Id = result
            });
        }
Esempio n. 2
0
        public async Task <ReadContestResponse> SetCurrentAsync(string id)
        {
            var result = await _contestRepository.ReadAsync(id);

            if (result != null)
            {
                await _contestRepository.SetCurrentAsync(id);
            }

            return(ContestMapper.MapContestStorageToReadContestResponse(result));
        }
Esempio n. 3
0
        public async Task <ReadContestResponse> ReadCurrentAsync()
        {
            var currentContest = await _contestRepository.ReadSettingsAsync("current");

            if (currentContest == null)
            {
                return(null);
            }

            return(ContestMapper.MapContestStorageToReadContestResponse(await _contestRepository.ReadAsync(currentContest.CurrentId)));
        }
Esempio n. 4
0
        public async Task UpdateAsync(string id, UpdateContestRequest updateContestRequest)
        {
            var contestStorage = ContestMapper.MapUpdateContestRequestToContestStorage(updateContestRequest);

            if (updateContestRequest.Closed == true)
            {
                var winner = await DeclareContestWinnerAsync(id);

                contestStorage.Winner = winner;
                await _contestRepository.SetWinnerAsync(winner);
            }

            await _contestRepository.UpdateAsync(id, contestStorage);
        }
Esempio n. 5
0
 public async Task <ReadContestResponse> ReadAsync(string id)
 {
     return(ContestMapper.MapContestStorageToReadContestResponse(await _contestRepository.ReadAsync(id)));
 }
Esempio n. 6
0
 public async Task <ReadContestListResponse> ReadAllAsync(string cursor)
 {
     return(ContestMapper.MapContestStorageToReadContestResponseList(await _contestRepository.ReadAllAsync(cursor)));
 }