Esempio n. 1
0
        public void ValidateAllData()
        {
            List <string>    errors        = new List <string>();
            List <TeamModel> existingTeams = SqlDataHandler.GetAllData <TeamModel>("dbo.SP_GetAllTeams");
            List <string>    usedNames     = new List <string>();
            string           nameLower     = "";

            if (TeamName != null)
            {
                nameLower = TeamName.ToLower();
            }

            foreach (TeamModel team in existingTeams)
            {
                usedNames.Add(team.TeamName);
            }

            if (usedNames.Contains(TeamName))
            {
                errors.Add($"Team name {TeamName} is already taken.");
            }

            if (String.IsNullOrWhiteSpace(TeamName))
            {
                errors.Add("Team must have a name.");
            }

            if (nameLower.Contains("dummy"))
            {
                errors.Add(@"Team name must not contain word ""dummy"".");
            }

            if (TeamMembers.Count == 0)
            {
                errors.Add("Team must have at least 1 member.");
            }

            bool somethingWrong = usedNames.Contains(TeamName) || String.IsNullOrWhiteSpace(TeamName) ||
                                  nameLower.Contains("dummy") || TeamMembers.Count == 0;

            if (somethingWrong)
            {
                CanCreateTeam = false;
                ErrorMessage  = $"* {string.Join(" ", errors)}";
            }
            else
            {
                CanCreateTeam = true;
                ErrorMessage  = null;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// When receiving the team
        /// </summary>
        /// <param name="teamId"></param>
        private async void TeamSelected(string teamId)
        {
            if (teamId.Contains("teamId"))
            {
                var TeamId = teamId.Split('=')[1];
                //get team id and load all it's matches and fixtures
                GetMatchesAndFixtures(TeamId);

                //loop through the live matches to find if the team is currently playing
                foreach (Match match in await repository.LoadLive())
                {
                    if (TeamId == match.home_id || TeamId == match.away_id)
                    {
                        CurrentlyLive  = true;
                        LiveMatch      = match;
                        LiveMatch.date = "LIVE";
                        return;
                    }
                    else
                    {
                        CurrentlyLive = false;
                    }
                }
            }

            if (teamId.Contains("teamName"))
            {
                TeamName = teamId.Split('=')[1];

                //load the team logo
                foreach (Logo logo in repository.LoadLogos())
                {
                    if (TeamName.ToLower() == logo.team_name.ToLower())
                    {
                        TeamLogo = logo.logo;
                        return;
                    }
                    if (TeamName.Contains(logo.team_name) ||
                        $"FC {TeamName}".Contains(logo.team_name) ||
                        $"{TeamName} FC".Contains(logo.team_name))
                    {
                        TeamLogo = logo.logo;
                        return;
                    }
                    TeamLogo = "";
                }
            }
        }