public ActionResult Edit(GamingSessionViewModel GamingSessionViewModel) { if (ModelState.IsValid) { //Adds the new Game GamingSession GamingSession = db.GamingSessions.Find(GamingSessionViewModel.GamingSession.id); Game NewGame = GamingSessionViewModel.NewGame; //Home Team Team HomeTeamTeam = db.pushTeam(NewGame.HomeTeam); NewGame.HomeTeam = HomeTeamTeam; NewGame.HomePlayer.DefaultTeam = HomeTeamTeam; Player HomeTeamPlayer = db.pushPlayer(NewGame.HomePlayer); NewGame.HomePlayer = HomeTeamPlayer; //Away Team Team AwayTeamTeam = db.pushTeam(NewGame.AwayTeam); NewGame.AwayTeam = AwayTeamTeam; NewGame.AwayPlayer.DefaultTeam = AwayTeamTeam; Player AwayTeamPlayer = db.pushPlayer(NewGame.AwayPlayer); NewGame.AwayPlayer = AwayTeamPlayer; //New Game GamingSession.Games.Add(GamingSessionViewModel.NewGame); //Other attributes GamingSession.Date = GamingSessionViewModel.GamingSession.Date; //db.GamingSessions.Attach(GamingSessionViewModel.GamingSession); //db.Entry(GamingSessionViewModel.GamingSession).State = EntityState.Modified; db.Games.Add(NewGame); var state = db.Entry(GamingSession).State; var state2 = db.Entry(NewGame).State; db.Entry(GamingSession).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(GamingSessionViewModel); }
// // GET: /GaminSession/Edit/5 public ActionResult Edit(int id = 0) { GamingSession GamingSession = db.GamingSessions.Find(id); GamingSessionViewModel GamingSessionViewModel = new GamingSessionViewModel(); GamingSessionViewModel.GamingSession = GamingSession; GamingSessionService GamingSessionService = new GamingSessionService(); if (GamingSession == null) { return HttpNotFound(); } //Add viewbags return View(GamingSessionViewModel); }