public async Task <ReadContestResponse> ReadCurrentAsync() { var currentContest = await _contestRepository.ReadSettingsAsync("current"); if (currentContest == null) { return(null); } return(ContestMapper.MapContestStorageToReadContestResponse(await _contestRepository.ReadAsync(currentContest.CurrentId))); }
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); }