Exemplo n.º 1
0
    public static string Country(string countryName)
    {
        checkData = CheckDataIsNotEmpty(countryName, "Country");

        if (checkData != "Ok")
        {
            return(checkData);
        }
        try
        {
            using (soccerContext context = new soccerContext())
            {
                Country country = new Country
                {
                    ui   = Guid.NewGuid(),
                    Name = countryName,
                };
                context.Countries.Add(country);
                context.SaveChanges();
                return($"Country: {country.Name} is add to data!");
            }
        }
        catch (Exception)
        {
            return($"There is problem to add Competition {countryName} ");
        }
    }
Exemplo n.º 2
0
    public static string Town(string townName, string countryName)
    {
        checkData = CheckDataIsNotEmpty(townName, "Town");

        if (checkData != "Ok")
        {
            return(checkData);
        }
        try
        {
            using (soccerContext context = new soccerContext())
            {
                var country = context.Countries.FirstOrDefault(c => c.Name == countryName);

                Town town = new Town
                {
                    ui         = Guid.NewGuid(),
                    Country_ui = country.ui,
                    Name       = townName
                };

                context.Towns.Add(town);
                context.SaveChanges();
                return($"Town: {town.Name} is add to data!");
            }
        }
        catch (Exception)
        {
            return($"There is problem to add Town {townName}  ");
        }
    }
Exemplo n.º 3
0
    public void Execute()
    {
        Game game = new Game
        {
            ui = Guid.NewGuid()
        };

        using (soccerContext context = new soccerContext())
        {
            Guid        competitionGuid = new Guid(this.competition);
            Guid        homeTeamGuid    = new Guid(this.homeTeam);
            Guid        awayTeamGuid    = new Guid(this.awayTeam);
            Competition competitionData = context.Competitions.FirstOrDefault(c => c.ui == competitionGuid);
            Team        teamHomeData    = context.Teams.FirstOrDefault(t => t.ui == homeTeamGuid);
            Team        teamAwayData    = context.Teams.FirstOrDefault(t => t.ui == awayTeamGuid);

            game.Competition_ui = competitionData.ui;
            game.HomeTeam_ui    = teamHomeData.ui;
            game.AwayTeam_ui    = teamAwayData.ui;
            game.HomeTeamGoals  = homeTeamGoals;
            game.AwayTeamGoals  = awayTeamGoals;
            game.Date           = dateOfGame.Date;

            try
            {
                context.Games.Add(game);
                context.SaveChanges();
            }
            catch (Exception)
            {
                throw new ArgumentException("There is problem with Games Import!");
            }
        }
    }
Exemplo n.º 4
0
    public void Execute()
    {
        int number = (int)((EnumColor)Enum.Parse(typeof(EnumColor), this.colourName));

        Colour colour = new Colour
        {
            Name = number
        };
        Guid guid = Guid.NewGuid();

        colour.ui = guid;

        try
        {
            using (soccerContext context = new soccerContext())
            {
                context.Colours.Add(colour);
                context.SaveChanges();
            }
        }
        catch (Exception)
        {
            throw new ArgumentException("There is such colour in data");
        }
    }
Exemplo n.º 5
0
    public void GetCountriesSelectOptions()
    {
        using (soccerContext context = new soccerContext())
        {
            Dictionary <Guid, string> countries = context.Countries.Select(c => new { c.ui, c.Name }).ToDictionary(c => c.ui, c => c.Name);

            foreach (var country in countries)
            {
                Response.Write(String.Format(@"<option val=""{0}"">{1}</option>", country.Key, country.Value));
            }
        }
    }
Exemplo n.º 6
0
 public static object DropDownCountries()
 {
     using (soccerContext context = new soccerContext())
     {
         // Make the dropDown List of Counries names from Data
         List <Country> competitions = context.Countries.OrderBy(c => c.Name).ToList();
         var            objList      = (new[] { new { Text = "" } }).ToList();
         foreach (var competition in competitions)
         {
             objList.Add(new { Text = competition.Name });
         }
         objList = objList.Skip(1).ToList();
         return(objList);
     }
 }
Exemplo n.º 7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        using (soccerContext context = new soccerContext())
        {
            //Competitions Drop Down
            string valueCompetition = DropDownListCompetitions.SelectedValue;
            this.newCompetitionValue = valueCompetition;

            DropDownListCompetitions.DataSource     = context.Competitions.OrderBy(c => c.Name).ToList();
            DropDownListCompetitions.DataTextField  = "name";
            DropDownListCompetitions.DataValueField = "ui";

            DropDownListCompetitions.DataBind();
            DropDownListCompetitions.Items.Insert(0, new ListItem(String.Empty, String.Empty));
        }
    }
