/// <summary> /// Get an array containing the property names to display at the top of the columns /// The function will check the names to not display and the names with a custom column header /// </summary> /// <returns></returns> protected string[] GetPropertyColumnNames() { string[] propertyNames = typeof(T).GetProperties() .Where(p => !IgnoredPropertyNames.Contains(p.Name)) .Select(p => GetPropertyColumnName(p)) .ToArray(); return(propertyNames); }
public virtual ActionResult GetAjax() { SetupIndex(); HtmlHelper helper = new HtmlHelper(new ViewContext(ControllerContext, new WebFormView(ControllerContext, "omg"), new ViewDataDictionary(), new TempDataDictionary(), new System.IO.StringWriter()), new ViewPage()); // Here, we need to use the property names from the class definition, not the column names that we display. string[] propertyNames = typeof(T).GetProperties() .Where(p => !IgnoredPropertyNames.Contains(p.Name)) .Select(p => p.Name) .ToArray(); // This is expected to set up the filter and pagination (and the sorting, once that is set up) IndexAjaxExtension.Initialize(ControllerContext, propertyNames); int totalRecordCount = Exchange.Get().Count(); string AdvancedSearchJson = Request["ef_Filter"]; JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, Dictionary <string, string> > filterEntries = serializer.Deserialize <Dictionary <string, Dictionary <string, string> > >(AdvancedSearchJson); Dictionary <string, ExpressFormsFilter> indexFilters = GetIndexFilters(); IEnumerable <T> filteredRecords = IndexAjaxExtension.RecordFilter.GetFilteredRecords <T>(Exchange.Get(), indexFilters, filterEntries); int filteredRecordCount = IndexAjaxExtension.RecordFilter.GetFilteredRecords <T>(Exchange.Get(), indexFilters, filterEntries).Count(); IEnumerable <T> sortedRecords = IndexAjaxExtension.RecordSorting.GetSortedRecords <T>(filteredRecords); IEnumerable <T> pageOfRecords = IndexAjaxExtension.RecordPagination.GetPageOfRecords <T>(sortedRecords); IEnumerable <ExpressFormsIndexRecord> indexRecords = pageOfRecords.Select(r => { ExpressFormsIndexRecord indexRecord = new ExpressFormsIndexRecord(); indexRecord.Initialize <T, TId>(r, GetIdFromRecord(r), propertyNames, IndexButtons, CustomPropertyDisplay, ControllerContext); return(indexRecord); }); var retval = new { iTotalRecords = totalRecordCount, // number of records in database before filtering iTotalDisplayRecords = filteredRecordCount, // number of records that match filter, not just on this page. aaData = indexRecords.Select(x => x.FieldHtml) }; return(Json(retval, JsonRequestBehavior.AllowGet)); } // end function GetAjax
} // end GetEditorButtons // A virtual helper function that is meant to be used to get the inputs that appear on the form. // May be overridden in a derived class to customize how the form works. protected virtual Dictionary <string, ExpressFormsInput> GetEditorInputs(T record) { // t.GetType() is used here rather than typeof(T) in order to get the most specific type implemented by the object passed in. IEnumerable <PropertyInfo> properties = record.GetType().GetProperties() .Where(p => (IgnoredPropertyNames == null) || !IgnoredPropertyNames.Contains(p.Name)); Func <PropertyInfo, ExpressFormsInput> InputSelector = p => GetEditorInput(record, p); Dictionary <string, ExpressFormsInput> inputs = properties .ToDictionary(p => p.Name, InputSelector); return(inputs); }
protected virtual Dictionary <string, ExpressFormsFilter> GetIndexFilters() { IEnumerable <PropertyInfo> properties = typeof(T).GetProperties() .Where(p => (IgnoredPropertyNames == null) || !IgnoredPropertyNames.Contains(p.Name)); Func <PropertyInfo, ExpressFormsFilter> FilterSelector = p => GetIndexFilter(p); Dictionary <string, ExpressFormsFilter> filters = properties .ToDictionary(p => p.Name, FilterSelector); return(filters); } // end GetIndexFilters
public EntityController() : base() { IgnoredPropertyNames.AddRange(new[] { "EntityState", "EntityKey" }); }