Esempio n. 1
1
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // 取消注释下面的代码行可对具有 IQueryable 或 IQueryable<T> 返回类型的操作启用查询支持。
            // 若要避免处理意外查询或恶意查询,请使用 QueryableAttribute 上的验证设置来验证传入查询。
            // 有关详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=279712。
            //config.EnableQuerySupport();

            // 若要在应用程序中禁用跟踪,请注释掉或删除以下代码行
            // 有关详细信息,请参阅: http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();

            // 参考:http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/creating-an-odata-endpoint
            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<Product>("Products");
            // 参考:http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/working-with-entity-relations
            builder.EntitySet<Supplier>("Suppliers");
            //config.Routes.MapODataRoute("OData", "odata", builder.GetEdmModel());
            config.Routes.MapODataServiceRoute("ODataRoute", "odata", builder.GetEdmModel());
        }
Esempio n. 2
0
		public static void Register(HttpConfiguration config)
		{
			// Attribute routing.
			config.MapHttpAttributeRoutes();

			config.Routes.MapHttpRoute(
				name: "DefaultApi",
				routeTemplate: "v1/{controller}/{id}",
				defaults: new { id = RouteParameter.Optional }
			);

			// Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
			// To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
			// For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
			config.AddODataQueryFilter();

			var builder = new ODataConventionModelBuilder();
			builder.EntitySet<Repository>("Repositories");
			builder.EntitySet<Session>("Sessions");
			builder.EntitySet<LogEntry>("LogEntries");
			config.Routes.MapODataServiceRoute("odata", "odata/v1", builder.GetEdmModel());

			// To disable tracing in your application, please comment out or remove the following line of code
			// For more information, refer to: http://www.asp.net/web-api
			config.EnableSystemDiagnosticsTracing();

			// Use camel case for JSON data.
			config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
		}
Esempio n. 3
0
 private static IEdmModel GetSampleModel()
 {
     ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
     builder.EntitySet<Employee>("employees");
     builder.EntitySet<WorkItem>("workitems");
     return builder.GetEdmModel();
 }
Esempio n. 4
0
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=301869.
            //config.EnableQuerySupport();

            ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.EntitySet<Employee>("Employees");
            var model = modelBuilder.GetEdmModel();

            config.Routes.MapODataRoute(routeName: "OData", routePrefix: "odata", model: model);

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();
        }
Esempio n. 5
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "CustomRoute",
                routeTemplate: "api/library/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            //Newly added for OData
            //    ODataModelBuilder builder = new ODataConventionModelBuilder();
            //    builder.EntitySet<Book>("Book");
            //    config.MapODataServiceRoute(
            //        routeName: "odata",
            //        routePrefix: "odata",
            //        model: builder.GetEdmModel());
            //}

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Book>("Book");
            config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());
        }
        public static IEdmModel GetEdmModel()
        {
            var builder = new ODataConventionModelBuilder();

            builder.DataServiceVersion = new Version(2, 0);
            builder.MaxDataServiceVersion = new Version(2, 0);
            builder.Namespace = "NuGetGallery";
            builder.ContainerName = "V2FeedContext";

            var packagesCollection = builder.EntitySet<V2FeedPackage>("Packages");
            packagesCollection.EntityType.HasKey(pkg => pkg.Id);
            packagesCollection.EntityType.HasKey(pkg => pkg.Version);

            var searchAction = builder.Action("Search");
            searchAction.Parameter<string>("searchTerm");
            searchAction.Parameter<string>("targetFramework");
            searchAction.Parameter<bool>("includePrerelease");
            searchAction.ReturnsCollectionFromEntitySet<V2FeedPackage>("Packages");

            var findPackagesAction = builder.Action("FindPackagesById");
            findPackagesAction.Parameter<string>("id");
            findPackagesAction.ReturnsCollectionFromEntitySet<V2FeedPackage>("Packages");

            var model = builder.GetEdmModel();
            model.SetEdmVersion(new Version(1, 0));
            model.SetEdmxVersion(new Version(1, 0));
            model.SetHasDefaultStream(model.FindDeclaredType(typeof(V2FeedPackage).FullName) as IEdmEntityType, hasStream: true);

            return model;
        }
Esempio n. 7
0
 private static IEdmModel GetInheritanceModel(HttpConfiguration config)
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder(config);
     var baseEntitySet = builder.EntitySet<BaseEntity>("BaseEntity");
     var derivedEntityType = builder.Entity<DerivedEntity>().DerivesFrom<BaseEntity>();
     return builder.GetEdmModel();
 }
 static IEdmModel GetModel()
 {
     ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
     builder.EntitySet<TodoList>("TodoLists");
     builder.EntitySet<TodoItem>("Todos");
     return builder.GetEdmModel();
 }
