예제 #1
0
        public ActionResult Create(Game game)
        {
            if (ModelState.IsValid)
            {
                game.Marker = User.Identity.Name;
                game = db.Games.Add(game);
                game.GameHoles = new List<GameHole>();
                for (int r = 1; r <= game.Rounds; r++)
                {
                    foreach (var hole in db.GolfCourses.Find(game.GolfCourseID).CourseHoles)
                    {
                        game.GameHoles.Add(new GameHole { CourseHoleID = hole.CourseHoleID  });
                    }
                }
                db.SaveChanges();
                ViewBag.GolfCourseID = new SelectList(db.GolfCourses, "GolfCourseID", "Name", game.GolfCourseID);

                return RedirectToAction("Index");
            }

            ViewBag.GolfCourseID = new SelectList(db.GolfCourses, "GolfCourseID", "Name", game.GolfCourseID);

            return View(game);
        }
예제 #2
0
 public ActionResult Edit(Game game)
 {
     if (ModelState.IsValid)
     {
         db.Entry(game).State = EntityState.Modified;
         db.SaveChanges();
     }
     return RedirectToAction("Index");
 }