예제 #1
0
        public ActionResult Create([Bind(Include="Id,Keyword,MaxScore,Type,JudgeNotes,Published,Collapsible")] Stunt stunt)
        {
            if (ModelState.IsValid)
            {
                // Créer une traduction par défaut et rediriger
                var st = new StuntTranslation();
                stunt.Translations = new Collection<StuntTranslation>() { st };

                db.Stunts.Add(stunt);
                db.SaveChanges();

                // Il faut aussi l'ajouter/assigner aux équipes déjà inscrites
                foreach (var team in db.Teams)
                {
                    var ts = new TeamStunt() { Stunt = stunt, Team = team };
                    db.TeamStunts.Add(ts);
                }

                db.SaveChanges();

                return RedirectToAction("Edit", "StuntTranslation", new { id = st.Id });
            }

            return View(stunt);
        }
예제 #2
0
        public ActionResult DataImport(string data)
        {
            var teams = JsonConvert.DeserializeObject<List<Team>>(data);

            db.Teams.AddRange(teams);
            db.SaveChanges();

            // Create TeamStunts for the teams
            foreach (var team in teams)
            {
                foreach (var stunt in db.Stunts)
                {
                    var ts = new TeamStunt() { Stunt = stunt, Team = team };
                    db.TeamStunts.Add(ts);
                }
            }
            db.SaveChanges();

            return RedirectToAction("IndexAdmin");
        }