public ActionResult Index(int?Id)
        {
            Id = Convert.ToInt32(TeamsRep.GetAllTeams().OrderBy(t => t.Id));

            var myplayers = PlayersRep.GetAllPlayers().Where(p => p.TeamId == Id);

            if (myplayers.Count() > 0)
            {
                ViewData["MyPlayers"] = myplayers.OrderBy(p => p.Team.Players);
            }
            return(View());
        }
Beispiel #2
0
        public ActionResult View(int Id)
        {
            TeamsRepository teamsrep = new TeamsRepository();
            var             allteams = teamsrep.GetAllTeams().Where(k => k.Id != Id).OrderBy(k => k.TeamName);



            if (allteams.Count() > 0)
            {
                ViewData["AllTeams"] = allteams;
            }
            var team = teamsrep.GetAllTeams().Where(k => k.Id == Id).FirstOrDefault();

            if (team != null)
            {
                MatchReportRepository matchreportrep = new MatchReportRepository();

                var allreports = matchreportrep.GetAllReports().Where(k => k.Match.HomeTeamId == Id || k.Match.AwayTeamId == Id).OrderByDescending(k => k.Match.Timestamp);


                if (Request.QueryString["opponent"] != null)
                {
                    var opponent = allteams.Where(k => k.Id.ToString() == Request.QueryString["opponent"].ToString()).FirstOrDefault();
                    if (opponent != null)
                    {
                        ViewData["OpponentTeamName"] = opponent.TeamName;
                        allreports = allreports.Where(k => k.Match.HomeTeamId == opponent.Id || k.Match.AwayTeamId == opponent.Id).OrderByDescending(k => k.Match.Timestamp);
                    }
                }


                var allhomegames = allreports.Where(k => k.Match.HomeTeamId == Id);
                var allawaygames = allreports.Where(k => k.Match.AwayTeamId == Id);

                if (allhomegames.Count() > 0)
                {
                    ViewData["HomeGames"] = allhomegames;
                }

                if (allawaygames.Count() > 0)
                {
                    ViewData["AwayGames"] = allawaygames;
                }


                return(View(team));
            }
            else
            {
                return(Redirect("/"));
            }
        }
        public ActionResult View(int Id)
        {
            TeamsRepository TeamsRep = new TeamsRepository();
            var             allteams = TeamsRep.GetAllTeams().Where(t => t.Id != Id).OrderBy(t => t.Name);


            if (allteams.Count() > 0)
            {
                ViewData["AllTeams"] = allteams;
            }

            var myteam = TeamsRep.GetAllTeams().Where(t => t.Id == Id).FirstOrDefault();

            if (myteam != null)
            {
                PlayersRepository playerrep = new PlayersRepository();
                ReportsRepository ReportRep = new ReportsRepository();
                var allreports = ReportRep.GetAllReports().Where(r => r.Match.Fixture.HomeTeamId == Id || r.Match.Fixture.AwayTeamId == Id).OrderByDescending(r => r.Match.Fixture.TimeStamp);



                if (Request.QueryString["opponent"] != null)
                {
                    var opponent = allteams.Where(t => t.Id.ToString() == Request.QueryString["opponent"].ToString()).FirstOrDefault();
                    if (opponent != null)
                    {
                        ViewData["OpponentTeamName"] = opponent.Name;
                        allreports = allreports.Where(k => k.Match.Fixture.HomeTeamId == opponent.Id || k.Match.Fixture.AwayTeamId == opponent.Id).OrderByDescending(k => k.Match.Fixture.TimeStamp);
                        ///return
                    }
                }

                var allhomegames = allreports.Where(h => h.Match.Fixture.HomeTeamId == Id);
                var allawaygames = allreports.Where(h => h.Match.Fixture.AwayTeamId == Id);

                if (allhomegames.Count() > 0)
                {
                    ViewData["HomeGames"] = allhomegames;
                }

                if (allawaygames.Count() > 0)
                {
                    ViewData["AwayGames"] = allawaygames;
                }
                return(View(myteam));
            }
            else
            {
                return(Redirect("/"));
            }
        }
