/// <summary> /// Converte i dati di un gioco presente su TheGamesDB con quelli di uPlayAgain /// </summary> /// <param name="d"></param> /// <param name="genres"></param> /// <param name="platforms"></param> /// <returns></returns> public static Game Convert(uPlayAgain.TheGamesDB.Entity.Data d, List<Genre> genres, List<Platform> platforms) { Game g = new Game(); g.ImportId = d.Game.id; g.Description = d.Game.Overview; g.Title = d.Game.GameTitle; if (!string.IsNullOrEmpty(d.Game.GameTitle)) g.ShortName = d.Game.GameTitle.RemoveMultipleSpace().Replace(" ", "-").Substring(0, Math.Min(d.Game.GameTitle.Length, 30)); g.Platform = GetPlatform(d.Game.PlatformId, platforms); g.PlatformId = g.Platform != null ? g.Platform.PlatformId : null; g.Image = d.DowloadedFrontImage; g.ImageThumb = g.Resize(); g.Genre = GetGenre(d.Game.Genres == null ? string.Empty : d.Game.Genres.genre, genres); g.GenreId = g.Genre != null ? g.Genre.GenreId : null; return g; }
public async Task<IHttpActionResult> PostGame(Game game) { if (!ModelState.IsValid) { return BadRequest(ModelState); } // Calcolo le immagini thum if(game.Image != null) game.ImageThumb = game.Resize(); db.Games.Add(await CheckGenrePlatform(game)); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = game.GameId }, game); }