コード例 #1
0
        private List <TeamSchedule> TransformDataToModel(MySportsFeedSchedule matches)
        {
            var teamSchedules = new List <TeamSchedule>();

            foreach (var team in Teams.Playoff)
            {
                var teamSchedule = matches.fullgameschedule.gameentry.Where(x => String.Equals(x.awayTeam.Abbreviation, team, StringComparison.CurrentCultureIgnoreCase) ||
                                                                            String.Equals(x.homeTeam.Abbreviation, team, StringComparison.CurrentCultureIgnoreCase));

                foreach (var match in teamSchedule)
                {
                    //var dateString = match.date.Split(' ');
                    // dateString[0] => 20161130, change to 2016-11-30
                    //var newDate = DateTime.ParseExact(match.date,
                    //              "yyyyMMdd",
                    //               CultureInfo.InvariantCulture);
                    var newDate = DateTime.Parse(match.date);
                    teamSchedules.Add(new TeamSchedule()
                    {
                        C_Team = team,
                        D_Date = newDate
                    });
                }
            }

            if (!teamSchedules.Any())
            {
                return(null);
            }

            return(teamSchedules);
        }
コード例 #2
0
        private MySportsFeedSchedule GetMatches()
        {
            MySportsFeedSchedule data = null;

            try
            {
                // file in Client/bin
                var appDomain = System.AppDomain.CurrentDomain;
                var basePath  = appDomain.RelativeSearchPath ?? appDomain.BaseDirectory;
                var json      = Path.Combine(basePath, "Playoff1stRound.json");

                // FIle.ReadAllText : open, read, then clode the file no need of using(){}
                data = JsonConvert.DeserializeObject <MySportsFeedSchedule>(File.ReadAllText(json));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(data);
        }