Beispiel #4
0
        public ActionResult Add(Team team)
        {
            if (!String.IsNullOrWhiteSpace(team.TeamName))
            {
                TeamsRepository teamsrep = new TeamsRepository();

                if (teamsrep.GetAllTeams().Where(k => k.TeamName.ToLower() == team.TeamName.ToLower()).Count() > 0)
                {
                    ModelState.AddModelError("TeamName", "That team name is already in use");
                }
                else
                {
                    teamsrep.Add(team);
                    teamsrep.SaveChanges();

                    return(Redirect("/teams"));
                }
            }
            else
            {
                ModelState.AddModelError("TeamName", "Please enter a team name");
            }

            return(View(team));
        }
        public ActionResult Edit(int?id)
        {
            //var tm = db.Teams.Where(t => t.TeamId == id).FirstOrDefault
            TeamsRepository TeamsRep = new TeamsRepository();
            var             myteams  = TeamsRep.GetAllTeams().SingleOrDefault(t => t.Id == id);


            return(View(myteams));
        }
Beispiel #6
0
        public ActionResult Add(Match match)
        {
            List <SelectListItem> teamlist = new List <SelectListItem>();
            TeamsRepository       teamsrep = new TeamsRepository();
            var myteams = teamsrep.GetAllTeams().OrderBy(k => k.TeamName);

            if (myteams.Count() > 0)
            {
                foreach (Team t in myteams)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = t.Id.ToString();
                    sli.Text  = t.TeamName;
                    teamlist.Add(sli);
                }
            }
            ViewData["Teams"] = teamlist;


            if (match.HomeGoals != null)
            {
                if (match.AwayGoals != null)
                {
                    if (match.Timestamp != null)
                    {
                        if (match.HomeTeamId != match.AwayTeamId)
                        {
                            MatchesRepository matchesrep = new MatchesRepository();
                            matchesrep.Add(match);
                            matchesrep.SaveChanges();

                            return(Redirect("/matches"));
                        }
                        else
                        {
                            ModelState.AddModelError("HomeTeamId", "Please make sure that the teams are different for home and away sides");
                            ModelState.AddModelError("AwayTeamId", "Please make sure that the teams are different for home and away sides");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("Timestamp", "Please make sure you've entered a valid date for this match");
                    }
                }
                else
                {
                    ModelState.AddModelError("AwayGoals", "Please make sure you've entered the number of goals that the away team scored");
                }
            }
            else
            {
                ModelState.AddModelError("HomeGoals", "Please make sure you've entered the number of goals that the home team scored");
            }
            return(View());
        }
        public ActionResult All()
        {
            TeamsRepository teamsrep = new TeamsRepository();
            var             myteams  = teamsrep.GetAllTeams();

            if (myteams.Count() > 0)
            {
                ViewData["MyTeams"] = myteams.OrderBy(t => t.Name);
            }
            return(View());
        }
        public ActionResult Add(Team team)
        {
            List <SelectListItem> venuelist = new List <SelectListItem>();
            VenuesRepository      VenuesRep = new VenuesRepository();
            var             myvenues        = VenuesRep.GetAllVenues().OrderBy(k => k.Name);
            TeamsRepository teamsrep        = new TeamsRepository();

            //---  string fileName = Path.GetFileNameWithoutExtension(team.ImageUpload.FileName);
            // string extension = Path.GetExtension(team.ImageUpload.FileName);
            //fileName = fileName + DateTime.Now.ToString("yymmssff") + extension;
            // team.LogoUrl = "~/Content/images/" + fileName;
            // fileName = Path.Combine(Server.MapPath("~/Content/images/"), fileName);
            // team.ImageUpload.SaveAs(fileName);


            if (myvenues.Count() > 0)
            {
                foreach (Venue v in myvenues)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = v.Id.ToString();
                    sli.Text  = v.Name;
                    venuelist.Add(sli);
                }
            }

            ViewData["Venues"] = venuelist;


            if (!String.IsNullOrWhiteSpace(team.Name))
            {
                if (teamsrep.GetAllTeams().Where(k => k.Name.ToLower() == team.Name.ToLower()).Count() > 0)
                {
                    ModelState.AddModelError("Name", "That team name is already in use");
                }
                else
                {
                    teamsrep.Add(team);
                    teamsrep.SaveChanges();

                    return(Redirect("/teams"));
                }
            }
            else
            {
                //No team entered
                ModelState.AddModelError("Name", "Please enter team name");
            }
            return(View(team));
        }
        public ActionResult All()

        {
            //new instance of data access layer
            TeamsRepository teamsrep = new TeamsRepository();

            var myTeams = teamsrep.GetAllTeams();

            if (myTeams.Count() > 0)
            {
                ViewData["Teams"] = myTeams.OrderBy(x => x.TeamName);
                //viewdata like a tag which contains all the information and put into view
            }

            return(View());
        }
