public ActionResult AddMatch(int id) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); Set_TempData(username); var dal = new Competition_services(); var dal2 = new Team_services(); var dal3 = new Player_services(); SingleMatchModel match = new SingleMatchModel(); match.HomePoints = 0; match.AwayPoints = 0; match.Match = dal.One_match(id); if (dal3.Check_existing(match.Match.Match_contestants.ElementAt(0).Contestant.ID) != null) { match.HomeContestant = dal3.Check_existing(match.Match.Match_contestants.ElementAt(0).Contestant.ID).Name; match.AwayContestant = dal3.Check_existing(match.Match.Match_contestants.ElementAt(1).Contestant.ID).Name; } else { match.HomeContestant = dal2.Check_existing(match.Match.Match_contestants.ElementAt(0).Contestant.ID).Name; match.AwayContestant = dal2.Check_existing(match.Match.Match_contestants.ElementAt(1).Contestant.ID).Name; } List <Event_list> allEvents = dal.Sport_events(match.Match.League.Sport.ID); match.Events = new List <EventModel>(); foreach (var one in allEvents) { EventModel jedan = new EventModel(); jedan.Name = one.Name; jedan.Counts = one.Counts; jedan.Length = one.Length; jedan.Player1 = one.Player1; jedan.Player2 = one.Player2; jedan.Points1 = one.Points1; jedan.Points2 = one.Points2; jedan.Primary = one.Primary; match.Events.Add(jedan); } match.TeamPlayers = new List <string>(); match.TeamPlayers = dal2.TeamPlayers(match.HomeContestant, match.AwayContestant); return(View(match)); }
public ActionResult Round(int competition, int kolo) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); var dal = new Competition_services(); var dal2 = new Team_services(); var dal3 = new Player_services(); RoundViewModel model = new RoundViewModel(); Competition current = dal.Check_existing(competition); List <Match> matches = dal.RoundMatches(current, kolo); model.matches = new List <SingleMatchModel>(); foreach (var one in matches) { SingleMatchModel match = new SingleMatchModel(); match.HomePoints = dal.HomePoints(one); match.AwayPoints = dal.AwayPoints(one); match.Match = one; if (current.Sport.Sport_type.Type_name.Equals("1v1")) { match.HomeContestant = dal3.Check_existing(one.Match_contestants.ElementAt(0).Contestant.ID).Name; match.AwayContestant = dal3.Check_existing(one.Match_contestants.ElementAt(1).Contestant.ID).Name; } else { match.HomeContestant = dal2.Check_existing(one.Match_contestants.ElementAt(0).Contestant.ID).Name; match.AwayContestant = dal2.Check_existing(one.Match_contestants.ElementAt(1).Contestant.ID).Name; } model.matches.Add(match); } model.Round = kolo; Set_TempData(username); return(View(model)); }
public ActionResult Table(int competition) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); Set_TempData(username); var dal = new Competition_services(); var dal2 = new Team_services(); Competition current = dal.Check_existing(competition); LeagueViewModel model = new LeagueViewModel(); model.Rounds = new List <RoundViewModel>(); model.Standings = new List <Standing>(); model.Competition = current.ID; foreach (var one in current.Competition_contestants) { Standing TeamStanding = new Standing(); TeamStanding.Team = dal2.Check_existing(one.Contestant.ID); model.Standings.Add(TeamStanding); } var i = (current.Competition_contestants.Count() - 1) * 2; if (!current.Type_of_competition.DoubleQuadra) { i *= 2; } for (int j = 1; j < i + 1; j++) { RoundViewModel round = new RoundViewModel(); round.matches = new List <SingleMatchModel>(); List <Match> matches = dal.RoundMatches(current, j); foreach (var one in matches) { SingleMatchModel match = new SingleMatchModel(); match.HomePoints = dal.HomePoints(one); match.AwayPoints = dal.AwayPoints(one); match.Match = one; match.HomeContestant = dal2.Check_existing(one.Match_contestants.ElementAt(0).Contestant.ID).Name; match.AwayContestant = dal2.Check_existing(one.Match_contestants.ElementAt(1).Contestant.ID).Name; if (one.Locked) { model.Standings.FirstOrDefault(m => m.Team.Name == match.HomeContestant).PlayedMatches += 1; model.Standings.FirstOrDefault(m => m.Team.Name == match.HomeContestant).GoalsScored += match.HomePoints; model.Standings.FirstOrDefault(m => m.Team.Name == match.HomeContestant).GoalsConceded += match.AwayPoints; model.Standings.FirstOrDefault(m => m.Team.Name == match.AwayContestant).PlayedMatches += 1; model.Standings.FirstOrDefault(m => m.Team.Name == match.AwayContestant).GoalsScored += match.AwayPoints; model.Standings.FirstOrDefault(m => m.Team.Name == match.AwayContestant).GoalsConceded += match.HomePoints; if (match.HomePoints > match.AwayPoints) { model.Standings.FirstOrDefault(m => m.Team.Name == match.HomeContestant).Wins += 1; model.Standings.FirstOrDefault(m => m.Team.Name == match.HomeContestant).Points += current.Type_of_competition.Victory_points; model.Standings.FirstOrDefault(m => m.Team.Name == match.AwayContestant).Loses += 1; model.Standings.FirstOrDefault(m => m.Team.Name == match.AwayContestant).Points += current.Type_of_competition.Defeat_points; } else if (match.HomePoints < match.AwayPoints) { model.Standings.FirstOrDefault(m => m.Team.Name == match.AwayContestant).Wins += 1; model.Standings.FirstOrDefault(m => m.Team.Name == match.AwayContestant).Points += current.Type_of_competition.Victory_points; model.Standings.FirstOrDefault(m => m.Team.Name == match.HomeContestant).Loses += 1; model.Standings.FirstOrDefault(m => m.Team.Name == match.HomeContestant).Points += current.Type_of_competition.Defeat_points; } else { model.Standings.FirstOrDefault(m => m.Team.Name == match.HomeContestant).Draws += 1; model.Standings.FirstOrDefault(m => m.Team.Name == match.HomeContestant).Points += current.Type_of_competition.Tie_points; model.Standings.FirstOrDefault(m => m.Team.Name == match.AwayContestant).Draws += 1; model.Standings.FirstOrDefault(m => m.Team.Name == match.AwayContestant).Points += current.Type_of_competition.Tie_points; } } round.matches.Add(match); } round.Round = j; model.Rounds.Add(round); } model.Standings = model.Standings.OrderByDescending(m => m.Points).ToList(); return(View(model)); }