public async Task <IActionResult> PutSportLeague(int id, SportLeague sportLeague) { if (id != sportLeague.Id) { return(BadRequest()); } _context.Entry(sportLeague).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SportLeagueExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(string id, [Bind("SportTypeName,ShortName,LongName,Description")] SportLeague sportLeague) { if (id != sportLeague.ShortName) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(sportLeague); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SportLeagueExists(sportLeague.ShortName)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["SportTypeName"] = new SelectList(_context.SportType, "Name", "Name", sportLeague.SportTypeName); return(View(sportLeague)); }
private bool validateSportLeague(SportLeague sl) { if (sl.Name == string.Empty) { return(false); } return(true); }
public async Task <IActionResult> Create([Bind("SportTypeName,ShortName,LongName,Description")] SportLeague sportLeague) { if (ModelState.IsValid) { _context.Add(sportLeague); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SportTypeName"] = new SelectList(_context.SportType, "Name", "Name", sportLeague.SportTypeName); return(View(sportLeague)); }
public async Task <ActionResult <SportLeague> > PostSportLeague(SportLeague sportLeague) { if (validateSportLeague(sportLeague)) { _context.SportLeagues.Add(sportLeague); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSportLeague", new { id = sportLeague.Id }, sportLeague)); } else { return(new BadRequestObjectResult("Sport League Name is Required")); } }
private static Conference AddConference(SportLeague league, string Name, bool isActive) { Conference conference; if (!league.Conferences.Exists(c => c.Name == Name)) { conference = new Conference { Name = Name, isActive = isActive, Divisions = new List <Division>() }; league.Conferences.Add(conference); } else { conference = league.Conferences.First(c => c.Name == Name); conference.Name = Name; conference.isActive = isActive; } return(conference); }
private static SportLeague AddSportLeague(string Name, bool isEnabled) { var league = GetLeagueByName(Name); if (league == null) { league = new SportLeague { Name = Name, isEnabled = isEnabled, Conferences = new List <Conference>() }; } else { league.Name = Name; league.isEnabled = isEnabled; } var conf = AddConference(league, "AFC", true); var div1 = AddDivision(conf, "North", true); AddTeam(div1, "Baltimore", "Ravens", true); AddTeam(div1, "Pittsburgh", "Steelers", true); AddTeam(div1, "Cleveland", "Browns", true); AddTeam(div1, "Cincinnati", "Bengals", true); var div2 = AddDivision(conf, "South", true); AddTeam(div2, "Houston", "Texans", true); AddTeam(div2, "Tennessee", "Titans", true); AddTeam(div2, "Indianapolis", "Colts", true); AddTeam(div2, "Jacksonville", "Jaguars", true); var div3 = AddDivision(conf, "East", true); AddTeam(div3, "New England", "Patriots", true); AddTeam(div3, "Buffalo", "Bills", true); AddTeam(div3, "New York", "Jets", true); AddTeam(div3, "Miami", "Dolphins", true); var div4 = AddDivision(conf, "West", true); AddTeam(div4, "Baltimore", "Chiefs", true); AddTeam(div4, "Baltimore", "Broncos", true); AddTeam(div4, "Los Vegas", "Raiders", true); AddTeam(div4, "Los Angeles", "Chargers", true); Conference conf2 = AddConference(league, "NFC", true); var div5 = AddDivision(conf2, "North", true); AddTeam(div5, "Chicago", "Bears", true); AddTeam(div5, "Green Bay", "Packers", true); AddTeam(div5, "Detroit", "Lions", true); AddTeam(div5, "Minnesota", "Vikings", true); var div6 = AddDivision(conf2, "South", true); AddTeam(div6, "New Orleans", "Saints", true); AddTeam(div6, "Atlanta", "Falcons", true); AddTeam(div6, "Tampa Bay", "Buccaneers", true); AddTeam(div6, "Carolina", "Panthers", true); var div7 = AddDivision(conf2, "East", true); AddTeam(div7, "Philadelphia", "Eagles", true); AddTeam(div7, "Dallas", "Cowboys", true); AddTeam(div7, "Washington", "Redskins", true); AddTeam(div7, "New York", "Giants", true); var div8 = AddDivision(conf2, "West", true); AddTeam(div8, "San Francisco", "49ers", true); AddTeam(div8, "Seattle", "Seahawks", true); AddTeam(div8, "Los Angeles", "Rams", true); AddTeam(div8, "Arizona", "Cardinals", true); _context.Attach(league); _context.SaveChanges(); return(league); }