public async virtual Task <IActionResult> GetDataAsync( [FromRoute] string name, [FromQuery(Name = "$top")] string top, [FromQuery(Name = "$skip")] string skip, [FromQuery(Name = "$orderby")] string orderby, [FromQuery(Name = "$expand")] string expand, [FromQuery(Name = "$filter")] string filter) { try { ODataQueryOptions oDataQueryOptions = new ODataQueryOptions { Top = top, Skip = skip, //Select = select, OrderBy = orderby, Expand = expand, Filters = string.IsNullOrEmpty(filter) ? null : new List <string> { filter } }; var entity = entitiesRepository.GetById(name); if (entity == null) { return(NotFound($"No data found for entity {name}")); } var items = await(Task <IEnumerable <object> >) GetType() .GetMethod("ApplyQueryOptionsAsync") .MakeGenericMethod(entity.ToType()) .Invoke(this, new object[] { oDataQueryOptions }); return(Ok(new DataListResponse { Data = await PagedListData <object> .CreateAsync( items, top, skip, async() => await(Task <long?>) GetType() .GetMethod("CountAsync") .MakeGenericMethod(entity.ToType()) .Invoke(this, null)) })); } catch (Exception e) { return(this.InternalServerError(e.FlattenMessages())); } }
// GET api/<controller>/5 public async Task <IHttpActionResult> Get(Guid id) { var document = _documentRepository.GetById(id); //TODO add check for user name if (document == null) { return(NotFound()); } var fileStream = await _documentService.GetDocumentFile(document); HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(fileStream) }; httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = document.FileName, Size = document.Size }; httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); return(ResponseMessage(httpResponseMessage)); }
public virtual IActionResult Get([FromRoute] string entityName, ODataQueryOptions queryOptions) { var entity = entitiesRepository.GetById(entityName); if (entity == null) { return(NotFound($"No data found for entity {entityName}")); } return(Ok(GetType() .GetMethod("ApplyQueryOptions") .MakeGenericMethod(entity.ToType()) .Invoke(this, new object[] { queryOptions }))); }