// GET: odata/Orders public async Task<IHttpActionResult> GetOrders(ODataQueryOptions<Order> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } var repository = new Repositories.OrderMemoryRepository(); var orders = queryOptions.ApplyTo(repository.Get().AsQueryable<Order>()); return Ok<IQueryable<Order>>((IQueryable<Order>)orders); }
// GET: odata/References(5) public async Task<IHttpActionResult> GetReference([FromODataUri] int key, ODataQueryOptions<Reference> queryOptions) { //Get access token to SharePoint string accessToken = await _tokenProvider.GetSharePointAccessToken(); if (accessToken == null) { throw new UnauthorizedAccessException(); } // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } //Get reference from SharePoint string eTag = Request.Headers.IfNoneMatch.ToString(); Reference reference = await _repository.GetReference(accessToken, key, eTag); //Check eTag if (reference.__eTag == eTag) { return new StatusCodeResult(HttpStatusCode.NotModified, Request); } return Ok(reference); }
// GET: odata/Projects(5) public async Task<IHttpActionResult> GetProject([FromODataUri] int key, ODataQueryOptions<Project> queryOptions) { //Get access token to SharePoint string accessToken = ((Repository)_repository).GetAccessToken(); if (accessToken == null) { throw new UnauthorizedAccessException(); } // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } //Get project from SharePoint string eTag = Request.Headers.IfNoneMatch.ToString(); Project project = await _repository.GetProject(accessToken, key, eTag); //Check eTag if (project.__eTag == eTag) { return new StatusCodeResult(HttpStatusCode.NotModified, Request); } else { return Ok<Project>(project); } }
public IHttpActionResult GetSalesLeads(ODataQueryOptions<SalesLead> queryOptions) { try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } var queryResults = queryOptions.ApplyTo(SalesLeadFactory.GetSalesLeads()).Cast<SalesLead>(); return Ok<IQueryable<SalesLead>>(queryResults); }
// GET: odata/SalesLeads(5) public IHttpActionResult GetSalesLead([FromODataUri] int key, ODataQueryOptions<SalesLead> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } // return Ok<SalesLead>(salesLead); return StatusCode(HttpStatusCode.NotImplemented); }
public IEnumerable<Customer> GetCustomers(ODataQueryOptions<Customer> queryOptions) { // validate the query. queryOptions.Validate(_validationSettings); // Apply the query. IQuery query = queryOptions.ApplyTo(_db); Console.WriteLine("Executing HQL:\t" + query); Console.WriteLine(); return query.List<Customer>(); }
// GET: odata/Product(5) public IHttpActionResult GetProductViewModel([FromODataUri] System.Guid key, ODataQueryOptions<ProductViewModel> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } // return Ok<ProductViewModel>(productViewModel); return StatusCode(HttpStatusCode.NotImplemented); }
// GET: odata/Product public IHttpActionResult GetProduct(ODataQueryOptions<ProductViewModel> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } // return Ok<IEnumerable<ProductViewModel>>(productViewModels); return StatusCode(HttpStatusCode.NotImplemented); }
// GET: odata/CategoryEntities(5) public IHttpActionResult GetCategoryEntity([FromODataUri] int key, ODataQueryOptions<CategoryEntity> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } return Ok<CategoryEntity>(db.Category.Single(o=>o.CategoryId==key)); //return StatusCode(HttpStatusCode.NotImplemented); }
// GET: odata/DBElemiMunka(5) public IHttpActionResult GetVELEMIMUNKAINMLIST([FromODataUri] long key, ODataQueryOptions<VELEMIMUNKAINMLIST> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } // return Ok<VELEMIMUNKAINMLIST>(vELEMIMUNKAINMLIST); return StatusCode(HttpStatusCode.NotImplemented); }
// GET: odata/Orders(5) public async Task<IHttpActionResult> GetOrder([FromODataUri] System.Guid key, ODataQueryOptions<Order> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } // return Ok<Order>(order); return StatusCode(HttpStatusCode.NotImplemented); }
// GET: odata/Racers(5) public IHttpActionResult GetRacer([FromODataUri] long key, ODataQueryOptions<Racer> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } // return Ok<Racer>(racer); return StatusCode(HttpStatusCode.NotImplemented); }
// GET: RaceApi/Racers public IQueryable<Racer> GetRacers(ODataQueryOptions<Racer> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return null; } // return Ok<IEnumerable<Racer>>(racers); return CurrentRaceRepository.AllRacers; }
// GET: NewsOdata/GettingNewsUsingHeaderValue(5) public IHttpActionResult GetNews([FromODataUri] long key, ODataQueryOptions<NewsInfrastructure.News> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } // return Ok<News>(news); return StatusCode(HttpStatusCode.NotImplemented); }
// GET: odata/CategoryEntities public IHttpActionResult GetCategoryEntities(ODataQueryOptions<CategoryEntity> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } return Ok<IEnumerable<CategoryEntity>>(db.Category); return StatusCode(HttpStatusCode.NotImplemented); }
public async Task<HttpResponseMessage> Get(string id, ODataQueryOptions<UserInfo> options) { await _watchProjectService.CheckProjectAsync(id, UserId); var validationSettings = new ODataValidationSettings { MaxTop = 100, AllowedArithmeticOperators = AllowedArithmeticOperators.None, AllowedFunctions = AllowedFunctions.None, AllowedLogicalOperators = AllowedLogicalOperators.None, AllowedQueryOptions = AllowedQueryOptions.Skip | AllowedQueryOptions.Top }; // Validating OData try { options.Validate(validationSettings); } catch (Exception) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ResponseMessages.InvalidQueryOptions)); } // Parsing filter parameters DataQueryOptions filter; try { filter = _mapper.Map<ODataQueryOptions, DataQueryOptions>(options); } catch (AutoMapperMappingException) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ResponseMessages.InvalidQueryOptions)); } // Retrieving projects IEnumerable<UserInfo> users; try { users = await _projectAbuseService.GetProjectReportersSequenceAsync(id, filter); } catch (NotSupportedException) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ResponseMessages.BadRequest)); } return Request.CreateResponse(HttpStatusCode.OK, users); }
// Note this can be done through Queryable attribute as well public IQueryable<Order> Get(ODataQueryOptions queryOptions) { // Register a custom FilterByValidator to disallow custom logic in the filter query if (queryOptions.Filter != null) { queryOptions.Filter.Validator = new RestrictiveFilterByQueryValidator(); } // Validate the query, we only allow order by Id property and // we only allow maximum Top query value to be 9 ODataValidationSettings settings = new ODataValidationSettings(){ MaxTop = 9 }; settings.AllowedOrderByProperties.Add("Id"); queryOptions.Validate(settings); // Apply the query return queryOptions.ApplyTo(OrderList.AsQueryable()) as IQueryable<Order>; }
public async Task<HttpResponseMessage> GetWeek(ODataQueryOptions<TrendingWatch> options) { var validationSettings = new ODataValidationSettings { MaxTop = 100, AllowedArithmeticOperators = AllowedArithmeticOperators.None, AllowedFunctions = AllowedFunctions.None, AllowedLogicalOperators = AllowedLogicalOperators.Equal | AllowedLogicalOperators.And, AllowedQueryOptions = AllowedQueryOptions.Filter | AllowedQueryOptions.Skip | AllowedQueryOptions.Top }; // Validating OData try { options.Validate(validationSettings); } catch (Exception) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ResponseMessages.InvalidQueryOptions)); } // Parsing filter parameters DataQueryOptions filter; try { filter = _mapper.Map<ODataQueryOptions, DataQueryOptions>(options); } catch (AutoMapperMappingException) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ResponseMessages.InvalidQueryOptions)); } // Retrieving projects IEnumerable<TrendingWatch> watchProjects; try { watchProjects = await _viewsService.GetWeeklyTrendsSequenceAsync(filter); } catch (NotSupportedException) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ResponseMessages.BadRequest)); } return Request.CreateResponse(HttpStatusCode.OK, watchProjects); }
// GET: odata/Course public IHttpActionResult GetCourse(ODataQueryOptions<CourseModels> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } CourseModels result = new CourseModels { Id = Guid.NewGuid(), Name = "My Sample Course" }; List<CourseModels> a = new List<CourseModels> { result }; return Ok<IEnumerable<CourseModels>>(a); // return Ok<IEnumerable<CourseModels>>(courseModels); return StatusCode(HttpStatusCode.NotImplemented); }
// GET: odata/DBElemiMunka public IHttpActionResult GetDBElemiMunka(ODataQueryOptions<VELEMIMUNKAINMLIST> queryOptions) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } var munkak = DBElemiMunkaHelper.GetDbPage(queryOptions); int count = DBElemiMunkaHelper.GetCount(queryOptions); Request.ODataProperties().TotalCount = count; return Ok<IEnumerable<VELEMIMUNKAINMLIST>>(munkak.AsQueryable()); }
public async Task<IHttpActionResult> GetProducts(ODataQueryOptions<AggregateProduct> queryOptions) { logger.Trace("Call ProductsController GetProducts"); try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } var orders = (IQueryable<AggregateProduct>)queryOptions .ApplyTo(repository.Get().AsQueryable()); return Ok(orders); }
/// <summary> /// Gets the document sets. /// </summary> /// <param name="queryOptions">The query options.</param> /// <returns></returns> public IHttpActionResult GetDocumentSets(ODataQueryOptions<DocumentSet> queryOptions) { try { queryOptions.Validate(ValidationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } try { string json = File.ReadAllText(HttpContext.Current.Server.MapPath("~/app_data/documentsets.json")); var list = JsonConvert.DeserializeObject<List<DocumentSet>>(json).AsQueryable(); var results = queryOptions.ApplyTo(list) as IEnumerable<DocumentSet>; return Ok(results); } catch (Exception ex) { return InternalServerError(ex); } }
public PageResult<Customer> Get(ODataQueryOptions<Customer> options) { Guid VALID_TENANT_ID = Guid.Parse("7b6791d5-8658-44e5-86bc-8181735d0bf7"); IQueryable query = dbContext.Customers.Where(c => c.Tenant_Id == VALID_TENANT_ID); ODataQuerySettings odataSettings = new ODataQuerySettings(); if (options.Filter != null) { // set validator that restricts client's filtering options.Filter.Validator = new QuoteQueryValidator(); options.Validate(new ODataValidationSettings()); query = options.Filter.ApplyTo(query, odataSettings); } // get the total count IQueryable<Customer> custQuery = query as IQueryable<Customer>; long totalCount = custQuery.LongCount(); if (options.OrderBy != null) { query = options.OrderBy.ApplyTo(query, odataSettings); } if (options.Skip != null) query = options.Skip.ApplyTo(query, odataSettings); if (options.Top != null) query = options.Top.ApplyTo(query, odataSettings); // if (options.SelectExpand != null) // query = options.SelectExpand.ApplyTo(query, odataSettings); //var resultList = new List<Customer>(query); var retValue = new PageResult<Customer>( query as IEnumerable<Customer>, Request.GetNextPageLink(), totalCount); return retValue; }
public async Task<IHttpActionResult> GetChilds([FromODataUri] System.Guid key, ODataQueryOptions<CategoryTree> queryOptions) { logger.Trace("Call CategoryTreesController GetChilds"); try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } var data = await repository.GetByParentId(key); var query = (IQueryable<CategoryTree>)queryOptions .ApplyTo(data.AsQueryable()); return Ok(query); }
public IQueryable<NewsInfrastructure.News> GetGettingNewsUsingHeaderValue(ODataQueryOptions<NewsInfrastructure.News> queryOptions, string NewsHeaderForSearch) { // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return null; } if (NewsHeaderForSearch != null) { return CurrentNewsWebsiteRepository.AllNews.Where(CurrentNews => CurrentNews.Header.Contains(NewsHeaderForSearch)).DistinctBy(ResultNews => ResultNews.Header).AsQueryable(); } else { return null; } }
public async Task<IHttpActionResult> GetCalloutDefinitions(ODataQueryOptions<CalloutDefinition> queryOptions) { var declaringType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType; var fn = String.Format("{0}:{1}", declaringType.Namespace, declaringType.Name); try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { Debug.WriteLine(String.Format("{0}: {1}\r\n{2}", ex.Source, ex.Message, ex.StackTrace)); return BadRequest(ex.Message); } try { Debug.WriteLine(fn); var identity = CurrentUserDataProvider.GetIdentity(TenantId); var permissionId = CreatePermissionId("CanRead"); if (!identity.Permissions.Contains(permissionId)) { return StatusCode(HttpStatusCode.Forbidden); } var calloutDefinitions = CurrentUserDataProvider. GetEntitiesForUser(db.CalloutDefinitions, identity.Username, identity.Tid); return Ok<IEnumerable<CalloutDefinition>>(calloutDefinitions); } catch (Exception e) { Debug.WriteLine(String.Format("{0}: {1}\r\n{2}", e.Source, e.Message, e.StackTrace)); throw; } }
/// <summary> /// Get Projects OData /// </summary> public IHttpActionResult GetProjectsOData(ODataQueryOptions<Project> queryOptions) { try { queryOptions.Validate(ValidationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } try { //TODO : Data will be fetched from WCF Service var projects = GetData(); var results = queryOptions.ApplyTo(projects.AsQueryable()) as IEnumerable<Project>; return Ok(results); } catch (Exception ex) { return InternalServerError(ex); } }
public async Task<IHttpActionResult> GetReferences(ODataQueryOptions<Reference> queryOptions) { //Get access token to SharePoint string accessToken = await _tokenProvider.GetSharePointAccessToken(); if (accessToken == null) { throw new UnauthorizedAccessException(); } // validate the query. try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { return BadRequest(ex.Message); } //Get projects from SharePoint IEnumerable<Reference> references = await _repository.GetReferences(accessToken); return Ok(references.AsQueryable()); }
public async Task<HttpResponseMessage> Get(ODataQueryOptions<ExampleProject> options) { var validationSettings = new ODataValidationSettings { MaxTop = 100, AllowedArithmeticOperators = AllowedArithmeticOperators.None, AllowedFunctions = AllowedFunctions.None, AllowedLogicalOperators = AllowedLogicalOperators.None, AllowedQueryOptions = AllowedQueryOptions.Skip | AllowedQueryOptions.Top | AllowedQueryOptions.OrderBy }; // Validating OData try { options.Validate(validationSettings); } catch (Exception) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ResponseMessages.InvalidQueryOptions)); } // Parsing filter parameters DataQueryOptions filter; try { filter = _mapper.Map<ODataQueryOptions, DataQueryOptions>(options); } catch (AutoMapperMappingException) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ResponseMessages.InvalidQueryOptions)); } // Retrieving projects var projects = await _exampleProjectService.GetSequenceAsync(filter); return Request.CreateResponse(HttpStatusCode.OK, projects); }
// GET: api/Utilities.svc/LifeCycle public async Task<IHttpActionResult> GetLifeCycles(ODataQueryOptions<LifeCycle> queryOptions) { var declaringType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType; var fn = String.Format("{0}:{1}", declaringType.Namespace, declaringType.Name); try { queryOptions.Validate(_validationSettings); } catch (ODataException ex) { Debug.WriteLine(String.Format("{0}: {1}\r\n{2}", ex.Source, ex.Message, ex.StackTrace)); return BadRequest(ex.Message); } Debug.WriteLine(fn); // return Ok<IEnumerable<LifeCycle>>(lifeCycles); return StatusCode(HttpStatusCode.NotImplemented); }