public Round StartRoundOrGetExisting(int userId) { GameEntity gameEntity = StartNewGameOrGetExisting(userId); RoundEntity roundEntity = _roundRepository.GetCurrentOpenRound(gameEntity.Id); if (null != roundEntity) { // Unfinished round return(RoundEntityFactory.Create(roundEntity, ROUNDS_PER_GAME, RoundsPlayedInGame(gameEntity.Id))); } roundEntity = RoundEntityFactory.Create(gameEntity.Id); // Determine the correct one var randomImages = _imageRepository.GetRandomImages(IMAGES_PER_ROUND, _userRepository.Get(userId).FullName); int indexOfCorrectImageInList = (new Random()).Next(IMAGES_PER_ROUND); var correctImage = randomImages.ElementAt(indexOfCorrectImageInList); Round round = RoundFactory.Create(new List <Image>(), RoundsPlayedInGame(gameEntity.Id), ROUNDS_PER_GAME, correctImage.Name); roundEntity.CorrectImageId = correctImage.Id; _roundRepository.Create(roundEntity); foreach (ImageEntity imageEntity in randomImages) { ImageInRoundEntity imageInRoundEntity = ImageInRoundEntityFactory.Create(imageEntity.Id, roundEntity.Id); _imageInRoundRepository.Create(imageInRoundEntity); round.Images.Add(ImageFactory.Create(imageEntity.Url, imageEntity.Id)); } return(round); }
public static Image Create(ImageInRoundEntity imageInRoundEntity) { return(new Image { Id = imageInRoundEntity.ImageId, Url = imageInRoundEntity.Image.Url }); }