Example #1
0
        /// <summary>
        /// Возвращает результат запроса
        /// </summary>
        /// <returns></returns>
        public virtual QpContentResult GetRealData()
        {
            ValidateQuery();

            if (string.IsNullOrEmpty(_query.Fields))
            {
                throw new ArgumentNullException("Query.Fields");
            }

            string query = "SELECT " + _query.Fields +
                           " FROM " + _query.ContentName +
                           (string.IsNullOrEmpty(_query.Where) ? "" : " WHERE " + _query.Where);
            var command = _dbConnection.CreateCommand(query);

            var result = new QpContentResult
            {
                PrimaryContent = _dbConnection.GetRealData(command),
                Query          = _query,
                DbConnection   = _dbConnection
            };

            result.AddContent(_query.ContentName, result.PrimaryContent);

            return(result);
        }
Example #2
0
        /// <summary>
        /// Возвращает результат запроса
        /// </summary>
        /// <returns></returns>
        public virtual QpContentResult Get()
        {
            ValidateQuery();

            var result = new QpContentResult
            {
                PrimaryContent = _dbConnection.GetContentData(_query, out _),
                Query          = _query,
                DbConnection   = _dbConnection
            };

            result.AddContent(_query.ContentName, result.PrimaryContent);

            GetIncludes(result);

            return(result);
        }
Example #3
0
        /// <summary>
        /// Получает связанные контенты
        /// </summary>
        /// <param name="result">Результат</param>
        protected virtual void GetIncludes(QpContentResult result)
        {
            if (_includes.Count > 0)
            {
                var attributes = new QpMetadataManager(_dbConnection)
                                 .GetContentAttributes(
                    _query.SiteName,
                    _query.ContentName);

                foreach (var path in _includes)
                {
                    var    attr        = attributes.Where(w => w.Name == path).SingleOrDefault();
                    string contentName = _dbConnection.GetContentName(attr.RelatedContentId.Value);

                    string values = string.Empty;

                    if (attr.LinkId == null)
                    {
                        foreach (DataRow row in result.PrimaryContent.Rows)
                        {
                            if (contentName == _query.ContentName & !string.IsNullOrEmpty(row[path].ToString()))
                            {
                                if (result.PrimaryContent.Select(ContentItemIdFieldName + " = " + row[path].ToString()).Any())
                                {
                                    continue;
                                }
                            }

                            if (!string.IsNullOrEmpty(values) && !values.EndsWith(", "))
                            {
                                values += ", ";
                            }

                            string val = row[path].ToString();
                            if (!string.IsNullOrEmpty(val))
                            {
                                values += val;
                            }
                        }
                    }
                    else
                    {
                        foreach (DataRow row in result.PrimaryContent.Rows)
                        {
                            if (!string.IsNullOrEmpty(values))
                            {
                                values += ", ";
                            }

                            string val = row[ContentItemIdFieldName].ToString();
                            if (!string.IsNullOrEmpty(val))
                            {
                                values += val;
                            }
                        }

                        if (!string.IsNullOrEmpty(values) && !string.IsNullOrWhiteSpace(values))
                        {
                            values = _dbConnection.GetContentItemLinkIDs(attr.Name, values);
                        }
                    }

                    values = values.Trim();
                    if (values.EndsWith(","))
                    {
                        values = values.Substring(0, values.Length - 1);
                    }

                    if (!string.IsNullOrEmpty(values))
                    {
                        var query = new ContentDataQueryObject(
                            _dbConnection.DbConnector, _query.SiteName, contentName, "*",
                            string.Format(ContentItemIdFieldName + " in ({0})", values), null,
                            (long)0, (long)0,
                            (byte)0,
                            QpContentItemStatus.Published.GetDescription(),
                            (byte)0, (byte)0, false, 0.0, false, false);

                        var contentData       = _dbConnection.GetContentData(query, out _);
                        var existsContentData = result.GetContent(contentName);

                        if (existsContentData != null)
                        {
                            //NOTE: this line doesn't coverage unit tests
                            existsContentData.Merge(
                                contentData);
                        }

                        result.AddContent(contentName, contentData);
                    }
                }
            }
        }