/// <summary> /// Get paginated list of entities /// </summary> /// <param name="parentid"></param> /// <returns>Paginated list of entities</returns> /// <exception cref="EntityOperationException"></exception> /// <exception cref="EntityDoesNotExistException"></exception> /// <exception cref="UnauthorizedOperationException"></exception> /// <exception cref="EntityValidationException"></exception> protected virtual PaginatedList <TViewModel> GetMany <TViewModel>(string parentid = "", ODataHelper <T> oData = null) where TViewModel : class, IViewModel <T, TViewModel>, new() { if (oData == null) { int maxRecords = int.Parse(config["App:MaxReturnRecords"]); oData = new ODataHelper <T>(); string queryString = ""; if (HttpContext != null && HttpContext.Request != null && HttpContext.Request.QueryString != null && HttpContext.Request.QueryString.HasValue) { queryString = HttpContext.Request.QueryString.Value; } oData.Parse(queryString); oData.Top = oData.Top == 0 ? maxRecords : oData.Top; } Guid parentGuid = Guid.Empty; if (!string.IsNullOrEmpty(parentid)) { parentGuid = new Guid(parentid); } return(readRepository.Find <TViewModel>(parentGuid, oData.Filter, oData.Sort, oData.SortDirection, oData.Skip, oData.Top)); }
/// <summary> /// Uses ODataFilter to get a count of records in the database /// </summary> /// <param name="parentid"></param> /// <returns>Count of records in the database</returns> /// <exception cref="EntityOperationException"></exception> /// <exception cref="EntityDoesNotExistException"></exception> /// <exception cref="UnauthorizedOperationException"></exception> /// <exception cref="EntityValidationException"></exception> protected virtual int?Count(string parentid = "") { ODataHelper <T> oData = new ODataHelper <T>(); string queryString = ""; if (HttpContext != null && HttpContext.Request != null && HttpContext.Request.QueryString != null && HttpContext.Request.QueryString.HasValue) { queryString = HttpContext.Request.QueryString.Value; } oData.Parse(queryString); Guid parentGuid = Guid.Empty; if (!string.IsNullOrEmpty(parentid)) { parentGuid = new Guid(parentid); } var result = readRepository.Find(parentGuid, oData.Filter, oData.Sort, oData.SortDirection, 0, 0); return(result.TotalCount); }
public ODataHelperViewModel <T> GetOData(HttpContext context, ODataHelper <T> oData) { string queryString = string.Empty; if (context != null && context.Request != null && context.Request.QueryString != null && context.Request.QueryString.HasValue) { queryString = context.Request.QueryString.Value; } oData.Parse(queryString); Guid parentguid = Guid.Empty; var newNode = oData.ParseOrderByQuery(queryString); if (newNode == null) { newNode = new OrderByNode <T>(); } Predicate <T> predicate = null; if (oData != null && oData.Filter != null) { predicate = new Predicate <T>(oData.Filter); } int take = (oData?.Top == null || oData?.Top == 0) ? 100 : oData.Top; ODataHelperViewModel <T> oDataHelperViewModel = new ODataHelperViewModel <T>() { Direction = newNode.Direction, Predicate = predicate, Skip = oData.Skip, PropertyName = newNode.PropertyName, Take = take, Filter = oData.Filter, Sort = oData.Sort, Top = oData.Top, SortDirection = oData.SortDirection }; return(oDataHelperViewModel); }
public async Task <IActionResult> GetPeople( [FromRoute] string organizationId, [FromQuery(Name = "$filter")] string filter = "", [FromQuery(Name = "$orderby")] string orderBy = "", [FromQuery(Name = "$top")] int top = 100, [FromQuery(Name = "$skip")] int skip = 0) { try { ODataHelper <TeamMemberViewModel> oData = new ODataHelper <TeamMemberViewModel>(); string queryString = ""; if (HttpContext != null && HttpContext.Request != null && HttpContext.Request.QueryString != null && HttpContext.Request.QueryString.HasValue) { queryString = HttpContext.Request.QueryString.Value; } var newNode = oData.ParseOrderByQuery(queryString); if (newNode == null) { newNode = new OrderByNode <TeamMemberViewModel>(); } Guid orgId = Guid.Parse(organizationId); var result = _membershipManager.GetPeopleInOrganization(orgId, newNode.PropertyName, newNode.Direction, skip, top); return(Ok(result)); } catch (Exception ex) { return(ex.GetActionResult()); } }