예제 #1
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());
        }
예제 #2
0
        public ActionResult Add(Match match)
        {
            List <SelectListItem> fixturelist = new List <SelectListItem>();
            FixturesRepository    fixrep      = new FixturesRepository();
            var myfixtures = fixrep.GetAllFixtures().OrderByDescending(k => k.TimeStamp);

            if (myfixtures.Count() > 0)
            {
                foreach (Fixture f in myfixtures)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = f.Id.ToString();
                    sli.Text  = f.HomeTeamName + " vs " + f.AwayTeamName;
                    fixturelist.Add(sli);
                }
            }
            ViewData["MyMatches"] = fixturelist;

            MatchesRepository matchrep = new MatchesRepository();

            if (match.HomeTeamGoals != null)
            {
                if (match.AwayTeamGoals != null)
                {
                    matchrep.Add(match);
                    matchrep.SaveChanges();

                    return(Redirect("/matches"));
                }
                else
                {
                    ModelState.AddModelError("TeamAwayGoals", "Please make sure you've entered the number of goals that the away team scored");
                }
            }
            else
            {
                ModelState.AddModelError("TeamHomeGoals", "Please make sure you've entered the number of goals that the home team scored");
            }
            return(View(match));
        }
예제 #3
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));
        }