public async Task <IActionResult> Edit(int id, [Bind("CST_ID,CST_NAME,CST_CREDIT,CST_SEX")] Casters casters) { if (id != casters.CST_ID) { return(NotFound()); } if (ModelState.IsValid && (casters.CST_SEX == "M" || casters.CST_SEX == "F")) { try { _context.Update(casters); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CastersExists(casters.CST_ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } else { ModelState.AddModelError("", "Something went wrong, check your input data"); } return(View(casters)); }
public static T Cast <TFrom>(TFrom obj) { #if (DEBUG) try { return(Casters <TFrom> .Caster(obj)); } catch (InvalidCastException e) { throw new InvalidCastException(string.Format("Specified cast is not valid: {0} -> {1}", typeof(TFrom), typeof(T)), e); } #else return(Casters <TFrom> .Caster(obj)); #endif }
public async Task <IActionResult> Create([Bind("CST_NAME,CST_CREDIT,CST_SEX")] Casters casters) { try { if (ModelState.IsValid && (casters.CST_SEX == "M" || casters.CST_SEX == "F")) { _context.Add(casters); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ModelState.AddModelError("", "Something went wrong, check your input data"); } catch { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "you are done. Bye-bye"); } return(View(casters)); }
public static T Cast <TFrom>(TFrom obj) { return(Casters <TFrom> .Caster(obj)); }
public static void Initialize(FederationContext context) { context.Database.EnsureCreated(); if (context.Players.Any()) { return; } var players = new Players[] { new Players { PL_NAME = "Magnus Carlsen", PL_RATING = 2842, PL_SEX = "M" }, new Players { PL_NAME = "Fabiano Caruana", PL_RATING = 2831, PL_SEX = "M" }, new Players { PL_NAME = "Judit Polgar", PL_RATING = 2630, PL_SEX = "F" }, new Players { PL_NAME = "Jio Huan", PL_RATING = 2672, PL_SEX = "F" }, new Players { PL_NAME = "Artem Denisenko", PL_RATING = 2084, PL_SEX = "M" }, new Players { PL_NAME = "This Old Dude", PL_RATING = 1712, PL_SEX = "M" }, new Players { PL_NAME = "Hikaru Nakamura", PL_RATING = 2802, PL_SEX = "M" }, new Players { PL_NAME = "Robert Hess", PL_RATING = 2611, PL_SEX = "M" } }; foreach (Players p in players) { context.Players.Add(p); } context.SaveChanges(); var tourneys = new Tournaments[] { new Tournaments { TR_NAME = "World Championship 2018", TR_PRIZEPOOL = 10000000, TR_DATE_BEG = new DateTime(2018, 12, 1), TR_DATE_END = new DateTime(2018, 12, 15) }, new Tournaments { TR_NAME = "Tata Steel Chess", TR_PRIZEPOOL = 3000000, TR_DATE_BEG = new DateTime(2019, 1, 8), TR_DATE_END = new DateTime(2019, 1, 23) }, new Tournaments { TR_NAME = "Chicago Major", TR_PRIZEPOOL = 1000000, TR_DATE_BEG = new DateTime(2018, 10, 12), TR_DATE_END = new DateTime(2018, 11, 3) }, new Tournaments { TR_NAME = "Casters Battle", TR_PRIZEPOOL = 42000, TR_DATE_BEG = new DateTime(2018, 8, 3), TR_DATE_END = new DateTime(2018, 3, 17) }, new Tournaments { TR_NAME = "Blitz World Championship 2018", TR_PRIZEPOOL = 1500000, TR_DATE_BEG = new DateTime(2018, 7, 3), TR_DATE_END = new DateTime(2018, 7, 10) } }; foreach (Tournaments t in tourneys) { context.Tournaments.Add(t); } context.SaveChanges(); var games = new Games[] { new Games { GM_NOTATION = "nocontext1" }, new Games { GM_NOTATION = "nocontext2" }, new Games { GM_NOTATION = "nocontext3" }, new Games { GM_NOTATION = "nocontext4" }, new Games { GM_NOTATION = "nocontext5" }, new Games { GM_NOTATION = "nocontext6" }, new Games { GM_NOTATION = "nocontext7" }, new Games { GM_NOTATION = "nocontext8" }, new Games { GM_NOTATION = "nocontext9" }, new Games { GM_NOTATION = "nocontext10" }, new Games { GM_NOTATION = "nocontext11" }, new Games { GM_NOTATION = "nocontext12" } }; foreach (Games g in games) { context.Games.Add(g); } context.SaveChanges(); var titles = new Titles[] { new Titles { TTL_NAME = "World Champion" }, new Titles { TTL_NAME = "Female World Champion" }, new Titles { TTL_NAME = "Blitz World Champion" }, new Titles { TTL_NAME = "Nobody" } }; foreach (Titles t in titles) { context.Titles.Add(t); } context.SaveChanges(); var casters = new Casters[] { new Casters { CST_NAME = "Robert Hess", CST_CREDIT = 96, CST_SEX = "M" }, new Casters { CST_NAME = "Daniel Melon", CST_CREDIT = 99, CST_SEX = "M" }, new Casters { CST_NAME = "Anna Melon", CST_CREDIT = 88, CST_SEX = "F" }, new Casters { CST_NAME = "Judit Polgar", CST_CREDIT = 44, CST_SEX = "F" }, }; foreach (Casters c in casters) { context.Casters.Add(c); } context.SaveChanges(); var holders = new TitleHolders[] { new TitleHolders { titleID = 1, playerID = 1 }, new TitleHolders { titleID = 2, playerID = 4 }, new TitleHolders { titleID = 3, playerID = 7 }, new TitleHolders { titleID = 4, playerID = 5 } }; foreach (TitleHolders th in holders) { context.TitleHolders.Add(th); } context.SaveChanges(); }