示例#1
0
        /// <summary>
        /// Returns collection of grid columns for the type of data underlying grid rows whose properties are supplied.
        /// </summary>
        /// <param name="propertyNames">Names of properties whose columns are returned.</param>
        /// <returns>Grid column collection.</returns>
        /// <typeparam name="TItem">The type of data underlying grid rows.</typeparam>
        public IEnumerable <IGridColumn> GetGridColumns <TItem>(params string[] propertyNames)
        {
            Type itemType = typeof(TItem);
            List <IGridColumn> columns = new List <IGridColumn>();

            foreach (string propertyName in propertyNames)
            {
                PropertyInfo propertyInfo = itemType.GetProperty(propertyName);
                columns.Add(new GridColumn
                {
                    DisplayName      = _dataAnnotationsService.GetPropertyDisplayName <TItem>(propertyName),
                    ItemPropertyName = propertyName
                });
            }
            return(columns);
        }
示例#2
0
        /// <summary>
        /// Returns grid view model given search parameters and a search result.
        /// </summary>
        /// <typeparam name="TItem">The type of business model found in the search result.</typeparam>
        /// <param name="searchParameters">Search parameters.</param>
        /// <param name="searchResult">Search result.</param>
        /// <param name="properties">Model properties that determine grid column headers.</param>
        /// <param name="urlParameters">URL parameters determining hyperlinks found in first grid column.</param>
        /// <param name="routePropertyPairs">Determines route values dynamically extracted from business models.</param>
        /// <param name="noItemsMessage">String that is displayed when search result contains no items.</param>
        /// <returns>Grid of items.</returns>
        public Grid GetGrid <TItem>(ISearchParameters searchParameters, ISearchResult <TItem> searchResult, List <string> properties, UrlParameters urlParameters, List <RoutePropertyPair> routePropertyPairs, string noItemsMessage)
        {
            // Construct grid object
            Grid grid = new Grid
            {
                EmptyMessage = searchResult.Items.Count() == 0 ? noItemsMessage : null,
                Headers      = new List <GridHeader>(),
                Rows         = new List <GridRow>(),
                Search       = searchParameters.Search,
            };

            // Grid pager
            int pageCount = ((searchResult.Total - 1) / searchParameters.PageSize) + 1;

            if (pageCount > 1)
            {
                grid.Pager = new Pager
                {
                    FirstButtonLabel    = PagerResource.FirstButtonLabel,
                    PreviousButtonLabel = PagerResource.PreviousButtonLabel,
                    NextButtonLabel     = PagerResource.NextButtonLabel,
                    LastButtonLabel     = PagerResource.LastButtonLabel,
                    PageCount           = pageCount,
                    Summary             = string.Format(PagerResource.PageAndCountText, searchParameters.PageIndex, pageCount),
                    Page = searchParameters.PageIndex + 1
                };
            }

            // Populate headers
            foreach (string property in properties)
            {
                grid.Headers.Add(new GridHeader {
                    Label = _dataAnnotationsService.GetPropertyDisplayName <TItem>(property)
                });
            }

            // Populate rows
            UrlHelper urlHelper = null;// new UrlHelper();

            foreach (TItem item in searchResult.Items)
            {
                grid.Rows.Add(GetGridRow(item, properties, urlHelper, urlParameters, routePropertyPairs));
            }

            // Return the result
            return(grid);
        }