public async Task <IActionResult> Create(int countryId, [Bind("Id,Name,CreationDate")] Organisation organisation) { organisation.CountryId = countryId; if (ModelState.IsValid) { var c = (from org in _context.Organisations where org.Name.Contains(organisation.Name) select org).ToList(); if (c.Count > 0) { return(RedirectToAction("Index", "Organisations", new { id = countryId, name = _context.Countries.Where(c => c.Id == countryId).FirstOrDefault().Name })); } if (!Valid.Datecheck(organisation.CreationDate)) { return(RedirectToAction("Index", "Organisations", new { id = countryId, name = _context.Countries.Where(c => c.Id == countryId).FirstOrDefault().Name })); } _context.Add(organisation); await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); return(RedirectToAction("Index", "Organisations", new { id = countryId, name = _context.Countries.Where(c => c.Id == countryId).FirstOrDefault().Name })); } // ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "Name", organisation.CountryId); // return View(organisation); return(RedirectToAction("Index", "Organisations", new { id = countryId, name = _context.Countries.Where(c => c.Id == countryId).FirstOrDefault().Name })); }
public async Task <IActionResult> Create([Bind("Id,Name")] Country country) { if (ModelState.IsValid && !_context.Countries.Any(c => c.Name == country.Name)) { _context.Add(country); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(country)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Game game) { if (ModelState.IsValid && !_context.Games.Any(c => c.Name == game.Name)) { _context.Add(game); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(game)); }
public async Task <IActionResult> Create([Bind("Id,OrganisationId,Name,GameId")] Team team) { if (ModelState.IsValid && !_context.Teams.Any(c => c.Name == team.Name && team.GameId == c.GameId)) { _context.Add(team); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["GameId"] = new SelectList(_context.Games, "Id", "Name", team.GameId); ViewData["OrganisationId"] = new SelectList(_context.Organisations, "Id", "Name", team.OrganisationId); return(View(team)); }
public async Task <IActionResult> Create(int organisationId, [Bind("Id,Name")] Department department) { department.OrganisationId = organisationId; if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); return(RedirectToAction("Index", "Departments", new { id = organisationId, name = _context.Organisations.Where(c => c.Id == organisationId).FirstOrDefault().Name })); } // ViewData["OrganisationId"] = new SelectList(_context.Organisations, "Id", "Name", department.OrganisationId); // return View(department); return(RedirectToAction("Index", "Departments", new { id = organisationId, name = _context.Organisations.Where(c => c.Id == organisationId).FirstOrDefault().Name })); }
public async Task <IActionResult> Create([Bind("Id,CountryId,TeamId,Name,Birthdate")] Player player) { if (ModelState.IsValid) { if (!Valid.IsAllLetters(player.Name)) { return(RedirectToAction(nameof(Index))); } _context.Add(player); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "Name", player.CountryId); ViewData["TeamId"] = new SelectList(_context.Teams, "Id", "Name", player.TeamId); return(View(player)); }