public async Task <IActionResult> Add([FromBody] GoalscorerArrayDTO goalscorersDTO) { await _goalscorerService.Add(_mapper.Map <List <Goalscorer> >(goalscorersDTO.Goalscorer)); return(new OkObjectResult(true)); }
public void Run() { GoalscorersInExcel = new List <GoalscorerSync>(); GoalscorersToAdd = new List <Goalscorer>(); try { ConsoleMessage("/********************* Sync Goalscorers *********************/", ConsoleColor.DarkCyan); ConsoleMessage("Insert TournamentID: "); string strTournament = Console.ReadLine(); int tournamentId; if (!int.TryParse(strTournament, out tournamentId) || tournamentId <= 0) { ConsoleMessage("Tournament ID must be a number greater than 0", ConsoleColor.DarkRed, true); Run(); } ConsoleMessage("Retrieving tournament..", ConsoleColor.DarkMagenta); Tournament tournament = _tournamentService.Get(tournamentId).Result; if (tournament == null) { ConsoleMessage("Tournament not found", ConsoleColor.DarkRed, true); Run(); } ConsoleMessage(tournament.Name, ConsoleColor.DarkGreen); ConsoleMessage("Reading Excel file..", ConsoleColor.DarkMagenta); LoadExcelFile(); if (GoalscorersInExcel.Count <= 0) { ConsoleMessage("Excel file appears to be empty", ConsoleColor.DarkRed, true); Run(); } ConsoleMessage($"{GoalscorersInExcel.Count} goalscorers read", ConsoleColor.DarkGreen); CheckIfContinue(); ConsoleMessage("Processing file data..", ConsoleColor.DarkMagenta); ProcessData(tournament); if (GoalscorersToAdd.Count <= 0) { ConsoleMessage("No players were processed", ConsoleColor.DarkRed, true); Run(); } ConsoleMessage(GoalscorersToAdd.Count + " players processed", ConsoleColor.DarkGreen); CheckIfContinue(); ConsoleMessage("Saving..", ConsoleColor.DarkMagenta); try { _goalscorerService.Add(GoalscorersToAdd).Wait(); ConsoleMessage("Finished syncing goalscorers successfully", ConsoleColor.DarkGreen); } catch (Exception ex) { ConsoleMessage($"Error saving data: {ex.Message}", ConsoleColor.DarkRed); } ConsoleMessage("Press Enter to restart..", addNewLine: true); if (Console.ReadKey().Key == ConsoleKey.Enter) { Run(); } } catch (Exception ex) { ConsoleMessage($"Error: {ex.Message}", ConsoleColor.DarkRed); } }