public async Task <PagingDataSource <Staff> > Get(ODataQueryOptions <Staff> options, [FromUri] StaffList req) { StaffService.DisableProxy(); var litStaff = StaffService.GetAll(); if (req != null) { if (req.Includes != null && req.Includes.Length > 0) { litStaff = Include(litStaff, req.Includes); } if (req.PositionId > 0) { litStaff = litStaff.Where(o => o.PositionId == req.PositionId); } } var ls = (IQueryable <Staff>)options.ApplyTo(litStaff); var retVal = new PagingDataSource <Staff>(); retVal.Data = await ls.Cast <Staff>().ToListAsync(); retVal.Total = Request.GetInlineCount() ?? 0; return(retVal); }
public PagingDataSource <T> GetPagingDataSource <T>(string withSql, OrderPagingQuery <T> query, string tableName = "TResult") where T : class { string pageSql = SqlBuildHelper.BuildPageSql(withSql, query, tableName); string countSql = SqlBuildHelper.BuildCountSql(withSql, tableName); IList <T> pagedList = Database.SqlQuery <T>(pageSql).ToList(); int count = Database.SqlQuery <int>(countSql).FirstOrDefault(); var result = new PagingDataSource <T>(pagedList, query, count); return(result); }
public string Get() { DataSource dataSource = new DataSourceCreator(Name, KeyValues).Create(); if (dataSource.GetType() == typeof(PagingDataSource)) { PagingDataSource ds = dataSource as PagingDataSource; IEnumerable <string> jsonCollection; if (ds.Expands == null || ds.Expands.Length == 0) { jsonCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Parameters); } else { jsonCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Expands, ds.Parameters); } string json = string.Format("[{0}]", string.Join(",", jsonCollection)); int count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters); json = string.Format("{{\"@count\":{0},\"value\":{1}}}", count, json); return(json); } else if (dataSource.GetType() == typeof(CollectionDataSource)) { CollectionDataSource ds = dataSource as CollectionDataSource; IEnumerable <string> jsonCollection; if (ds.Expands == null || ds.Expands.Length == 0) { jsonCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Parameters); } else { jsonCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Expands, ds.Parameters); } return(string.Format("[{0}]", string.Join(",", jsonCollection))); } else if (dataSource.GetType() == typeof(DefaultGetterDataSource)) { DefaultGetterDataSource ds = dataSource as DefaultGetterDataSource; return(ODataQuerier.GetDefault(dataSource.Entity, ds.Select)); } else if (dataSource.GetType() == typeof(CountDataSource)) { CountDataSource ds = dataSource as CountDataSource; int count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters); return(string.Format("{{\"Count\": {0}}}", count)); } throw new NotSupportedException(dataSource.GetType().ToString()); }
public async Task <PagingDataSource <Bill> > Get(ODataQueryOptions <Bill> options, [FromUri] BillList req) { BillService.DisableProxy(); var listBill = BillService.GetAll(); if (req != null && req.Includes != null && req.Includes.Length > 0) { listBill = Include(listBill, req.Includes); } var ls = (IQueryable <Bill>)options.ApplyTo(listBill); var retVal = new PagingDataSource <Bill>(); retVal.Data = await ls.Cast <Bill>().ToListAsync(); retVal.Total = Request.GetInlineCount() ?? 0; return(retVal); }
public async Task <PagingDataSource <Position> > Get(ODataQueryOptions <Position> options, [FromUri] PositionList req) { PositionService.DisableProxy(); var litPosition = PositionService.GetAll(); if (req != null) { if (req.Includes != null && req.Includes.Length > 0) { litPosition = Include(litPosition, req.Includes); } } var ls = (IQueryable <Position>)options.ApplyTo(litPosition); var retVal = new PagingDataSource <Position>(); retVal.Data = await ls.Cast <Position>().ToListAsync(); retVal.Total = Request.GetInlineCount() ?? 0; return(retVal); }
public XElement Get() { DataSource dataSource = new DataSourceCreator(Name, KeyValues).Create(); if (dataSource.GetType() == typeof(PagingDataSource)) { PagingDataSource ds = dataSource as PagingDataSource; IEnumerable <XElement> xCollection; XElement xsd; if (ds.Expands == null || ds.Expands.Length == 0) { xCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Parameters, out xsd); } else { xCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Expands, ds.Parameters, out xsd); } string collectionName = GetCollectionName(Schema, ds.Entity); XElement element = new XElement(collectionName, xCollection); element.SetAttributeValue(XNamespace.Xmlns + "i", XSI); int count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters); return(Pack(element, count, xsd)); } else if (dataSource.GetType() == typeof(CollectionDataSource)) { CollectionDataSource ds = dataSource as CollectionDataSource; IEnumerable <XElement> xCollection; XElement xsd; if (ds.Expands == null || ds.Expands.Length == 0) { xCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Parameters, out xsd); } else { xCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Expands, ds.Parameters, out xsd); } string collection = GetCollectionName(Schema, ds.Entity); XElement element = new XElement(collection, xCollection); element.SetAttributeValue(XNamespace.Xmlns + "i", XSI); return(Pack(element, null, xsd)); } else if (dataSource.GetType() == typeof(DefaultGetterDataSource)) { DefaultGetterDataSource ds = dataSource as DefaultGetterDataSource; XElement element = ODataQuerier.GetDefault(dataSource.Entity, ds.Select, out XElement xsd); element.SetAttributeValue(XNamespace.Xmlns + "i", XSI); return(Pack(element, null, xsd)); } else if (dataSource.GetType() == typeof(CountDataSource)) { CountDataSource ds = dataSource as CountDataSource; int count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters); return(new XElement("Count", count)); } throw new NotSupportedException(dataSource.GetType().ToString()); }