Esempio n. 9
0
        // Invoked once at startup to configure your application.
        public void Configuration(IAppBuilder builder)
        {
			builder.Use((context, next) => { context.Response.Headers.Add("MyHeader", new [] { "abc" }); return next(); });

			builder.UseStaticFiles("/Client");
			//builder.UseFileServer(new FileServerOptions()
			//{
			//	RequestPath = new PathString("/Client"),
			//	FileSystem = new PhysicalFileSystem(".\\Client")
			//});

			builder.Use<BasicAuthentication>();

			HttpConfiguration config = new HttpConfiguration();
			config.Routes.MapHttpRoute("Default", "api/Customer/{customerID}", new { controller="CustomerWebApi", customerID = RouteParameter.Optional });

			var oDataBuilder = new ODataConventionModelBuilder();
			oDataBuilder.EntitySet<Customer>("Customer");
			config.Routes.MapODataRoute("odata", "odata", oDataBuilder.GetEdmModel());

			// Use this if you want XML instead of JSON
			//config.Formatters.XmlFormatter.UseXmlSerializer = true;
			//config.Formatters.Remove(config.Formatters.JsonFormatter);

            config.Formatters.JsonFormatter.UseDataContractJsonSerializer = true;
			//config.Formatters.Remove(config.Formatters.XmlFormatter);

            builder.UseWebApi(config);
		}
Esempio n. 10
0
        public static void Register(HttpConfiguration config)
        {
            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            //config.EnableQuerySupport();

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api
            //config.EnableSystemDiagnosticsTracing();

            ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.EntitySet<QueueModel>("Queues");
            modelBuilder.EntitySet<QueueDetailModel>("QueueDetails");
            //modelBuilder.EntitySet<TestModel>("Test");
            modelBuilder.EntitySet<CaseModel>("Cases");
            modelBuilder.EntitySet<CaseSummaryModel>("CasesSummary");
            modelBuilder.EntitySet<CaseNotesModel>("CasesNotes");
            modelBuilder.EntitySet<IssueWIModel>("IssueWI");
            modelBuilder.EntitySet<QueueActivityModel>("QueueActivity");
            modelBuilder.EntitySet<EmployeeDetailModel>("EmployeeDetails");

            Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel();
            config.Routes.MapODataRoute("OdataRoute", "hapi", model);
            config.EnableQuerySupport();
        }
Esempio n. 11
0
        public static void Register(HttpConfiguration config)
        {
            // Web API routes
            config.MapHttpAttributeRoutes();

            // Use camel case for JSON data.
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            config.Formatters.JsonFormatter.SerializerSettings.DateFormatString = "yyyy-MM-ddTHH:mm:ssZ";
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.Filters.Add(new AuthorizeAttribute());
            config.Filters.Add(new SecurityExceptionFilterAttribute());

            ODataModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<GroupViewModel>("Groups");
            builder.EntitySet<LessonViewModel>("Lessons");
            builder.EntitySet<ScoreViewModel>("Scores");
            builder.EntitySet<UserViewModel>("UserView");
            config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());
        }
Esempio n. 12
0
        public static void Register(HttpConfiguration config)
        {
            // OData configuration
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Author>("authors");
            builder.EntitySet<Blog>("blogs");
            builder.EntitySet<Comment>("comments");
            builder.EntitySet<Post>("posts");
            builder.ContainerName = "BlogItDataService";

            config.Routes.MapODataServiceRoute("OData", "api/odata", builder.GetEdmModel());

            var queryAttributes = new EnableQueryAttribute()
            {
                PageSize = 100,
                MaxTop = 100,
                EnsureStableOrdering = false
            };
            config.AddODataQueryFilter(queryAttributes);

            // Web API attribute routing
            config.MapHttpAttributeRoutes();

            // Additional formatters
            config.Formatters.Add(new BsonMediaTypeFormatter());
        }
Esempio n. 13
0
 private static IEdmModel GetModel()
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     EntitySetConfiguration<OrderByCustomer> customers = builder.EntitySet<OrderByCustomer>("OrderByCustomers");
     EntitySetConfiguration<OrderByOrder> orders = builder.EntitySet<OrderByOrder>("OrderByOrders");
     return builder.GetEdmModel();
 }
