public async Task <IActionResult> Create([Bind("PlayerId,FullName")] Player player) { if (ModelState.IsValid) { _context.Add(player); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(player)); }
public async Task <IActionResult> Create([Bind("CityId,Name")] City city) { if (ModelState.IsValid) { _context.Add(city); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(city)); }
public async Task <IActionResult> Create([Bind("TeamId,Name,CityId")] Team team) { if (ModelState.IsValid) { _context.Add(team); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(_context.Cities, "CityId", "Name", team.CityId); return(View(team)); }
public async Task <IActionResult> Create(int CityId, [Bind("StadiumId,Name,CityId")] Stadium stadium) { stadium.CityId = CityId; if (ModelState.IsValid) { _context.Add(stadium); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Stadia", new { id = CityId, name = _context.Cities.Where(c => c.CityId == CityId).FirstOrDefault().Name })); } return(RedirectToAction("Index", "Stadia", new { id = CityId, name = _context.Cities.Where(c => c.CityId == CityId).FirstOrDefault().Name })); }
public async Task <IActionResult> Create([Bind("RefereeId,FullName,BirthDate")] Referee referee) { if (referee.BirthDate < new DateTime(1950, 12, 1)) { ModelState.AddModelError("BirthDate", "Дата народження повина бути більша за 01.12.1950"); } if (ModelState.IsValid) { _context.Add(referee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(referee)); }
public async Task <IActionResult> Create([Bind("TournamentId,Name,Prize,StartDate,EndDate,Info")] Tournament tournament) { if (tournament.StartDate > tournament.EndDate) { ModelState.AddModelError("StartDate", "Невірний часовий проміжок"); } if (tournament.Prize > 1000000000 || tournament.Prize < 0) { ModelState.AddModelError("Prize", "Сума повинна бути менше одного мільярда, і більше нуля"); } if (ModelState.IsValid) { _context.Add(tournament); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tournament)); }
public async Task <IActionResult> Create(int playerId, [Bind("CareerId,TeamId,PlayerId,StartDate,EndDate,PositionId")] Career career) { career.PlayerId = playerId; if (career.EndDate != null && career.StartDate > career.EndDate) { ModelState.AddModelError("StartDate", "Невірний часовий проміжок"); } if (ModelState.IsValid) { _context.Add(career); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(RedirectToAction("Index", "Careers", new { id = playerId, name = _context.Players.Where(c => c.PlayerId == playerId).FirstOrDefault().FullName })); } //ViewData["PlayerId"] = new SelectList(_context.Players, "PlayerId", "FullName", career.PlayerId); //ViewData["PositionId"] = new SelectList(_context.Positions, "PositionId", "Name", career.PositionId); //ViewData["TeamId"] = new SelectList(_context.Teams, "TeamId", "Name", career.TeamId); //return View(career); return(RedirectToAction("Index", "Careers", new { id = playerId, name = _context.Players.Where(a => a.PlayerId == playerId).FirstOrDefault().FullName })); }
public async Task <IActionResult> Create([Bind("GameId,StartTime,StadiumId,TournamentId,TeamId,TeamId2,RefereeId")] Game game) { if (game.TeamId == game.TeamId2) { ModelState.AddModelError("TeamId", "Помилкова пара команд"); } if (game.StartTime < new DateTime(1970, 12, 1)) { ModelState.AddModelError("StartTime", "Час доступний 1970 р.н.е. і далі"); } if (ModelState.IsValid) { _context.Add(game); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RefereeId"] = new SelectList(_context.Referees, "RefereeId", "FullName", game.RefereeId); ViewData["StadiumId"] = new SelectList(_context.Stadiums, "StadiumId", "Name", game.StadiumId); ViewData["TeamId"] = new SelectList(_context.Teams, "TeamId", "Name", game.TeamId); ViewData["TeamId2"] = new SelectList(_context.Teams, "TeamId", "Name", game.TeamId2); ViewData["TournamentId"] = new SelectList(_context.Tournaments, "TournamentId", "Name", game.TournamentId); return(View(game)); }