コード例 #1
0
        public ResponseContentActionResult<UserRecordsResponse> Get(long userId, bool lifetime = false, string types = "")
        {
            var query = new RecordQuery
                {
                    IncludeLifetime = lifetime,
                    Queries = _manager.ParseToRecordQuery(types)
                };

            var results = _manager.GetRecordsForUser(userId, query);

            if (results == null)
            {
                return CreateNullResponse<UserRecordsResponse>();
            }

            var firstRecord = results.FirstOrDefault();
            var userName = firstRecord != null ? firstRecord.UserName : String.Empty;

            var response = new UserRecordsResponse
                {
                    UserId = userId,
                    UserName = userName,
                    Lifetime = results.FirstOrDefault(r => r.RecordType == RecordType.Lifetime).ToResponse(),
                    Seasons = results.Where(r => r.RecordType == RecordType.Season).Select(r => r.ToResponse() as UserSeasonRecordResponse).ToList(),
                    SeasonTypes = results.Where(r => r.RecordType == RecordType.SeasonType).Select(r => r.ToResponse() as UserSeasonTypeRecordResponse).ToList(),
                    Weeks = results.Where(r => r.RecordType == RecordType.Week).Select(r => r.ToResponse() as UserWeeklyRecordResponse).ToList(),
                };

            return CreateResponse(response);
        }
コード例 #2
0
        private void BuildQueryConditions(RecordQuery query, MySqlCommand cmd, string sql)
        {
            var sb = new StringBuilder();

            sb.AppendLine("WHERE `type` = @type ");

            if (query.IncludeLifetime)
            {
                cmd.Parameters.AddWithValue("@type", RecordType.Lifetime);
            }
            else
            {
                cmd.Parameters.AddWithValue("@type", -1);
            }

            sb.AppendLine(BuildSeasonQueryCondition(query.Queries.Where(q => q.RecordType == RecordType.Season).ToArray()));
            sb.AppendLine(BuildSeasonTypeQueryCondition(query.Queries.Where(q => q.RecordType == RecordType.SeasonType).ToArray()));
            sb.AppendLine(BuildWeekQueryCondition(query.Queries.Where(q => q.RecordType == RecordType.Week).ToArray()));

            cmd.CommandText = String.Format(sql, sb);
        }
コード例 #3
0
        public IList<UserRecord> GetRecordsForUser(long userId, RecordQuery query)
        {
            var records = new List<UserRecord>();

            using (var conn = GetConnection())
            {
                var cmd = new MySqlCommand
                    {
                        Connection = conn
                    };

                cmd.Parameters.AddWithValue("@userId", userId);
                BuildQueryConditions(query, cmd, GET_FOR_USER);
                ExecuteReader(cmd, dr => records.Add(MapUserRecord(dr)));
            }

            return  records;
        }
コード例 #4
0
ファイル: RecordsManager.cs プロジェクト: hecubu5/sportpicks
 public IList<UserRecord> GetRecordsForUser(long userId, RecordQuery query)
 {
     return _recordsRepository.GetRecordsForUser(userId, query);
 }