Esempio n. 14
0
 protected static IEdmModel GetEdmModel(HttpConfiguration config)
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder(config);
     var entitySet = builder.EntitySet<StubEntity>("StubEntity");
     entitySet.EntityType.Collection.Action("Paged").ReturnsCollectionFromEntitySet<StubEntity>("StubEntity");
     return builder.GetEdmModel();
 }
Esempio n. 15
0
        public static void Register( HttpConfiguration config )
        {
            XmlConfigurator.Configure();
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<WebUser>( "WebUsers" );
            builder.EntitySet<Login>( "Logins" );
            builder.EntitySet<Role>( "Roles" );
            builder.EntitySet<Address>( "Address" );
            builder.EntitySet<Permission>( "Permissions" );
            builder.EntitySet<Credential>( "Credentials" );
            builder.EntitySet<Task>( "Tasks" );
            builder.EntitySet<IUser>( "IUsers" );

            var conventions = ODataRoutingConventions.CreateDefault();
            conventions.Insert( 0, new NavigationIndexRoutingConvention() );
            config.Routes.MapODataServiceRoute( "odata", "odata", builder.GetEdmModel(), new DefaultODataPathHandler(), conventions );

            // Obsolet:
            //config.Routes.MapODataRoute( routeName: "OData", routePrefix: "odata", model: builder.GetEdmModel() );

            //  config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "odata/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);
        }
Esempio n. 16
0
        public void Application_Start()
        {
            var edmx = new XmlDocument();
            edmx.Load(HttpContext.Current.Server.MapPath(WesentConfiguration.DefaultInstance.Model));
            var modelParser = new EdmxParser(edmx);

            var types = new RuntimeTypeGenerator(modelParser).GenerateTypes();

            GlobalConfiguration.Configure(config =>
            {

                //config.MessageHandlers.Add(new BasicAuthenticationHandler());
                //config.Filters.Add(new BasicAuthorizationFilter());

                ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

                config.Services.Replace(typeof(IHttpControllerSelector), new DynamicControllerSelector(config, types));

                foreach (var kv in types)
                {
                    var mi = typeof(ODataConventionModelBuilder).GetMethod("EntitySet").MakeGenericMethod(kv.Value); ;
                    mi.Invoke(builder, new[] { kv.Key });
                }
                config.Routes.MapODataRoute("odata", "", builder.GetEdmModel());

                if(!Directory.Exists("C:\\LogFiles\\wesent\\"))
                {
                    Directory.CreateDirectory("C:\\LogFiles\\wesent\\");
                }
                File.AppendAllLines("C:\\LogFiles\\wesent\\log.log", new[] { DateTime.Now.ToString() });

            });
        }
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
            config.Filters.Add(new AzureRaceDataWebAPI.Filters.ValidateHttpAntiForgeryTokenAttribute());

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Meeting>("Meetings");
            builder.EntitySet<RaceStartItem>("RaceStartItem");
            builder.EntitySet<CoverageItem>("CoverageItem");

            config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());

            //Use JSON formatting by default
            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.EnableCors();

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
Esempio n. 18
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            //config.EnableQuerySupport();

            var modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.EntitySet<Song>("Songs");
            modelBuilder.EntitySet<Artist>("Artists");
            modelBuilder.EntitySet<Album>("Albums");

            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;

            var model = modelBuilder.GetEdmModel();
            config.Routes.MapODataRoute("odata", "odata", model);
            config.EnableQuerySupport();
        }
Esempio n. 19
0
 private static IEdmModel GetModel()
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     var customers = builder.EntitySet<PropertyCustomer>("PropertyCustomers");
     customers.EntityType.Ignore(p => p.Secret);
     return builder.GetEdmModel();
 }
