public IActionResult CreateTeam(TeamEditModel model) { if (ModelState.IsValid) { if (TeamRepository.TeamExist(model.name)) { ViewBag.Exist = "These Team account exist"; } else { var m = new Team() { name = model.name, TeamDate = DateTime.Parse(model.TeamDate) }; TeamRepository.Add(m); TeamRepository.Commit(); HttpContext.Session.SetString("Success", "Team successfully created"); return(RedirectToAction("CreateTeam")); } } return(View()); }
public void ReadJsonDeserialize(string fileName, ITeam _teams, IPlayer _players, IEnumerable <Playersalary> playerSalaries) { Rootobject rootObject = JsonConvert.DeserializeObject <Rootobject>(File.ReadAllText(fileName)); decimal salary; int i = 1; int j = 0; foreach (var item in rootObject.rosterplayers.playerentry) { try { var name = item.player.LastName + " " + item.player.FirstName; System.Diagnostics.Debug.Write("#: " + i++ + "Id: " + item.player.ID + " " + name); Playersalary playerSalary = playerSalaries.FirstOrDefault(p => p.Player == name); if ((playerSalary == null) || (playerSalary.Salary == null)) { System.Diagnostics.Debug.Write(" " + j++ + "No Salary"); salary = 1000000; } else { salary = ( decimal )(playerSalary.Salary); } salary /= 1000000; SalaryCapData.Data.Models.Team team = new SalaryCapData.Data.Models.Team { Id = Convert.ToInt32(item.team.ID), City = item.team.City, Name = item.team.Name, Abbrev = item.team.Abbreviation }; int playerId = Convert.ToInt32(item.player.ID); SalaryCapData.Data.Models.PlayerPosition playerPosition = new SalaryCapData.Data.Models.PlayerPosition { PlayerId = playerId, Position = item.player.Position }; SalaryCapData.Data.Models.Player player = new SalaryCapData.Data.Models.Player { Id = playerId, Age = Convert.ToInt32(item.player.Age), FirstName = item.player.FirstName, LastName = item.player.LastName, IsRookie = item.player.IsRookie == "true" ? true : false, Position = item.player.Position, Team = team, TeamId = team.Id, //TotalPoints = 0, //PlayerPositions = playerPositions, InitialValue = salary }; _players.Add(player); _teams.Add(team); _players.AddPlayerPosition(playerPosition); //System.Diagnostics.Debug.Write( "\n" ); } catch (Exception ex) { System.Diagnostics.Debug.Write(ex); } System.Diagnostics.Debug.WriteLine(i + "Records Processed. " + j + "Had no salary. Delta: " + (i - j)); } }