public ActionResult Create([Bind(Include = "SeasonID,StartDate,EndDate,Champion")] Season season) { if (ModelState.IsValid) { db.Seasons.Add(season); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(season)); }
public ActionResult Create([Bind(Include = "ID,LastName,FirstName,currentTeam,StartDate,EndDate,Position,Secret")] Player player) { try { if (ModelState.IsValid) { db.Players.Add(player); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(player)); }
static void Main(string[] args) { var clubFlag = false; var playersFlag = false; var clearDatabase = false; var clubsPath = ""; var playersPath = ""; CheckArgs(args, ref clubFlag, ref playersFlag, ref clubsPath, ref playersPath, ref clearDatabase); var clubs = new List <Club>(); var players = new List <Player>(); if (clubFlag && !string.IsNullOrWhiteSpace(clubsPath)) { ReadClubs(ref clubs, clubsPath); } if (playersFlag && !string.IsNullOrWhiteSpace(playersPath)) { ReadPlayers(ref players, playersPath, ref clubs); } #region InicializationDB using (var db_context = new HockeyContext()) { if (clearDatabase) { db_context.Database.ExecuteSqlCommand("DELETE FROM Player"); db_context.Database.ExecuteSqlCommand("DELETE FROM Club"); } foreach (var club in clubs) { db_context.Clubs.Add(club); } foreach (var player in players) { db_context.Players.Add(player); } db_context.SaveChanges(); foreach (var club in db_context.GetClubs()) { Console.WriteLine(club); } foreach (var player in db_context.GetPlayers()) { Console.WriteLine(player); } } Console.WriteLine("DB Loaded!"); Console.ReadLine(); #endregion }