Ejemplo n.º 1
0
        public async Task <IActionResult> Upload(IFormFile upload)
        {
            using (var reader = new StreamReader(upload.OpenReadStream()))
            {
                string currentLine;
                while ((currentLine = reader.ReadLine()) != null)
                {
                    Console.WriteLine(currentLine);
                    string[] columns = currentLine.Split(',');
                    Console.WriteLine(columns);
                    Player playerToAdd = new Player();
                    playerToAdd.PlayerName = columns[0];
                    playerToAdd.PlayerTeam = columns[1];
                    string playerPos = Regex.Replace(columns[2], @"[\d-]", string.Empty);
                    playerToAdd.PlayerPos = playerPos;
                    Console.WriteLine(playerToAdd);
                    await _playerRepository.AddNewPlayerAsync(playerToAdd);

                    var returnedPlayer = await _playerRepository.GetByPlayerByName(playerToAdd.PlayerName);

                    await AddPlayerRankingMethod.AddPlayerRanking(returnedPlayer, _rankingRepository, _playerRepository);
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(Player newPlayer, IFormCollection collection)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(newPlayer));
                }

                await _playerRepository.AddNewPlayerAsync(newPlayer);

                var returnedPlayer = await _playerRepository.GetByPlayerByName(newPlayer.PlayerName);

                await AddPlayerRankingMethod.AddPlayerRanking(returnedPlayer, _rankingRepository, _playerRepository);

                return(RedirectToAction(nameof(Index)));
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(View(newPlayer));
        }