/// <summary> /// Configure /// </summary> /// <param name="app"></param> /// <param name="env"></param> public static void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseSwagger(c => { c.RouteTemplate = ApiConstants.Swagger.RouteTemplate; }); app.UseSwaggerUI(c => { c.DocumentTitle = ApiConstants.Swagger.ApiName; c.SwaggerEndpoint(ApiConstants.Swagger.Endpoint, $"{ApiConstants.Swagger.ApiName} {ApiConstants.Swagger.ApiVersion}"); c.RoutePrefix = ApiConstants.Swagger.RoutePrefix; c.DocExpansion(DocExpansion.None); }); app.UseAuthorization(); app.UseProblemDetails() .UseMvc(routeBuilder => { routeBuilder.EnableDependencyInjection(); routeBuilder.Select().Filter().OrderBy().Expand().Count().MaxTop(null); routeBuilder.MapODataServiceRoute("api", "api", EdmModelHelper.GetEdmModel(app.ApplicationServices)); }); }
public IActionResult Get(ODataQueryOptions <TaskModel> filter) { var tasks = repository.ListAll(); if (!string.IsNullOrWhiteSpace(filter.Filter?.RawValue)) { IEdmModel model = EdmModelHelper.GetEdmModel(); IEdmType type = model.FindDeclaredType("AspNetCoreODataWithModel.Data.Entities.Tarea"); IEdmNavigationSource source = model.FindDeclaredEntitySet("Tareas"); ODataQueryOptionParser parser = new ODataQueryOptionParser(model, type, source, new Dictionary <string, string> { { "$filter", filter.Filter?.RawValue } }); ODataQueryContext context = new ODataQueryContext(model, typeof(Tarea), filter.Context.Path); FilterQueryOption newfilter = new FilterQueryOption(filter.Filter?.RawValue, context, parser); tasks = newfilter.ApplyTo(tasks, new ODataQuerySettings()) as IQueryable <Tarea>; } var results = tasks.Select(p => mapper.Map <TaskModel>(p)); var page = new PageResult <TaskModel>(mapper.Map <IEnumerable <TaskModel> >(results.ToList()), Request.HttpContext.ODataFeature().NextLink, Request.HttpContext.ODataFeature().TotalCount); return(Ok(page)); }