public ActionResult PrjEdit(Project project, int[] selectedWorkers) { Project newProject = db.Projects.Find(project.Id); newProject.Name = project.Name; newProject.Leader = project.Leader; newProject.Customer = project.Customer; newProject.Performer = project.Performer; newProject.Priority = project.Priority; newProject.DateStart = project.DateStart; newProject.DateEnd = project.DateEnd; if (ModelState.IsValid) { newProject.Workers.Clear(); if (selectedWorkers != null) { foreach (var c in db.Workers.Where(co => selectedWorkers.Contains(co.Id))) { newProject.Workers.Add(c); } } db.Entry(newProject).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("../Home/Index")); } ViewBag.Workers = db.Workers.ToList(); return(View(project)); }
public IActionResult Create(TeamItem item) { Guid g; g = Guid.NewGuid(); var name = item.name; var nameFC = _context.TeamItems.Where(e => e.name == name).ToList(); var location = item.location; var locationFC = _context.TeamItems.Where(e => e.location == location).ToList(); var wht = _context.TeamItems.Where(e => e.location == location && e.name == name).ToList(); if (item.players != null) { if (item.players.Count >= 24) { var reasonPhrase = "Too Many Players"; return(BadRequest(reasonPhrase)); } } else if (wht.Count > 0) { var reasonPhrase = "Name and Location cannot be the same for multiple teams"; return(BadRequest(reasonPhrase)); } item.id = g; _context.TeamItems.Add(item); _context.SaveChanges(); return(Ok(item)); }
public ActionResult WorkerEdit(Worker worker, int[] selectedProjects) { Worker newPlayer = db.Workers.Find(worker.Id); newPlayer.Name = worker.Name; newPlayer.Surname = worker.Surname; newPlayer.Patronymic = worker.Patronymic; newPlayer.Email = worker.Email; if (ModelState.IsValid) { newPlayer.Projects.Clear(); if (selectedProjects != null) { foreach (var c in db.Projects.Where(co => selectedProjects.Contains(co.Id))) { newPlayer.Projects.Add(c); } } db.Entry(newPlayer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("../Home/Index")); } ViewBag.Projects = db.Projects.ToList(); return(View(worker)); }
public Team Remove(Team team) { var removedTeam = _teamContext.Team.Remove(team); _teamContext.SaveChanges(); return(removedTeam); }
public Team AddTeam(Team team) { _context.Teams.Add(team); _context.SaveChanges(); return(team); }
public int AddTeam(Team team) { if (team == null) { throw new Exception("AddTeam method error: team is null"); } _db.Teams.Add(team); _db.SaveChanges(); return(team.Id); }
public ActionResult Create([Bind(Include = "ID,FirstName,LastName")] Player player) { if (ModelState.IsValid) { db.Players.Add(player); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(player)); }
public ActionResult Create([Bind(Include = "ID,Name,Wins,Losses,Ties")] Team team) { if (ModelState.IsValid) { db.Teams.Add(team); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(team)); }
public ActionResult Create(Team model) { if (ModelState.IsValid) { db.Teams.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Create([Bind(Include = "ID,SchoolName,Nickname")] Team team) { if (ModelState.IsValid) { db.Teams.Add(team); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(team)); }
public ActionResult Create([Bind(Include = "ID,PlayerName,Position,TeamId")] Player player) { if (ModelState.IsValid) { db.Players.Add(player); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TeamId = new SelectList(db.Teams, "ID", "SchoolName", player.TeamId); return(View(player)); }
public IActionResult Create([FromBody] Player player) { if (player == null) { return(BadRequest()); } _context.Team.Add(player); _context.SaveChanges(); return(CreatedAtRoute("GetPlayer", new { name = player.name, number = player.number, position = player.position, id = player.Id, salary = player.salary, }, player)); }
public ActionResult Create([Bind(Include = "ID,Name,Wins,Losses,Ties")] Team team) { if (ModelState.IsValid) { db.Teams.Add(team); db.SaveChanges(); // When a team is added, the cache is out of date. // Clear the cached teams. ClearCachedTeams(); return(RedirectToAction("Index")); } return(View(team)); }
void PlayGames() { ViewBag.msg += "Updating team statistics. "; // Play a "season" of games. var teams = from t in db.Teams select t; Team.PlayGames(teams); db.SaveChanges(); // Clear any cached results ClearCachedTeams(); }
private static void FillAllTables() { using (var context = new TeamContext()) { context.Teams.Add(firstTeam); context.Teams.Add(secondTeam); context.Players.Add(firstPlayer); context.Players.Add(secondPlayer); context.Players.Add(thirdPlayer); context.Players.Add(fourthPlayer); context.Players.Add(fifthPlayer); context.Players.Add(sixthPlayer); context.Players.Add(seventhPlayer); context.Players.Add(eighthPlayer); context.Players.Add(ninthPlayer); context.Players.Add(tenthPlayer); context.Players.Add(eleventhPlayer); context.Players.Add(twelfthPlayer); context.Players.Add(thirteenthPlayer); context.Players.Add(fourteenthPlayer); context.SaveChanges(); } }
/// <summary> /// The method creates a team undert the given name and adds it to the database /// </summary> /// <example> /// <code> /// try /// { /// TeamBusiness.CreateTeam(ImputTeamName); /// } /// </code> /// </example> /// <exception cref="HangManV2.Commons.TeamAlreadyExistsExeption">Thrown when the inserted team name is already used by another team /// </exception> /// <exception cref="HangManV2.Commons.TeamNameNullExeption">Thrown when the inserted team name is null /// </exception> public static void CreateTeam(string imputTeamName) { try { CheckIfTeamNameNull(imputTeamName); } catch (TeamNameNullExeption) { throw new TeamNameNullExeption(); } if (imputTeamName.Length > 10) { throw new InvalidOperationException(); } try { CheckIfTeamExists(imputTeamName); } catch (TeamAlreadyExistsExeption) { throw new TeamAlreadyExistsExeption(); } using (var dbcontext = new TeamContext()) { RemovePointsFromOldTeam(); team newTeam = new team(); newTeam.TeamName = imputTeamName; newTeam.TeamPointAmount = CurrentUser.poitAmount; dbcontext.Teams.Add(newTeam); dbcontext.SaveChanges(); CurrentUser.UpdateUserTeamInDB(newTeam.TeamId); } }
public void CanReadManagerHistoryView() { var team = TeamAjax; var firstmanager = new Manager("Scott", "Hunter"); team.ChangeManagement(firstmanager); team.ChangeManagement(new Manager("Erik", "ten Hag")); var teamdotNet = new Team("dotNet", "The Nerds", "2002", "MS Campus"); teamdotNet.ChangeManagement(firstmanager); teamdotNet.ChangeManagement(new Manager("David", "Fowler")); using (var context = new TeamContext()) { context.AddRange(team, teamdotNet, firstmanager); context.SaveChanges(); } using (var context2 = new TeamContext()) { var histories = context2.ManagerHistories.ToList(); int counter = 0; foreach (var history in context2.ManagerHistories.ToList()) { counter += 1; output.WriteLine($"{history.Manager}: {history.Team}"); } Assert.Equal(4, counter); } }
public void RemoveTeam_Test() { //Arrange var options = new DbContextOptionsBuilder <TeamContext>().UseInMemoryDatabase($"TeamContext_{ Guid.NewGuid() }").Options; using (var context = new TeamContext(options)) { context.Add(new Team() { Id = 1, City = "Chicago", Name = "Chicago Fire", DateOfFoundation = DateTime.Now }); context.Add(new Team() { Id = 2, City = "Los Angeles", Name = "Los Angeles Galaxy", DateOfFoundation = DateTime.Now }); context.SaveChanges(); var repository = new TeamsRepository(context); //Act repository.RemoveTeam(1); var teams = repository.GetTeams().ToList(); //Assert Assert.Equal(1, teams.Count); } }
public IActionResult Post([FromBody] CrashLog newLog) { using (TeamContext context = new TeamContext()) { context.CrashLogs.Add(newLog); context.SaveChanges(); } return(Created("/User", Log())); }
public IActionResult Create([FromBody] Team item) { if (item == null) { return(BadRequest()); } var team = new Team { Id = item.Id, Name = item.Name, Sport = _sportContext.Sports.FirstOrDefault(x => x.Id == item.SportId) }; _context.Teams.Add(team); _context.SaveChanges(); return(CreatedAtRoute("GetTeam", new { id = item.Id }, item)); }
public IEnumerable <Team> Create([FromBody] Team newTeam) { using (TeamContext context = new TeamContext()) { context.Teams.Add(newTeam); context.SaveChanges(); return(GetTeam(context)); } }
public IEnumerable <Player> Create([FromBody] Player newPlayer) { using (TeamContext context = new TeamContext()) { context.Players.Add(newPlayer); context.SaveChanges(); return(GetPlayers(context)); } }
public void CanStoreAndRetrieveHomeColors() { var team = CreateTeamAjax(); team.SpecifyHomeUniformColors(Color.White, Color.Red, Color.Empty, Color.White, Color.Empty, Color.White); var options = new DbContextOptionsBuilder <TeamContext> ().UseInMemoryDatabase("storemanagerhistory").Options; using (var context = new TeamContext(options)) { context.Teams.Add(team); context.SaveChanges(); } }
public PlayerController(TeamContext context) { _context = context; if (_context.Team.Count() == 0) { _context.Team.Add(new Player { name = "David Luiz", position = "defender", number = 30, salary = 2000000, Id = 1 }); _context.SaveChanges(); } }
protected override void Seed(TeamContext context) { context.Players.AddOrUpdate( new Player { FirstName = "Carson", LastName = "Alexander" }, new Player { FirstName = "David", LastName = "Harris" } ); context.SaveChanges(); context.Teams.AddOrUpdate( new Team { teamName = "Birds" }); context.SaveChanges(); }
public TeamController(TeamContext context) { _context = context; if (_context.Teams.Count() == 0) { _context.Teams.AddRange(new SampleTeamData().GetSampleTeamData()); _context.Teams.Add(new Team { Name = "Default Team" }); _context.SaveChanges(); } }
public void CanStoreAndMaterializeImmutableTeamNameFromDataStore() { var team = TeamAjax; using (var context = new TeamContext()) { context.Teams.Add(team); context.SaveChanges(); } using (var context = new TeamContext()) { var storedTeam = context.Teams.FirstOrDefault(); Assert.Equal("AFC Ajax", storedTeam.TeamName); } }
/// <summary> /// The method removes the current users points from their teamID /// </summary> /// <example> /// <code> /// RemovePointsFromOldTeam(); /// </code> /// </example> private static void RemovePointsFromOldTeam() { if (CurrentUser.teamId != 1) { using (var dbcontext = new TeamContext()) { var oldTeam = dbcontext.Teams.Find(CurrentUser.teamId); var oldTeamUpdatedpoints = oldTeam; oldTeamUpdatedpoints.TeamPointAmount -= CurrentUser.poitAmount; dbcontext.Entry(oldTeam).CurrentValues.SetValues(oldTeamUpdatedpoints); // dbcontext.Teams.Add(newTeam); dbcontext.SaveChanges(); } } }
public IEnumerable <Player> Delete(int id) { using (TeamContext context = new TeamContext()) { Player toRemove = context.Players.Find(id); if (toRemove != null) { context.Players.Remove(toRemove); context.SaveChanges(); } return(GetPlayers(context)); } }
public void CanStoreAndMaterializeImmutableTeamNameFromDataStore() { var team = TeamAjax; var options = new DbContextOptionsBuilder <TeamContext>().UseInMemoryDatabase("immutableTeamName").Options; using (var context = new TeamContext(options)) { context.Teams.Add(team); context.SaveChanges(); } using (var context = new TeamContext(options)) { var storedTeam = context.Teams.FirstOrDefault(); Assert.Equal("AFC Ajax", storedTeam.TeamName); } }