Example #1
0
        public async Task CreateAsync(GameImageDto imageDto)
        {
            ThrowIfNotValidImage(imageDto);
            var image = await GetGameImageAsync(imageDto);

            await _gameImageRepository.AddAsync(image);

            await _unitOfWork.CommitAsync();
        }
Example #2
0
        private static GameImageDto GetGameImageDto()
        {
            var dto = new GameImageDto
            {
                Content     = new byte[] { 1, 2, 3 },
                ContentType = "image/png"
            };

            return(dto);
        }
Example #3
0
        private static void ThrowIfNotValidImage(GameImageDto image)
        {
            if (image?.Content == null || !image.Content.Any())
            {
                throw new InvalidServiceOperationException("Is empty image");
            }

            if (string.IsNullOrEmpty(image.GameKey))
            {
                throw new InvalidServiceOperationException("Is empty game key");
            }
        }
Example #4
0
        private async Task <GameImage> GetGameImageAsync(GameImageDto imageDto)
        {
            var game = await _gameService.GetByKeyAsync(imageDto.GameKey);

            var image = new GameImage
            {
                Id          = imageDto.Id,
                Content     = imageDto.Content,
                ContentType = imageDto.ContentType,
                GameRootId  = game.Id
            };

            return(image);
        }
Example #5
0
        private static async Task <GameImageDto> GetImageDtoAsync(ModifyImageViewModel viewModel)
        {
            await using var stream = new MemoryStream();
            await viewModel.Image.CopyToAsync(stream);

            var gameImageDto = new GameImageDto
            {
                Id          = viewModel.Id,
                Content     = stream.ToArray(),
                GameKey     = viewModel.GameKey,
                ContentType = viewModel.Image.ContentType
            };

            return(gameImageDto);
        }