/// <summary> /// Multiple selector page. /// </summary> /// <param name="modelDelegate">Get index model delegate.</param> /// <param name="searchDelegate">Get search item delegate.</param> /// <param name="parentDelegate">Get parent model delegate.</param> /// <param name="page">Number of current page.</param> /// <param name="size">Number of entities per page.</param> /// <param name="parentpath">Path of parent for entity.</param> /// <param name="parentid">Parent id.</param> /// <param name="search">Is a search result.</param> /// <returns></returns> public async Task <ActionResult> GetMultipleSelectorAction(GetIndexModelDelegate modelDelegate, GetSearchItemDelegate searchDelegate, GetParentModelDelegate parentDelegate, int page = 1, int size = 10, string parentpath = null, Guid?parentid = null, bool search = false) { IQueryable <TEntity> queryable = EntityContext.Query(); EntitySearchItem[] searchItems = null; if (search) { searchItems = searchDelegate(ref queryable); } if (parentpath != null && parentid.HasValue) { try { queryable = EntityContext.InParent(queryable, parentpath, parentid.Value); } catch { return(new HttpStatusCodeResult(400)); } } var model = await modelDelegate(EntityContext.OrderBy(queryable), page, size); if (model == null) { return(new HttpStatusCodeResult(404)); } if (Metadata.ParentProperty != null) { model.Parent = await parentDelegate(parentid); } model.Headers = Metadata.ViewProperties; model.SearchItem = searchItems; model.Items = await EntityContext.ToArrayAsync(model.Queryable.Skip((model.CurrentPage - 1) * model.CurrentSize).Take(model.CurrentSize)); return(GetView(model)); }
/// <summary> /// Get the action result of index page. /// </summary> /// <param name="modelDelegate">Get index model delegate.</param> /// <param name="searchDelegate">Get search item delegate.</param> /// <param name="parentDelegate">Get parent model delegate.</param> /// <param name="page">Number of current page.</param> /// <param name="size">Number of entities per page.</param> /// <param name="parentpath">Path of parent for entity.</param> /// <param name="parentid">Parent id.</param> /// <param name="search">Is a search result.</param> /// <returns></returns> public async Task <ActionResult> GetIndexAction(GetIndexModelDelegate modelDelegate, GetSearchItemDelegate searchDelegate, GetParentModelDelegate parentDelegate, int page = 1, int size = 20, string parentpath = null, Guid?parentid = null, bool search = false) { if (page < 1) { return(new HttpStatusCodeResult(400)); } if (size < 1) { return(new HttpStatusCodeResult(400)); } IQueryable <TEntity> queryable = EntityContext.Query(); EntitySearchItem[] searchItems; if (search) { searchItems = searchDelegate(ref queryable); } else { searchItems = new EntitySearchItem[0]; if (parentpath != null && parentid.HasValue) { try { queryable = EntityContext.InParent(queryable, parentpath, parentid.Value); } catch { return(new HttpStatusCodeResult(400)); } } } var model = await modelDelegate(queryable, page, size); if (model == null) { return(new HttpStatusCodeResult(404)); } if (Metadata.ParentProperty != null && !search) { model.Parent = await parentDelegate(parentid); } model.SearchItem = searchItems; model.Items = await EntityContext.ToArrayAsync(model.Queryable.Skip((model.CurrentPage - 1) * model.CurrentSize).Take(model.CurrentSize)); if (model.ViewButtons.Length > 0) { IServiceProvider serviceProvider = Controller.GetServiceProvider(); foreach (var item in model.ViewButtons) { item.SetTarget(serviceProvider); } } return(GetView(model)); }