public async Task CreateAsync(GameImageDto imageDto) { ThrowIfNotValidImage(imageDto); var image = await GetGameImageAsync(imageDto); await _gameImageRepository.AddAsync(image); await _unitOfWork.CommitAsync(); }
private static GameImageDto GetGameImageDto() { var dto = new GameImageDto { Content = new byte[] { 1, 2, 3 }, ContentType = "image/png" }; return(dto); }
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"); } }
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); }
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); }