Exemplo n.º 8
0
    public void Execute()
    {
        Town town = new Town
        {
            Name = name,
            ui   = Guid.NewGuid()
        };

        soccerContext context = new soccerContext();

        try
        {
            Country country = context.Countries.FirstOrDefault(c => c.Name == countryName);
            country.Towns.Add(town);//Add town to this country
            town.Country_ui = country.ui;
            context.SaveChanges();
        }
        catch (Exception)
        {
            throw new System.InvalidOperationException("There is such town in data");
        }
    }
Exemplo n.º 9
0
    public void Execute()
    {
        Competition competition = new Competition
        {
            ui   = Guid.NewGuid(),
            Name = competitionName
        };

        try
        {
            using (soccerContext context = new soccerContext())
            {
                context.Competitions.Add(competition);
                context.SaveChanges();
            }

            //Working!
        }
        catch (Exception)
        {
            throw new ArgumentException("There is such Competition name!");
        }
    }
Exemplo n.º 10
0
    public void Execute()
    {
        Team team = new Team
        {
            Name = teamName,
            ui   = Guid.NewGuid()
        };

        using (soccerContext context = new soccerContext())
        {
            Competition competition = context.Competitions.FirstOrDefault(c => c.Name == competitionName);
            //competition.Teams.Add(team);

            Town town = context.Towns.FirstOrDefault(t => t.Name == townName);
            //town.Teams.Add(team);
            team.Competition_ui = competition.ui;
            team.Town_ui        = town.ui;
            int    idFirst   = int.Parse(primaryColour);
            int    idSecond  = int.Parse(secondaryColour);
            Colour colourOne = context.Colours.FirstOrDefault(c => c.Name == idFirst);
            Colour colourTwo = context.Colours.FirstOrDefault(c => c.Name == idSecond);

            team.Colour  = colourOne;
            team.Colour1 = colourTwo;

            try
            {
                context.Teams.Add(team);
                context.SaveChanges();
            }
            catch (Exception)
            {
                throw new ArgumentException("There is such team in data");
            }
        }
    }
Exemplo n.º 11
0
    public static string getWhileLoopData(string competitionUi)
    {
        string htmlStr = "";

        List <Team> teams = new List <Team>();
        List <Game> games = new List <Game>();

        Guid guidCompetition = new Guid(competitionUi);

        using (soccerContext context = new soccerContext())
        {
            // List of teams in that competition
            Competition competition = context.Competitions.FirstOrDefault(c => c.ui == guidCompetition);
            if (competition != null)
            {
                teams = context.Teams.Where(t => t.Competition.ui == guidCompetition).ToList(); //List of teams in this Competition
                games = context.Games.Where(g => g.Competition_ui == competition.ui).ToList();  //List of games in this competition
            }
        }
        Dictionary <Team, List <Game> > teamGames  = new Dictionary <Team, List <Game> >();
        Dictionary <Team, List <int> >  teamPoints = new Dictionary <Team, List <int> >();

        int    points   = 0;
        string teamName = "";
        int    wins     = 0;
        int    draws    = 0;
        int    loses    = 0;

        int    scoredGoals    = 0;
        int    receivedGoals  = 0;
        string goalDifference = "";

        foreach (var team in teams)
        {
            teamGames.Add(team, new List <Game>()); //add key Team
            teamPoints.Add(team, new List <int>()); //Add team with zero points
            teamName = team.Name;
            foreach (var game in games)
            {
                if (game.HomeTeam_ui == team.ui)                 //find is the team playing in this game and its home team
                {
                    scoredGoals   += game.HomeTeamGoals;         // add scored Goals
                    receivedGoals += game.AwayTeamGoals;         //add received Goals
                    if (game.HomeTeamGoals > game.AwayTeamGoals) //Our team is winner we give 3 points
                    {
                        points += 3;
                        wins   += 1;
                    }
                    else if (game.HomeTeamGoals == game.AwayTeamGoals)//Draw 1 points
                    {
                        points += 1;
                        draws  += 1;
                    }
                    else if (game.HomeTeamGoals < game.AwayTeamGoals)//Team lose 0 points , one loose
                    {
                        loses += 1;
                    }
                }
                else if (game.AwayTeam_ui == team.ui)            //find is the team playing in this game and its away  team
                {
                    scoredGoals   += game.AwayTeamGoals;         // add scored Goals
                    receivedGoals += game.HomeTeamGoals;         //add received Goals
                    if (game.HomeTeamGoals < game.AwayTeamGoals) //Our team is winner we give 3 points
                    {
                        points += 3;
                        wins   += 1;
                    }
                    else if (game.HomeTeamGoals == game.AwayTeamGoals)//Draw 1 points
                    {
                        points += 1;
                        draws  += 1;
                    }
                    else if (game.HomeTeamGoals > game.AwayTeamGoals)//Team lose 0 points , one loose
                    {
                        loses += 1;
                    }
                }
            }
            teamPoints[team].Add(points);
            teamPoints[team].Add(wins);
            teamPoints[team].Add(draws);
            teamPoints[team].Add(loses);
            teamPoints[team].Add(scoredGoals);
            teamPoints[team].Add(receivedGoals);

            points = 0;
            wins   = 0;
            draws  = 0;
            loses  = 0;

            scoredGoals   = 0;
            receivedGoals = 0;
        }
        int possition = 1;

        foreach (var team in teamPoints.OrderByDescending(t => t.Value[0]))
        {
            goalDifference = (team.Value[4] + "/" + team.Value[5] + "(" + (team.Value[4] - team.Value[5]) + ")").ToString();
            htmlStr       += "<tr><td>" + possition + "</td><td>" + team.Key.Name + "</td><td>" + team.Value[1] +
                             "</td><td>" + team.Value[2] + "</td><td>" + team.Value[3] + "</td><td>" + goalDifference + "</td><td>" + team.Value[0] + "</td><tr>";

            possition++;
        }
        return(htmlStr);
    }
