Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public async Task <bool> UpdateAsync(string pictureId, string userId, UpdatePictureRequest updatePictureRequest)
        {
            var pictureStorage = PictureMapper.MapUpdatePictureRequestToPictureStorage(updatePictureRequest);

            var previousPicture = await _pictureRepository.ReadAsync(pictureId);

            var pictureContest = await _contestRepository.ReadAsync(previousPicture.ContestId);

            var currentContest = await _contestRepository.ReadSettingsAsync("current");

            // Vote has been cast, picture belongs to current contest, user has not already voted for contest
            if (updatePictureRequest.Vote &&
                pictureContest.Id == currentContest.CurrentId &&
                (pictureContest.Voters == null ||
                 pictureContest.Voters.All(x => x != userId)))
            {
                if (pictureContest.Voters == null)
                {
                    pictureContest.Voters = new List <string>();
                }

                pictureContest.Voters.Add(userId);
                pictureStorage.Votes = previousPicture.Votes + 1;

                await _contestRepository.UpdateAsync(pictureContest.Id, new ContestStorage
                {
                    Voters = pictureContest.Voters
                });

                await _pictureRepository.UpdateAsync(pictureId, pictureStorage);

                return(true);
            }
            if (updatePictureRequest.Caption != null)
            {
                await _pictureRepository.UpdateAsync(pictureId, pictureStorage);

                return(true);
            }

            return(false);
        }