public async Task <IActionResult> Create([Bind("Id,Name,Info")] Game game) { int counter = 0; foreach (var g in _context.Game) { if (g.Name == game.Name) { counter++; break; } } if (counter != 0) { ModelState.AddModelError("Name", "Таке ім'я вже існує"); return(View(game)); } else { if (ModelState.IsValid) { _context.Add(game); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(game)); } }
public async Task <IActionResult> Create([Bind("Id,Name,SponsorId,Location,PrizeFund")] Tournament tournament) { if (ModelState.IsValid) { _context.Add(tournament); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SponsorId"] = new SelectList(_context.Sponsor, "Id", "Name", tournament.SponsorId); return(View(tournament)); }
public async Task <IActionResult> Create(int gameId, string gameName, [Bind("Id,TournametId")] TournamentGames tournamentGames) { if (gameName == null) { return(RedirectToAction("Home", "Index")); } TournamentGames tg = new TournamentGames(); tg.GameId = gameId; tournamentGames.GameId = gameId; tg.TournametId = tournamentGames.TournametId; if (ModelState.IsValid) { _context.Add(tg); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { id = gameId, name = gameName })); } return(RedirectToAction("Index", new { id = gameId, name = gameName })); }
public async Task <IActionResult> Create(int teamId, int gameId, string gameName, [Bind("Id,Name,Position,Info,EntranceDate")] Player player) { if (player.EntranceDate > DateTime.Now) { ModelState.AddModelError("EntranceDate", "jhbfdjnhghnj"); return(View(player)); } else { if (gameName == null) { return(RedirectToAction("Index", "Home")); } player.TeamId = teamId; if (ModelState.IsValid) { _context.Add(player); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Players", new { id = teamId, gameId, gameName })); } return(RedirectToAction("Index", "Players", new { id = teamId, gameId, gameName })); } }