// PUT: odata/GamesImporter(5) public async Task<IHttpActionResult> Put([FromODataUri] int key, Game patch) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Game game = await db.Games.FindAsync(key); if (game == null) { return NotFound(); } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameExists(key)) { return NotFound(); } else { throw; } } return Updated(game); }
public GameDto(Game g) { this.GameId = g.GameId; this.ShortName = g.ShortName; this.Title = g.Title; this.Description = g.Description; this.ImportId = g.ImportId; this.RegistrationDate = g.RegistrationDate; this.Image = g.ImageThumb; this.GenreId = g.GenreId; this.PlatformId = g.PlatformId; }
// POST: odata/GamesImporter public async Task<IHttpActionResult> Post(Game game) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Games.Add(game); await db.SaveChangesAsync(); return Created(game); }
/// <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; }
private async Task<Game> CheckGenrePlatform(Game game) { if (game.Genre != null) { if (await db.Genres.Where(gr => gr.GenreId == game.Genre.GenreId).AnyAsync()) game.Genre = null; else Conflict(); } if (game.Platform != null) { if (await db.Platforms.Where(p => p.PlatformId == game.Platform.PlatformId).AnyAsync()) game.Platform = null; else Conflict(); } return game; }
public async Task<IHttpActionResult> PutGame(int id, Game game) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != game.GameId) { return BadRequest(); } db.Entry(await CheckGenrePlatform(game)).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task LoadFromuPlayAgain() { List<Game> gs = null; Game GameFilter = new Game(); await Task.Factory.StartNew(async () => { GiochiCaricati = string.Empty; if (GamesDto.Count > 0) GamesDto.Clear(); // Create oData Filter and count if (CurrentPlatform != default(Platform)) GameFilter.PlatformId = CurrentPlatform.PlatformId; if (CurrentGenre != default(Genre)) GameFilter.GenreId = CurrentGenre.GenreId; gs = (await _currentWebApi.GetGameIds(GameFilter)).ToList(); int numGiochi = gs.Count; int giocoCorrente = 0; double percentageToIncrement = (double)100 / numGiochi; ProgressBarValue = 0; gs.ForEach(async currentGameSummary => { try { GameDto result = _mapper.Map<GameDto>(await _currentWebApi.GetGameById(new Game() { GameId = currentGameSummary.GameId })); if(result != null) await App.Current.Dispatcher.BeginInvoke((Action)delegate () { GamesDto.Add(result); }); } catch (Exception ex) { string a = ex.Message; } finally { giocoCorrente++; GiochiCaricati = string.Format("{0} / {1}", giocoCorrente, numGiochi); ProgressBarValue += percentageToIncrement; if (numGiochi == giocoCorrente) // Apro il popup di segnalazione. Finita importazione await App.Current.Dispatcher.BeginInvoke((Action)async delegate () { await _dialogCoordinator.ShowMessageAsync(this, "Caricamento completato...", "Puoi modificare i giochi o crearne di nuovi", MessageDialogStyle.Affirmative, new MetroDialogSettings() { ColorScheme = MetroDialogColorScheme.Accented, AnimateShow = true }); }); } }); }); }
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); }
public async Task<Game> UpdateGame(Game g) => await Client.UpdateGame(g);
public async Task DeleteGame(Game g) => await Client.DeleteGame(g);
public async Task<Game> InsertGame(Game g) => await Client.InsertGame(g);
public async Task<Game> GetGameById(Game g) => await Client.GetGameById(g);
public async Task<IEnumerable<Game>> GetGameIds(Game g) => await Client.GetGameIds(g);
public async Task<IEnumerable<Game>> GetGamesByFieldSearch(Game g) => await Client.GetGamesByFieldSearch(g);
public async Task<Game> GetGameByFieldSearch(Game g) => await Client.GetGameByFieldSearch(g);