Beispiel #10
0
        public ActionResult Add()
        {
            List <SelectListItem> teamlist = new List <SelectListItem>();
            TeamsRepository       teamsrep = new TeamsRepository();
            var myteams = teamsrep.GetAllTeams().OrderBy(k => k.TeamName);

            if (myteams.Count() > 0)
            {
                foreach (Team t in myteams)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = t.Id.ToString();
                    sli.Text  = t.TeamName;
                    teamlist.Add(sli);
                }
            }
            ViewData["Teams"] = teamlist;

            return(View());
        }
Beispiel #11
0
        public ActionResult Edit(Match match)
        {
            List <SelectListItem> teamlist = new List <SelectListItem>();
            TeamsRepository       teamsrep = new TeamsRepository();
            var myTeams = teamsrep.GetAllTeams().OrderBy(k => k.TeamName);

            if (myTeams.Count() > 0)
            {
                foreach (Team t in myTeams)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = t.Id.ToString();
                    sli.Text  = t.TeamName;
                    teamlist.Add(sli);
                }
                ViewData["Teams"] = teamlist;
                //duplicating the dropdownlist if we make errors....


                if (match.HomeTeamId == match.AwayTeamId)
                {
                    ModelState.AddModelError("HomeTeamId", "Please select different teams");
                    //ModelState.AddModelError("HomeTeamId", "Please select different teams");
                }

                else if (ModelState.IsValid)
                {
                    Match model = db.Matches.Where(w => w.Id == match.Id).FirstOrDefault();
                    model.HomeTeamId = match.HomeTeamId;
                    model.AwayTeamId = match.AwayTeamId;
                    model.HomeGoals  = match.HomeGoals;
                    model.AwayGoals  = match.AwayGoals;
                    model.TimeStamp  = match.TimeStamp;
                    db.SubmitChanges();

                    return(RedirectToAction("Index"));
                }
            }

            return(View(match));
        }
        public ActionResult Edit(Team team)
        {
            if (!String.IsNullOrWhiteSpace(team.TeamName))
            {
                TeamsRepository teamsrep = new TeamsRepository();

                if (teamsrep.GetAllTeams().Where(k => k.TeamName.ToLower() == team.TeamName.ToLower()).Count() > 0)
                {
                    //team name is already in use
                    ModelState.AddModelError("TeamName", "that team is already in use");
                }
                else
                {
                    Team model = db.Teams.Where(w => w.Id == team.Id).FirstOrDefault();
                    model.TeamName = team.TeamName;
                    db.SubmitChanges();
                    return(RedirectToAction("Index"));
                }
            }
            return(View(team));
        }
Beispiel #13
0
        public ActionResult Add(Match match)
        {
            List <SelectListItem> teamlist = new List <SelectListItem>();
            TeamsRepository       teamsrep = new TeamsRepository();
            var myTeams = teamsrep.GetAllTeams().OrderBy(k => k.TeamName);

            if (myTeams.Count() > 0)
            {
                foreach (Team t in myTeams)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = t.Id.ToString();
                    sli.Text  = t.TeamName;
                    teamlist.Add(sli);
                }
                ViewData["Teams"] = teamlist;
                //duplicating the dropdownlist if we make errors....


                if (match.HomeTeamId == match.AwayTeamId)
                {
                    ModelState.AddModelError("HomeTeamId", "Please select different teams");
                    //ModelState.AddModelError("HomeTeamId", "Please select different teams");
                }

                else if (ModelState.IsValid)
                {
                    MatchesRepository matchesrep = new MatchesRepository();
                    {
                        matchesrep.Add(match);
                        matchesrep.SaveChanges();

                        return(RedirectToAction("Index"));
                    }
                }
            }

            return(View(match));
        }
Beispiel #14
0
        public ActionResult Edit(int?Id)
        {
            List <SelectListItem> teamlist = new List <SelectListItem>();
            TeamsRepository       teamsrep = new TeamsRepository();
            var myTeams = teamsrep.GetAllTeams().OrderBy(k => k.TeamName);

            if (myTeams.Count() > 0)
            {
                foreach (Team t in myTeams)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = t.Id.ToString();
                    sli.Text  = t.TeamName;
                    teamlist.Add(sli);
                }
                ViewData["Teams"] = teamlist;
            }
            //TeamsRepository teamsrep = new TeamsRepository();
            //Team team = teamsrep.GetTeam(Id);
            Match model = db.Matches.Where(w => w.Id == Id).FirstOrDefault();

            return(View(model));
        }