Esempio n. 20
0
        internal static IEdmModel GetEdmModel(this ApiActionDescriptor actionDescriptor, Type entityClrType)
        {
            if (actionDescriptor == null)
            {
                throw Error.ArgumentNull("actionDescriptor");
            }

            if (entityClrType == null)
            {
                throw Error.ArgumentNull("entityClrType");
            }

            // save the EdmModel to the action descriptor
            return actionDescriptor.Properties.GetOrAdd(EdmModelKey + entityClrType.FullName, _ =>
            {
                // It's safe to create HttpConfiguration, since it's used as an assembly Resolver.
                //ODataConventionModelBuilder builder = new ODataConventionModelBuilder(new HttpConfiguration(), isQueryCompositionMode: true);
                ODataConventionModelBuilder builder = new ODataConventionModelBuilder(new HttpConfiguration());
                EntityTypeConfiguration entityTypeConfiguration = builder.AddEntity(entityClrType);
                builder.AddEntitySet(entityClrType.Name, entityTypeConfiguration);
                IEdmModel edmModel = builder.GetEdmModel();
                Contract.Assert(edmModel != null);
                return edmModel;
            }) as IEdmModel;
        }
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.
            // TODO
            ////config.SuppressDefaultHostAuthentication();
            ////config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Attribute routing.
            config.MapHttpAttributeRoutes();

            // Validate all models sent to server upon receiving them
            config.Filters.Add(new ValidateModelAttribute(false));

            // There must be exactly one exception handler. (There is a default one that may be replaced.)
            // To make this sample easier to run in a browser, replace the default exception handler with one that sends
            // back text/plain content for all errors.
            config.Services.Replace(typeof(IExceptionHandler), new SiteExceptionHandler());

            // Convention-based routing.
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional });

            // OData
            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<Product>("Product");
            builder.EntitySet<Category>("Category");
            config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());

            // Custom JsonFormatter resolving
            ////config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
        }
        public void Build()
        {
            var builder = new ODataConventionModelBuilder();

            var entity = builder.EntitySet<ODataPackage>("Packages");
            entity.EntityType.HasKey(pkg => pkg.Id);
            entity.EntityType.HasKey(pkg => pkg.Version);

            var searchAction = builder.Action("Search");
            searchAction.Parameter<string>("searchTerm");
            searchAction.Parameter<string>("targetFramework");
            searchAction.Parameter<bool>("includePrerelease");
            searchAction.ReturnsCollectionFromEntitySet<ODataPackage>("Packages");

            var findPackagesAction = builder.Action("FindPackagesById");
            findPackagesAction.Parameter<string>("id");
            findPackagesAction.ReturnsCollectionFromEntitySet<ODataPackage>("Packages");

            var getUpdatesAction = builder.Action("GetUpdates");
            getUpdatesAction.Parameter<string>("packageIds");
            getUpdatesAction.Parameter<bool>("includePrerelease");
            getUpdatesAction.Parameter<bool>("includeAllVersions");
            getUpdatesAction.Parameter<string>("targetFrameworks");
            getUpdatesAction.Parameter<string>("versionConstraints");
            getUpdatesAction.ReturnsCollectionFromEntitySet<ODataPackage>("Packages");

            model = builder.GetEdmModel();
            model.SetHasDefaultStream(model.FindDeclaredType(typeof(ODataPackage).FullName) as IEdmEntityType, hasStream: true);
        }
Esempio n. 23
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            GlobalConfiguration.Configuration.Formatters.Clear();
            var formatter = new JsonMediaTypeFormatter
                                {
                                    SerializerSettings =
                                        new JsonSerializerSettings
                                            {
                                                PreserveReferencesHandling =
                                                    PreserveReferencesHandling.Objects
                                            }
                                };

            GlobalConfiguration.Configuration.Formatters.Add(formatter);

            // OData
            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<UserDevice>("UserDevice");
            builder.EntitySet<UserInformation>("UserInformation");
            config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
Esempio n. 24
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            config.Routes.MapHttpBatchRoute(
                routeName: "WebApiBatch",
                routeTemplate: "$batch",
                batchHandler: new DefaultHttpBatchHandler(GlobalConfiguration.DefaultServer));
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Category>("Categories");
            builder.EntitySet<Item>("Items");
            builder.EntitySet<Company>("Companies");
            builder.EntitySet<Inventory>("Inventories");
            builder.EntitySet<Event>("Events");
            builder.EntitySet<User>("Users");
            builder.EntitySet<Member>("Members");
            builder.EntitySet<Phone>("Phones");

            config.Routes.MapODataServiceRoute("odata", "/", builder.GetEdmModel());
            

        }
        public static void Register(HttpConfiguration config)
        {
            // Dependency resolver for dependency injection
            UnityContainer container = new UnityContainer();
            container.RegisterType<IResearchRepository, ResearchRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IProjectsRepository, ProjectsRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IReferencesRepository, ReferencesRepository>(new HierarchicalLifetimeManager());
            config.DependencyResolver = new UnityResolver(container);

            config.MapHttpAttributeRoutes();

            // API routes
            config.Routes.MapHttpRoute(
             name: "DefaultApi",
             routeTemplate: "api/{controller}/{id}",
             defaults: new { id = RouteParameter.Optional });

            //OData Models
            ODataModelBuilder odataBuilder = new ODataConventionModelBuilder();
            odataBuilder.Namespace = "SpResearchTracker.Models";
            odataBuilder.EntitySet<Project>("Projects");
            odataBuilder.EntitySet<Reference>("References");

            // OData routes
            config.Routes.MapODataRoute(
              routeName: "odata",
              routePrefix: "odata",
              model: odataBuilder.GetEdmModel(),
              batchHandler: new BreezeODataBatchHandler(GlobalConfiguration.DefaultServer));
        }
