コード例 #1
0
        /// <summary>Overwrites all of the players in the source with this collection.</summary>
        /// <param name="players">All of the players to to store in the source.</param>
        [HttpPost] public void OverwritePlayers(PlayerCollection players)
        {
            if (players == null || players.Players == null)
            {
                throw new BadRequestException("Players not set");
            }
            var playerList = _cleanService.CleanData(players.Players);

            playerList = _sortService.SortPlayers(playerList);
            _writerService.WriteCsvData(_configuration.GetValue <string>("CsvFiles:PlayerFile"), playerList);
        }
        /// <summary>Export the players as a CSV file.</summary>
        /// <returns>A CSV file containing the players.</returns>
        [HttpGet] public async Task <IActionResult> ExportPlayers()
        {
            var existingPlayers = await _getterService.GetData <List <CsvBaseballPlayer> >($"{_configuration.GetValue<string>("ServiceUrls:PlayerService")}/v1/player");

            var fileContent = _writerService.WriteCsvData(existingPlayers ?? new List <CsvBaseballPlayer>());

            Response.Headers.Add("Content-Disposition", new ContentDisposition {
                FileName = "players.csv", Inline = false
            }.ToString());
            return(File(fileContent, "application/octet-stream", "players.csv"));
        }