public async Task <IActionResult> OnPostAsync(FootballPlayer FootballPlayer) { FootballPlayer FootballPlayerToUpdate = await _context.FootballPlayers.FirstOrDefaultAsync(m => m.Id == FootballPlayer.Id).ConfigureAwait(false); if (null == FootballPlayerToUpdate) { return(Content("Error - Football player does not exist.")); } FootballPlayerToUpdate.CentreBack = FootballPlayer.CentreBack; FootballPlayerToUpdate.Sweeper = FootballPlayer.Sweeper; FootballPlayerToUpdate.FullBack = FootballPlayer.FullBack; FootballPlayerToUpdate.WingBack = FootballPlayer.WingBack; FootballPlayerToUpdate.CentreMidfield = FootballPlayer.CentreMidfield; FootballPlayerToUpdate.DefensiveMidfield = FootballPlayer.DefensiveMidfield; FootballPlayerToUpdate.AttackingMidfield = FootballPlayer.AttackingMidfield; FootballPlayerToUpdate.WideMidfield = FootballPlayer.WideMidfield; FootballPlayerToUpdate.Forward = FootballPlayer.Forward; FootballPlayerToUpdate.CentreForward = FootballPlayer.CentreForward; FootballPlayerToUpdate.Winger = FootballPlayer.Winger; FootballPlayerToUpdate.SetRating(); int result = await _context.SaveChangesAsync().ConfigureAwait(false); if (result == 1) { return(Content($"{FootballPlayerToUpdate.Player.FirstName} has been updated!")); } return(Content("Error - please contact your system administrator")); }
public void SetPlayerRatingTest() { FootballPlayer FootyPlayer = GenerateFootballPlayers()[0]; FootyPlayer.SetRating(); Assert.IsNotNull(FootyPlayer.Rating); Assert.IsTrue(FootyPlayer.Rating <= 100 && FootyPlayer.Rating >= 0); var FootyPlayer2 = new FootballPlayer() { Defence = 56, Midfield = 80, Forward = 90 }; int expectedRating = (FootyPlayer2.Defence + FootyPlayer2.Midfield + FootyPlayer2.Forward) / 3; FootyPlayer2.SetRating(); int actualRating = FootyPlayer2.Rating; Assert.AreEqual(expectedRating, actualRating); }
public async void Seed() { Random rnd = new Random(); if (!Players.Any() && !FootballPlayers.Any() && !Sports.Any()) { Sport Football = new Football(); Sports.Add(Football); var Andrew = new Player() { FirstName = "Andrew", LastName = "Sharrock", }; var Stuart = new Player() { FirstName = "Stuart", LastName = "Sharrock", }; var Jim = new Player() { FirstName = "Jim", LastName = "Sharrock", }; var Gill = new Player() { FirstName = "Gill", LastName = "Sharrock", }; var Stevie = new Player() { FirstName = "Stevie", LastName = "Sharrock", }; var Carly = new Player() { FirstName = "Carly", LastName = "Richardson" }; var Timme = new Player() { FirstName = "Timme", LastName = "Martin", }; var Pete = new Player() { FirstName = "Pete", LastName = "Skipp", }; var Paul = new Player() { FirstName = "Paul", LastName = "French", }; var Leeroy = new Player() { FirstName = "Leeroy", LastName = "Jenkins", }; await Players.AddAsync(Andrew); await Players.AddAsync(Stuart); await Players.AddAsync(Jim); await Players.AddAsync(Gill); await Players.AddAsync(Stevie); await Players.AddAsync(Carly); await Players.AddAsync(Timme); await Players.AddAsync(Pete); await Players.AddAsync(Paul); await Players.AddAsync(Leeroy); SaveChanges(); var AndrewFootballPlayer = new FootballPlayer() { PlayerId = Andrew.Id, CentreBack = rnd.Next(1, 101), CentreMidfield = rnd.Next(1, 101), Forward = rnd.Next(1, 101) }; var StuartFootballPlayer = new FootballPlayer() { PlayerId = Stuart.Id, CentreBack = rnd.Next(1, 101), CentreMidfield = rnd.Next(1, 101), Forward = rnd.Next(1, 101) }; var JimFootballPlayer = new FootballPlayer() { PlayerId = Jim.Id, CentreBack = rnd.Next(1, 101), CentreMidfield = rnd.Next(1, 101), Forward = rnd.Next(1, 101) }; var GillFootballPlayer = new FootballPlayer() { PlayerId = Gill.Id, CentreBack = rnd.Next(1, 101), CentreMidfield = rnd.Next(1, 101), Forward = rnd.Next(1, 101) }; var StevieFootballPlayer = new FootballPlayer() { PlayerId = Stevie.Id, CentreBack = rnd.Next(1, 101), CentreMidfield = rnd.Next(1, 101), Forward = rnd.Next(1, 101) }; var CarlyFootballPlayer = new FootballPlayer() { PlayerId = Carly.Id, CentreBack = rnd.Next(1, 101), CentreMidfield = rnd.Next(1, 101), Forward = rnd.Next(1, 101) }; var TimmeFootballPlayer = new FootballPlayer() { PlayerId = Timme.Id, CentreBack = rnd.Next(1, 101), CentreMidfield = rnd.Next(1, 101), Forward = rnd.Next(1, 101) };; var PeteFootballPlayer = new FootballPlayer() { PlayerId = Pete.Id, CentreBack = rnd.Next(1, 101), CentreMidfield = rnd.Next(1, 101), Forward = rnd.Next(1, 101) }; var PaulFootballPlayer = new FootballPlayer() { PlayerId = Paul.Id, CentreBack = rnd.Next(1, 101), CentreMidfield = rnd.Next(1, 101), Forward = rnd.Next(1, 101) }; var LeeroyFootballPlayer = new FootballPlayer() { PlayerId = Leeroy.Id, CentreBack = rnd.Next(1, 101), CentreMidfield = rnd.Next(1, 101), Forward = rnd.Next(1, 101) }; AndrewFootballPlayer.SetRating(); StuartFootballPlayer.SetRating(); JimFootballPlayer.SetRating(); GillFootballPlayer.SetRating(); StevieFootballPlayer.SetRating(); CarlyFootballPlayer.SetRating(); TimmeFootballPlayer.SetRating(); PeteFootballPlayer.SetRating(); PaulFootballPlayer.SetRating(); LeeroyFootballPlayer.SetRating(); await FootballPlayers.AddAsync(AndrewFootballPlayer); await FootballPlayers.AddAsync(StuartFootballPlayer); await FootballPlayers.AddAsync(JimFootballPlayer); await FootballPlayers.AddAsync(GillFootballPlayer); await FootballPlayers.AddAsync(StevieFootballPlayer); await FootballPlayers.AddAsync(CarlyFootballPlayer); await FootballPlayers.AddAsync(TimmeFootballPlayer); await FootballPlayers.AddAsync(PeteFootballPlayer); await FootballPlayers.AddAsync(PaulFootballPlayer); await FootballPlayers.AddAsync(LeeroyFootballPlayer); SaveChanges(); await PlayerSports.AddAsync(new PlayerSports() { PlayerId = Andrew.Id, SportId = Football.Id, }); await PlayerSports.AddAsync(new PlayerSports() { PlayerId = Stuart.Id, SportId = Football.Id, }); await PlayerSports.AddAsync(new PlayerSports() { PlayerId = Jim.Id, SportId = Football.Id, }); await PlayerSports.AddAsync(new PlayerSports() { PlayerId = Gill.Id, SportId = Football.Id, }); await PlayerSports.AddAsync(new PlayerSports() { PlayerId = Stevie.Id, SportId = Football.Id, }); await PlayerSports.AddAsync(new PlayerSports() { PlayerId = Carly.Id, SportId = Football.Id, }); await PlayerSports.AddAsync(new PlayerSports() { PlayerId = Timme.Id, SportId = Football.Id, }); await PlayerSports.AddAsync(new PlayerSports() { PlayerId = Pete.Id, SportId = Football.Id, }); await PlayerSports.AddAsync(new PlayerSports() { PlayerId = Paul.Id, SportId = Football.Id, }); await PlayerSports.AddAsync(new PlayerSports() { PlayerId = Leeroy.Id, SportId = Football.Id, }); SaveChanges(); } }