Beispiel #15
0
        public ActionResult Add()
        {
            List <SelectListItem> teamlist = new List <SelectListItem>();
            TeamsRepository       TeamsRep = new TeamsRepository();
            var myteams = TeamsRep.GetAllTeams().OrderBy(k => k.Name);

            if (myteams.Count() > 0)
            {
                foreach (Team t in myteams)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = t.Id.ToString();
                    sli.Text  = t.Name;
                    teamlist.Add(sli);
                }
            }

            ViewData["Teams"] = teamlist;

            List <SelectListItem> venuelist = new List <SelectListItem>();
            VenuesRepository      VenuesRep = new VenuesRepository();
            var myvenues = VenuesRep.GetAllVenues().OrderBy(k => k.Name);

            if (myvenues.Count() > 0)
            {
                foreach (Venue v in myvenues)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = v.Id.ToString();
                    sli.Text  = v.Name;
                    venuelist.Add(sli);
                }
            }

            ViewData["Venues"] = venuelist;
            return(View());
        }
Beispiel #16
0
        public ActionResult Add(Fixture fixture)
        {
            List <SelectListItem> teamlist = new List <SelectListItem>();
            TeamsRepository       TeamsRep = new TeamsRepository();
            var myteams = TeamsRep.GetAllTeams().OrderBy(k => k.Name);

            if (myteams.Count() > 0)
            {
                foreach (Team t in myteams)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = t.Id.ToString();
                    sli.Text  = t.Name;
                    teamlist.Add(sli);
                }
            }

            ViewData["Teams"] = teamlist;

            List <SelectListItem> venuelist = new List <SelectListItem>();
            VenuesRepository      VenuesRep = new VenuesRepository();
            var myvenues = VenuesRep.GetAllVenues().OrderBy(k => k.Name);

            if (myvenues.Count() > 0)
            {
                foreach (Venue v in myvenues)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = v.Id.ToString();
                    sli.Text  = v.Name;
                    venuelist.Add(sli);
                }
            }

            ViewData["Venues"] = venuelist;

            FixturesRepository FixturesRep = new FixturesRepository();

            if (fixture.TimeStamp > DateTime.Today)
            {
                if (fixture.TimeStamp != null)
                {
                    if (fixture.HomeTeamId != fixture.AwayTeamId)
                    {
                        //if (teamsrep.GetAllTeams().Where(k => k.Name.ToLower() == team.Name.ToLower()).Count() > 0)
                        if (FixturesRep.GetAllFixtures().Any(k => k.TimeStamp == fixture.TimeStamp && FixturesRep.GetAllFixtures().Any(s => s.VenueName == fixture.VenueName)))
                        {
                            ModelState.AddModelError("TimeStamp", "There is a match in this venue at this time, add valid fixture");
                            //FixturesRep.Add(fixture);
                            //FixturesRep.SaveChanges();
                            //return Redirect("/fixtures");
                        }
                        else
                        {
                            //ModelState.AddModelError("VenuedId", "There is a match at this venue at this time, add valid fixture");
                            FixturesRep.Add(fixture);
                            FixturesRep.SaveChanges();

                            return(Redirect("/fixtures"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("HomeTeamId", "Please make sure that the teams are different for home and away sides");
                        ModelState.AddModelError("AwayTeamId", "Please make sure that the teams are different for home and away sides");
                    }
                }
                else
                {
                    ModelState.AddModelError("TimeStamp", "Invalid date e.g. 20 November 2019");
                }
            }
            else
            {
                ModelState.AddModelError("TimeStamp", "You can't add fixtures on the past, Enter a future date");
            }
            return(View(fixture));
        }
Beispiel #17
0
        // GET: Tables
        public ActionResult Index()
        {
            List <LeagueTableResults> results    = new List <LeagueTableResults>();
            MatchesRepository         matchesrep = new MatchesRepository();
            var allmatches = matchesrep.GetAllMatches();

            TeamsRepository teamsrep = new TeamsRepository();

            var allteams = teamsrep.GetAllTeams();

            if (allteams.Count() > 0)
            {
                foreach (Team t in allteams)
                {
                    LeagueTableResults res = new LeagueTableResults();
                    res.TeamId   = t.Id;
                    res.TeamName = t.Name;

                    //Calculate number of wins

                    int wins  = 0;
                    int lost  = 0;
                    int draws = 0;

                    int fgoals = 0;
                    int agoals = 0;

                    int points = 0;


                    var allteammatches     = allmatches.Where(m => m.Fixture.HomeTeamId == t.Id || m.Fixture.AwayTeamId == t.Id);
                    var allteamhomematches = allteammatches.Where(m => m.Fixture.HomeTeamId == t.Id);
                    var allteamawaymatches = allteammatches.Where(m => m.Fixture.AwayTeamId == t.Id);
                    var noplayed           = 0;
                    noplayed = allmatches.Where(m => m.Fixture.HomeTeamId == t.Id || m.Fixture.AwayTeamId == t.Id).Count();
                    foreach (Match m in allteamhomematches)
                    {
                        if (m.HomeTeamGoals > m.AwayTeamGoals)
                        {
                            wins++;
                            points = points + 3;
                        }

                        if (m.HomeTeamGoals < m.AwayTeamGoals)
                        {
                            lost++;
                            points = points + 0;
                        }
                        if (m.HomeTeamGoals == m.AwayTeamGoals)
                        {
                            draws++;
                            points = points + 1;
                        }

                        fgoals += (int)m.HomeTeamGoals;
                        agoals += (int)m.AwayTeamGoals;
                    }

                    foreach (Match m in allteamawaymatches)
                    {
                        if (m.AwayTeamGoals > m.HomeTeamGoals)
                        {
                            wins++;
                            points = points + 3;
                        }
                        if (m.AwayTeamGoals < m.HomeTeamGoals)
                        {
                            lost++;
                            points = points + 0;
                        }
                        if (m.AwayTeamGoals == m.HomeTeamGoals)
                        {
                            draws++;
                            points = points + 1;
                        }

                        fgoals += (int)m.AwayTeamGoals;
                        agoals += (int)m.HomeTeamGoals;
                    }
                    res.Win    = wins;
                    res.Lost   = lost;
                    res.Draw   = draws;
                    res.GF     = fgoals;
                    res.GA     = agoals;
                    res.GD     = fgoals - agoals;
                    res.Points = points;
                    res.Played = noplayed;

                    results.Add(res);
                }
            }

            ViewData["Results"] = results.OrderByDescending(r => r.Points).ThenByDescending(r => r.GD);
            return(View());
        }
Beispiel #18
0
        // GET: Tables
        public ActionResult Index()

        {
            List <LeagueTableResult> results    = new List <LeagueTableResult>();
            MatchesRepository        matchesrep = new MatchesRepository();
            TeamsRepository          teamsrep   = new TeamsRepository();

            var allteams   = teamsrep.GetAllTeams();
            var allmatches = matchesrep.GetAllMatches();

            if (allteams.Count() > 0)
            {
                foreach (Team t in allteams)
                {
                    LeagueTableResult res = new LeagueTableResult();
                    res.TeamId   = t.Id;
                    res.TeamName = t.TeamName;

                    //calc number of wins for team
                    int wins         = 0;
                    int losses       = 0;
                    int draws        = 0;
                    int goalsfor     = 0;
                    int goalsagainst = 0;
                    int points       = 0;

                    var allteammatches     = allmatches.Where(l => l.HomeTeamId == t.Id || l.AwayTeamId == t.Id);
                    var allteamhomematches = allteammatches.Where(l => l.HomeTeamId == t.Id);
                    var allteamawaymatches = allteammatches.Where(l => l.AwayTeamId == t.Id);

                    foreach (Match m in allteamhomematches)
                    {
                        if (m.HomeGoals > m.AwayGoals)
                        {
                            wins++;
                            points += 3;
                        }
                        if (m.HomeGoals == m.AwayGoals)
                        {
                            draws++;
                            points += 1;
                        }

                        if (m.HomeGoals < m.AwayGoals)
                        {
                            losses++;
                        }

                        goalsfor     += (int)m.HomeGoals;
                        goalsagainst += (int)m.AwayGoals;
                    }

                    foreach (Match m in allteamawaymatches)
                    {
                        if (m.AwayGoals > m.HomeGoals)
                        {
                            wins++;
                            points += 3;
                        }
                        if (m.AwayGoals == m.HomeGoals)
                        {
                            draws++;
                            points += 1;
                        }
                        if (m.AwayGoals < m.HomeGoals)
                        {
                            losses++;
                        }

                        goalsfor     += (int)m.AwayGoals;
                        goalsagainst += (int)m.HomeGoals;
                    }
                    res.GoalsFor       = goalsfor;
                    res.GoalsAgainst   = goalsagainst;
                    res.GoalDifference = goalsfor - goalsagainst;
                    res.Wins           = wins;
                    res.Losses         = losses;
                    res.Draws          = draws;
                    res.Points         = points;

                    results.Add(res);
                }
            }

            ViewData["results"] = results.OrderByDescending(k => k.Points).ThenByDescending(k => k.GoalDifference);


            return(View());
        }