public async Task <IActionResult> SetGameImage(int id, IFormFile image) { if (!IsValidImage(image)) { return(BadRequest( $"invalid content type for image, got {image.ContentType} but expected image/png")); } var result = await _gameImageService.SetImageAsync(id, image.OpenReadStream()); return(result ? (IActionResult)AcceptedAtRoute(nameof(GetGameImage), new { id }) : BadRequest("Failed to set image")); }
public async Task <Game> CreateGame(NewGameModel model) { try { var dbModel = _mapper.Map <Game>(model); await _context.Games.AddAsync(dbModel); await _context.SaveChangesAsync(); if (model.Image != null) { await _gameImageService.SetImageAsync(dbModel.Id, model.Image.OpenReadStream()); } return(dbModel); } catch { return(null); } }