Esempio n. 26
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            config.MessageHandlers.Add(new LogHandler());
            // Web API routes
            config.MapHttpAttributeRoutes();

            //Definir	el	encargado	de	serializar	los	objetos
            var json = config.Formatters.JsonFormatter;
            //Establecemos	que	queremos	mantener	las	referencias	en	el	formateo
                                                json.SerializerSettings.PreserveReferencesHandling =
            Newtonsoft.Json.PreserveReferencesHandling.Objects;
            //Deshabilitamos	la	serializacion	en	XML
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); //registra los modelos de datos para all OData
            builder.EntitySet<Usuario>("Usuarios"); //conjunto de datos de cada una de las tablas que queremos mapear
            builder.EntitySet<Mensaje>("Mensaje");//conjunto de datos de cada una de las tablas que queremos mapear
            config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel()); //la ruta cuando queremos utilizar OData

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
Esempio n. 27
0
        public static void Register(HttpConfiguration config)
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();

            //builder.EntitySet<Entities.Models.Customer>(typeof(Entities.Models.Customer).Name);
            //builder.EntitySet<Entities.Models.Order>(typeof(Entities.Models.Order).Name);

            //var orderDetailBuilder = builder.EntitySet<Entities.Models.OrderDetail>(typeof(Entities.Models.OrderDetail).Name);
            //orderDetailBuilder.EntityType.HasKey(x => x.ProductID);

            //var customerDemographicBuilder = builder.EntitySet<Entities.Models.CustomerDemographic>(typeof(Entities.Models.CustomerDemographic).Name);
            //customerDemographicBuilder.EntityType.HasKey(x => x.CustomerDesc);

            //var productBuilder = builder.EntitySet<Entities.Models.Product>(typeof(Entities.Models.Product).Name);
            //productBuilder.EntityType.HasKey(t => t.ProductID);

            //builder.EntitySet<Entities.Models.Category>(typeof(Entities.Models.Category).Name);
            //builder.EntitySet<Entities.Models.Supplier>(typeof(Entities.Models.Supplier).Name);

            //builder.EntitySet<Entities.Models.Employee>(typeof(Entities.Models.Employee).Name);
            //builder.EntitySet<Entities.Models.Shipper>(typeof(Entities.Models.Shipper).Name);

        //    var model = builder.GetEdmModel();
         //   config.Routes.MapODataRoute("odata", "odata", model);

            config.EnableQuerySupport();
        }
 internal static ODataQueryContext CreateProductContext()
 {
     ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
     builder.EntitySet<Product>("Product");
     IEdmModel model = builder.GetEdmModel();
     return new ODataQueryContext(model, typeof(Product));
 }
 public IEdmModel GetModel()
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     builder.EntitySet<Customer>("ODataControllerWithQueryableOnAction");
     builder.EntitySet<Order>("Orders");
     return builder.GetEdmModel();
 }
Esempio n. 30
0
        public static void Register( HttpConfiguration config ) {
            config.EnableCors();
            config.MapHttpAttributeRoutes();
            // To prevent Error: Self referencing loop
            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
            config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet<IUser>( "Users" );
            builder.EntitySet<WebUser>( "WebUsers" );
            builder.EntitySet<Guest>( "Guests" );
            builder.EntitySet<Login>( "LoginSet" );
            builder.EntitySet<Permission>( "PermissionSet" );
            builder.EntitySet<Role>( "RoleSet" );
            builder.EntitySet<Address>( "AddressSet" );
            builder.EntitySet<Credential>( "CredentialSet" );
            builder.EntitySet<Task>( "TaskSet" );

            builder.Namespace = "OdataApi.Controllers";
            builder.Entity<WebUser>().Action( "Post" ).Parameter<int>( "Rating" );

            config.Routes.MapODataServiceRoute( "odata", "odata", builder.GetEdmModel() );
        }