public async Task <ImportResponse> ImportGamesAsync(GameImportRequest request) { ImportResponse response = await CheckRequest(request.UserID, request.Games.Count); if (!response.Successful) { return(response); } var user = await _userManager.FindByIdAsync(request.UserID); foreach (var game in request.Games) { try { game.UserID = request.UserID; game.UserNum = user.UserNum; game.ID = 0; _gameService.Add(game); response.Imported++; } catch (Exception ex) { response.Failed++; response.Message += $"{game.Title} - {ex.Message} : {ex.InnerException?.Message}"; } } response.Successful = true; return(response); }
public async Task <IActionResult> ImportGames([FromBody] GameImportRequest request) { if (request == null) { return(BadRequest("Request missing")); } var result = await _importService.ImportGamesAsync(request); return(Json(result)); }