public JsonResult GetTeamID(FFGame game) { var hID = game.HomeTeamID; return Json(hID, JsonRequestBehavior.AllowGet); }
public ActionResult CreateSchedule(int TeamID) { FFTeam Team = db.FFTeamDB.Find(TeamID); FFLeague League = db.FFLeagueDB.Find(Team.FFLeagueID); //Make filled into numofteams List<int> Listof0oppo = new List<int> { 1, 2, 3, 4, 5, 6, 7 }; List<int> Listof1oppo = new List<int> { 0, 2, 3, 4, 5, 6, 7 }; List<int> Listof2oppo = new List<int> { 0, 1, 3, 4, 5, 6, 7 }; List<int> Listof3oppo = new List<int> { 0, 1, 2, 4, 5, 6, 7 }; List<int> Listof4oppo = new List<int> { 0, 1, 2, 3, 5, 6, 7 }; List<int> Listof5oppo = new List<int> { 0, 1, 2, 3, 4, 6, 7 }; List<int> Listof6oppo = new List<int> { 0, 1, 2, 3, 4, 5, 7 }; List<int> Listof7oppo = new List<int> { 0, 1, 2, 3, 4, 5, 6 }; if ( (League.Schedule.Count() == 0) && (League.NumberOfTeams == League.Teams.Count()) ) { if (Team.DivisionID == 0 || Team.DivisionID == null) { Dictionary<int, List<int>> DictOfOppoList = new Dictionary<int, List<int>>(); Dictionary<int, List<int>> MasterDict = new Dictionary<int, List<int>>(); DictOfOppoList.Add(0, Listof0oppo); DictOfOppoList.Add(1, Listof1oppo); DictOfOppoList.Add(2, Listof2oppo); DictOfOppoList.Add(3, Listof3oppo); DictOfOppoList.Add(4, Listof4oppo); DictOfOppoList.Add(5, Listof5oppo); DictOfOppoList.Add(6, Listof6oppo); DictOfOppoList.Add(7, Listof7oppo); MasterDict = DictOfOppoList.ToDictionary(entry => entry.Key, entry => entry.Value); for (int weekCntr = 1; weekCntr < League.PlayoffWeekStart; ++weekCntr) { if (weekCntr == League.NumberOfTeams) { //Reset when opponents run out Listof0oppo = new List<int> { 1, 2, 3, 4, 5, 6, 7 }; Listof1oppo = new List<int> { 0, 2, 3, 4, 5, 6, 7 }; Listof2oppo = new List<int> { 0, 1, 3, 4, 5, 6, 7 }; Listof3oppo = new List<int> { 0, 1, 2, 4, 5, 6, 7 }; Listof4oppo = new List<int> { 0, 1, 2, 3, 5, 6, 7 }; Listof5oppo = new List<int> { 0, 1, 2, 3, 4, 6, 7 }; Listof6oppo = new List<int> { 0, 1, 2, 3, 4, 5, 7 }; Listof7oppo = new List<int> { 0, 1, 2, 3, 4, 5, 6 }; MasterDict.Clear(); MasterDict.Add(0, Listof0oppo); MasterDict.Add(1, Listof1oppo); MasterDict.Add(2, Listof2oppo); MasterDict.Add(3, Listof3oppo); MasterDict.Add(4, Listof4oppo); MasterDict.Add(5, Listof5oppo); MasterDict.Add(6, Listof6oppo); MasterDict.Add(7, Listof7oppo); } //Reset for next schedule Week List<FFTeam> NoChangeListTeams = League.Teams.ToList(); List<int> WeekCheckList = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7 }; //Refill Running Delete List with current values DictOfOppoList = MasterDict.ToDictionary(entry => entry.Key, entry => entry.Value); while (DictOfOppoList.Count != 0 ) //Only have enough opponents for x(NUMOFTEAM) amount of weeks { var WeekCheckListIterator = 0; //needs to reset on every iteration var oppoList = DictOfOppoList.First().Value; //oppoList is ListofXopponent int FirstTeamKey = DictOfOppoList.First().Key; //The Key is the num of the first team int oppIndex = -1; //jump into while for first result, -1 = nf so do..while, will inf.loop if never found while (oppIndex == -1) { //if not found keep going //Find the Index of the first opponent in the oppoX List, if not found go to next available opponent in weekcheck(opponent)list oppIndex = oppoList.FindIndex(x => x == WeekCheckList[WeekCheckListIterator]); WeekCheckListIterator += 1; } var secondTeamoppoListValue = oppoList[oppIndex]; //Storing value (opponentNum) in var var firstTeam = NoChangeListTeams.ElementAt(FirstTeamKey); var secondTeam = NoChangeListTeams.ElementAt(secondTeamoppoListValue); //FFGame(int pWeek, int pYear, int pHomeTeamID, int pVisTeamID) FFGame Game = new FFGame(weekCntr, FFLeague.YEAR, firstTeam.FFTeamID, secondTeam.FFTeamID); League.Schedule.Add(Game); db.FFGameDB.Add(Game); db.SaveChanges(); //Remove opponents from oppolist in dictionary DictOfOppoList[FirstTeamKey].Remove(secondTeamoppoListValue); DictOfOppoList[secondTeamoppoListValue].Remove(FirstTeamKey); //Need MasterDict to keep the values of the Lists, I have to delete the entries from the main list //Copy removed value list to MasterDict MasterDict[FirstTeamKey] = DictOfOppoList[FirstTeamKey]; MasterDict[secondTeamoppoListValue] = DictOfOppoList[secondTeamoppoListValue]; DictOfOppoList.Remove(FirstTeamKey); //Remove FirstTeam from Dict var removeDict = DictOfOppoList.First(x => x.Key == (secondTeamoppoListValue)); DictOfOppoList.Remove(removeDict.Key); WeekCheckList.Remove(FirstTeamKey);//remove boths values from weekcheecklist WeekCheckList.Remove(secondTeamoppoListValue); } } } } else { string err = "Need correct amount of Teams in League to create schedule or League Schedule has games in it already"; return View(err); } return RedirectToAction("Schedule", new { TeamID = Team.FFTeamID }); }