public async Task <ActionResult <Models.Team> > PutTeam(long id, Team team) { bool isUnique = await _context.IsUnique(team.name, id); if (!isUnique) { return(ValidationProblem("Name must be unique")); } var originalTask = await _context.GetTeam(id); team.id = id; team.date = originalTask.date; team._id = originalTask._id; await _context.Update(team); try { await _context.SaveChangesAsync(); return(team); } catch (DbUpdateConcurrencyException) { if (!TeamExists(id)) { return(ValidationProblem()); } else { throw; } } }
public void CanStoreAndUpdatePlayer() { var firstname = "Romelu"; var lastname = "Lukaku"; var firstname2 = "Eden"; var lastname2 = "Hazard"; var team = CreateTeamAjax(); Assert.True(team.AddPlayer(firstname, lastname, out var response)); var player = team.Players.First(); using (var context = new TeamContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Teams.Add(team); context.SaveChanges(); } Team teamFound; using (var context = new TeamContext()) { teamFound = context.Teams.Include(t => t.Players).FirstOrDefault(t => t.Id == team.Id); } Assert.Equal(player.Name, teamFound.Players.First().Name); Assert.True(teamFound.RemovePlayer(firstname, lastname, out response)); Assert.True(teamFound.AddPlayer(firstname2, lastname2, out response)); using (var context = new TeamContext()) { var storedTeam = context.Teams.Include(t => t.Players).FirstOrDefault(t => t.Id == team.Id); context.Update(storedTeam); storedTeam.SyncPlayers(teamFound.Players); context.SaveChanges(); } using (var context = new TeamContext()) { teamFound = context.Teams.Include(t => t.Players).FirstOrDefault(t => t.Id == team.Id); } Assert.Equal(new Player(firstname2, lastname2).Name, teamFound.Players.First().Name); }