public async Task <PagedList <BookResponse> > GetBooksAsync(QueryOptions options) { QueryProcessing <Book> processing = new QueryProcessing <Book>(options); IQueryable <Book> query = GetEntities() .Include(p => p.Publisher) .Include(c => c.Category) .ThenInclude(c => c.ParentCategory); IQueryable <BookResponse> processedBooks; if (options.SortPropertyName == $"{nameof(Publisher)}.{nameof(Publisher.Name)}" || options.SortPropertyName == $"{nameof(Category)}.{nameof(Category.Name)}" || options.SortPropertyName == $"{nameof(Category)}.{nameof(Category.ParentCategory)}.{nameof(Category.Name)}") { processedBooks = options.DescendingOrder ? processing.ProcessQuery(query.OrderByDescending(b => b.Title)) .Select(e => e.MapBookResponse()) : processing.ProcessQuery(query.OrderBy(b => b.Title)) .Select(e => e.MapBookResponse()); } else { processedBooks = processing.ProcessQuery(query) .Select(e => e.MapBookResponse()); } PagedList <BookResponse> books = await Task.Run(() => new PagedList <BookResponse>(processedBooks, options)); return(books); }
public async Task <PagedList <Publisher> > GetPublishersAsync(QueryOptions options) { QueryProcessing <Publisher> processing = new QueryProcessing <Publisher>(options); IQueryable <Publisher> query = GetEntities(); IQueryable <Publisher> publishers = processing.ProcessQuery(query); return(await Task.Run(() => new PagedList <Publisher>(publishers, options))); }
public async Task <ActionResult> QueryResult(QueryInfo queryInfo) { if (queryInfo == null) { return(BadRequest()); } ViewData[nameof(SearchInfo)] = queryInfo; object results; try { /*** validation ***/ queryInfo.Validate(); /*** query preparation ***/ SparqlRemoteEndpoint endpoint = SearchPreparing.CreateEndpoint(queryInfo.Endpoints[0], queryInfo.Timeout, queryInfo.DefaultGraph); SparqlQuery query = QueryParsing.ParseQuery(queryInfo.QueryString); /*** query processing ***/ results = await QueryProcessing.ProcessQuery(query, endpoint); //ViewData["ExecutionTime"] = query.QueryExecutionTime; } catch (BrowserException e) { return(View("QueryResultError", e.Message)); } catch (Exception) { //TODO: better text return(View("QueryResultError", "Unknown error...")); } /*** result processing ***/ if (results is SparqlResultSet) { return(View("QueryResultSet", (SparqlResultSet)results)); } else if (results is IGraph) { return(View("QueryResultGraph", (IGraph)results)); } else if (results is AsyncError) { return(View("QueryResultError", ErrorProcessing.ProcessAsyncError((AsyncError)results))); } else { //TODO: better text return(View("QueryResultError", "Unknown error...")); } }
private static async Task <Dictionary <string, int> > RetrievePopularPropertiesFromEndpoint() { string errorMessage = ""; object results = null; try { SparqlQuery query = QueryParsing.ParseQuery(QueryCreating.GetQueryTemplateCopy(QueryTemplates.SelectPopularProperties)); SparqlRemoteEndpoint endpoint = SearchPreparing.CreateEndpoint(Config.LOV_SPARQL_ENDPOINT, Config.LOV_PREDICATES_SEARCH_TIMEOUT); results = await QueryProcessing.ProcessQuery(query, endpoint); } catch (BrowserException) { throw; } catch (Exception e) { throw new BrowserException("An unexpected error occured while retrieving the list of popular predicates.", e); } if (results is SparqlResultSet) { return(ResultSetToDictionary((SparqlResultSet)results)); } else if (results is AsyncError) { /*TODO: remove exceptions */ throw ((AsyncError)results).Error.InnerException; //errorMessage += ResultProcessing.ProcessAsyncError((AsyncError)results); //return null; } /*TODO: remove exceptions*/ throw new Exception(errorMessage); //otherwise it should be null and errorMessage should be already set //return null; }
public async Task <PagedList <CategoryResponse> > GetCategoriesAsync(QueryOptions options) { if (string.IsNullOrEmpty(options.SortPropertyName)) { options.SortPropertyName = nameof(Category.Name); } QueryProcessing <Category> processing = new QueryProcessing <Category>(options); IQueryable <Category> entities = GetEntities(); IQueryable <Category> query = entities .GroupJoin(entities, subcategory => subcategory.ParentCategoryID, category => category.Id, (Category subcategory, IEnumerable <Category> categories) => new { subcategory, categories }) .SelectMany(newCategory => newCategory.categories.DefaultIfEmpty(), (temp0, categoryWithDisplayedName) => new Category { Id = temp0.subcategory.Id, Name = temp0.subcategory.Name, ParentCategoryID = temp0.subcategory.ParentCategoryID, DisplayedName = (temp0.subcategory.ParentCategoryID == null) ? temp0.subcategory.Name : ((temp0.subcategory.ParentCategory.Name + " <=> ") + temp0.subcategory.Name) } ); //from subcategories in entities //join categories in entities //on subcategories.ParentCategoryID equals categories.Id into categoriesWithParent //from cwp in categoriesWithParent.DefaultIfEmpty() //select new Category //{ // Id = subcategories.Id, // Name = subcategories.Name, // ParentCategoryID = subcategories.ParentCategoryID, // DisplayedName = subcategories.ParentCategoryID == null // ? subcategories.Name // : subcategories.ParentCategory.Name + " <=> " + subcategories.Name //}; IQueryable <CategoryResponse> processedCategories; if (options.SortPropertyName == $"{nameof(Category.Name)}") { options.SortPropertyName = $"{nameof(Category.DisplayedName)}"; processedCategories = processing.ProcessQuery(query) .Select(e => e.MapCategoryResponse()); } else { processedCategories = processing.ProcessQuery(query) .Select(e => e.MapCategoryResponse()); } PagedList <CategoryResponse> pagedList = await Task.Run(() => new PagedList <CategoryResponse>(processedCategories, options)); return(pagedList); }