Exemplo n.º 12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        using (soccerContext context = new soccerContext())
        {
            countries = context.Countries.Select(c => new { c.ui, c.Name }).ToDictionary(c => c.ui, c => c.Name);
        }

        //Make the dropDown List from Enum Class order by colour name
        DropDownListPrimaryKitColour.DataSource     = Enumeration.GetAll <EnumColor>().OrderBy(c => c.Value);
        DropDownListPrimaryKitColour.DataTextField  = "Value";
        DropDownListPrimaryKitColour.DataValueField = "Key";

        //Make the dropDown List from Enum Class order by colour name
        DropDownListSecondaryKitColour.DataSource     = Enumeration.GetAll <EnumColor>().OrderBy(c => c.Value);
        DropDownListSecondaryKitColour.DataTextField  = "Value";
        DropDownListSecondaryKitColour.DataValueField = "Key";

        DropDownListPrimaryKitColour.DataBind();
        DropDownListSecondaryKitColour.DataBind();

        using (soccerContext context = new soccerContext())
        {
            //Make the dropDown List from Competitions Data
            DropDownCompetitions.DataSource    = context.Competitions.OrderBy(c => c.Name).ToList();
            DropDownCompetitions.DataTextField = "name";
            DropDownCompetitions.DataBind();

            //Make the dropDown List from Town Data
            DropDownTowns.DataSource    = context.Towns.OrderBy(c => c.Name).ToList();
            DropDownTowns.DataTextField = "name";
            DropDownTowns.DataBind();


            //Get The new Team Name and import it to data
        }
        //if (Request.Form.Count > 0)
        //{
        //    string nameOfTeam = Request.Form["team"];
        //    string[] controls = Request.Form.AllKeys.Reverse().Take(5).ToArray();
        //    if (nameOfTeam != null && nameOfTeam != "")
        //    {
        //        string competition = Request.Form["ctl00$MainContent$DropDownCompetitions"];
        //        string town = Request.Form["ctl00$MainContent$DropDownTowns"];
        //        //there can be the same primary and secondary kit colour
        //        string primaryKitColour = Request.Form["ctl00$MainContent$DropDownListPrimaryKitColour"];
        //        string secondaryKitColour = Request.Form["ctl00$MainContent$DropDownListSecondaryKitColour"];
        //        if (primaryKitColour==secondaryKitColour)
        //        {
        //            throw new ArgumentException("Primary kit colour and secondary kit colour can not be the same");
        //        }
        //        //ToDO if Any is blanc like Select Competition or Select Town Throw Exeption
        //        string[] dataArgs = new string[] { nameOfTeam, competition, town, primaryKitColour, secondaryKitColour };


        //        CommandDispatcher commandDispatcher = new CommandDispatcher("team", dataArgs);

        //    }
        //    else
        //    {
        //        throw new ArgumentException("The Team Name is null or Empty");//ToDo this is not for here
        //    }
        //}
    }