コード例 #1
0
        public IQueryable <dynamic> GetFixtures([RouteData] string countryName)
        {
            var fixtures = Singleton.Get <RedisCacheManager>()
                           .Get <IList <WebFormModel.FootballFixture> >
                           (
                () => RequestLoader.FootballFixturesByDate(DateTime.Now),
                RequestLoader.Locker_FootballFixturesByDate,
                DateTime.Now.AddHours(4),
                RedisKeyMaker.FootballFixturesByDate(DateTime.Now)
                           );

            // step1. 종료된 경기는 필터링
            IEnumerable <WebFormModel.FootballFixture> filteredByData;

            if (string.IsNullOrEmpty(countryName))
            {
                filteredByData = fixtures.Where(elem => elem.MatchTime > DateTime.Now.AddHours(-2));
            }
            else
            {
                filteredByData = fixtures.Where(elem => elem.MatchTime > DateTime.Now.AddHours(-2) && elem.League.Country.Equals(countryName));
            }

            // step2. 데이터를 리그, 시작시간으로 그룹화
            var group_query = filteredByData.GroupBy(elem => new { League = elem.LeagueId, StartTime = elem.MatchTime });

            var result_query = from queryData in group_query
                               select new
            {
                League = queryData.FirstOrDefault().League.Name,
                queryData.Key.StartTime,
                queryData.FirstOrDefault()?.League.Flag,
                Fixtures = queryData.ToArray()
            };

            return(result_query.AsQueryable());
        }
コード例 #2
0
        public void DDLBindData()
        {
            List <DDL_NameValue> ddlDataList = new List <DDL_NameValue>();

            ddlDataList.Add(new DDL_NameValue {
                Name = "Filtered by country"
            });

            var fixtures = Singleton.Get <RedisCacheManager>()
                           .Get <IList <WebFormModel.FootballFixture> >
                           (
                () => RequestLoader.FootballFixturesByDate(DateTime.Now),
                RequestLoader.Locker_FootballFixturesByDate,
                DateTime.Now.AddHours(4),
                RedisKeyMaker.FootballFixturesByDate(DateTime.Now)
                           );

            // 종료된 경기 필터링
            var exclusive_finished = fixtures.Where(elem => elem.MatchTime > DateTime.Now.AddHours(-2));

            var group_query = exclusive_finished.GroupBy(elem => new { CountryName = elem.League.Country });

            var bindData = from queryData in group_query
                           select new DDL_NameValue
            {
                Name  = queryData.Key.CountryName,
                Value = queryData.Key.CountryName,
            };

            ddlDataList.AddRange(bindData);

            ddl_kindCountry.DataTextField  = "Name";
            ddl_kindCountry.DataValueField = "Value";
            ddl_kindCountry.DataSource     = ddlDataList;
            ddl_kindCountry.DataBind();
        }
コード例 #3
0
        /// <summary>
        /// 관심 경기 체크
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void chk_fixture_InterestedIndexChanged(Object sender, EventArgs e)
        {
            CheckBox chkbox = sender as CheckBox;

            if (chkbox == null)
            {
                return;
            }

            // 관심경기에 추가하는 경우
            if (chkbox.Checked)
            {
                // 모든 경기 가져오기
                var fixtures = Singleton.Get <RedisCacheManager>()
                               .Get <IList <WebFormModel.FootballFixture> >
                               (
                    () => RequestLoader.FootballFixturesByDate(DateTime.Now),
                    RequestLoader.Locker_FootballFixturesByDate,
                    DateTime.Now.AddHours(4),
                    RedisKeyMaker.FootballFixturesByDate(DateTime.Now)
                               );

                // 관심 경기 검색
                int interestedFixtureID = int.Parse(chkbox.ToolTip);
                var interestedFixture   = fixtures.Where(elem => elem.FixtureId == interestedFixtureID).FirstOrDefault();

                if (interestedFixture == null)
                {
                    return;
                }

                // 관심 경기 데이터 가져오기
                var interestedFixtures = Singleton.Get <RedisCacheManager>()
                                         .GetNullable <IList <WebFormModel.FootballFixture> >
                                         (
                    RedisKeyMaker.FootballInterestedFixture()
                                         );

                if (interestedFixtures == null)
                {
                    interestedFixtures = new List <WebFormModel.FootballFixture>();
                }

                // 관심 경기에 추가
                interestedFixtures.Add(interestedFixture);

                // 레디스에 저장
                Singleton.Get <RedisCacheManager>().Set
                (
                    JsonConvert.SerializeObject(interestedFixtures),
                    RequestLoader.Locker_FootballInterestedFixture,
                    new DateTime(9999, 12, 31),
                    RedisKeyMaker.FootballInterestedFixture()
                );
            }
            else // 관심경기에서 제거하는 경우
            {
                // 관심 경기 데이터 가져오기
                var interestedFixtures = Singleton.Get <RedisCacheManager>()
                                         .GetNullable <IList <WebFormModel.FootballFixture> >
                                         (
                    RedisKeyMaker.FootballInterestedFixture()
                                         );

                // 제거할 경기
                int interestedFixtureID = int.Parse(chkbox.ToolTip);
                var interestedFixture   = interestedFixtures.Where(elem => elem.FixtureId == interestedFixtureID).FirstOrDefault();

                if (interestedFixture == null)
                {
                    return; // 이미 제거된 경기
                }
                // 관심 경기에서 제거
                interestedFixtures.Remove(interestedFixture);

                // 레디스에 저장
                Singleton.Get <RedisCacheManager>().Set
                (
                    JsonConvert.SerializeObject(interestedFixtures),
                    RequestLoader.Locker_FootballInterestedFixture,
                    new DateTime(9999, 12, 31),
                    RedisKeyMaker.FootballInterestedFixture()
                );
            }
        }