/// <summary> /// Initializes a new instance of the <Typ>LearningStoreQuerySort</Typ> class. /// </summary> /// <param name="column"></param> /// <param name="direction"></param> public LearningStoreQuerySort(LearningStoreViewColumn column, LearningStoreSortDirection direction) { // Check the parameters if (column == null) { throw new LearningComponentsInternalException("LSTR2220"); } m_column = column; m_direction = direction; }
/// <summary> /// Add a sort order for the returned data /// </summary> /// <param name="columnName">Name of the column to be sorted on. This must /// refer to a non-XML, non-Guid column.</param> /// <param name="direction">Direction for the sort.</param> /// <exception cref="ArgumentNullException"><paramref name="columnName"/> is a null reference.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="direction"/> is invalid.</exception> /// <exception cref="InvalidOperationException"> /// The column was not found or is not sortable</exception> /// <example> /// The following code creates a new query that returns the names of /// all the users in the system sorted by name: /// <code language="C#"> /// LearningStoreQuery query = store.CreateQuery("UserItemView"); /// query.AddColumn("Name"); /// query.AddSort("Name", LearningStoreSortDirection.Ascending); /// </code> /// </example> public void AddSort(string columnName, LearningStoreSortDirection direction) { // Check input parameters if (columnName == null) { throw new ArgumentNullException("columnName"); } if ((direction != LearningStoreSortDirection.Ascending) && (direction != LearningStoreSortDirection.Descending)) { throw new ArgumentOutOfRangeException("direction"); } // Find the column in the view LearningStoreViewColumn column = null; if (!m_view.TryGetColumnByName(columnName, out column)) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, LearningStoreStrings.ColumnNotFound, columnName)); } // Can't sort on some columns if (!column.Sortable) { throw new InvalidOperationException( LearningStoreStrings.ColumnCannotBeSorted); } // Verify that the same sort hasn't already been added if (m_sorts.Exists(delegate(LearningStoreQuerySort otherSort) { return(Object.ReferenceEquals(column, otherSort.Column)); })) { throw new InvalidOperationException( LearningStoreStrings.ColumnAlreadySortedOn); } // Add the sort LearningStoreQuerySort sort = new LearningStoreQuerySort( column, direction); m_sorts.Add(sort); }