コード例 #1
0
        public ActionResult Create(Match match, string teamListHome, string teamListAway)
        {
            var teamHomeId = Convert.ToInt32(teamListHome);
            var teamAwayId = Convert.ToInt32(teamListAway);
            if (ModelState.IsValid)
            {
                using (var context = new FootballManagerDBContext())
                {
                    Team teamHome = context.Teams.Single(d => d.ID == teamHomeId);
                    Team teamAway = context.Teams.Single(d => d.ID == teamAwayId);
                    match.HomeTeamId = teamHomeId;
                    match.AwayTeamId = teamAwayId;
                    match.HomeTeamName = teamHome.Name;
                    match.AwayTeamName = teamAway.Name;
                    context.Matches.Add(match);
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }

            return View(match);
        }
コード例 #2
0
        public ActionResult Edit(Match match)
        {
            if (ModelState.IsValid)
            {
                using (var context = new FootballManagerDBContext())
                {
                    context.Entry(match).State = EntityState.Modified;
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            return View(match);
        }