/// <summary> /// Gets the properties that make up the primary key for the model /// </summary> /// <typeparam name="TModel">The model type that the API is being built for</typeparam> /// <typeparam name="TUser">The type of authenticated user context</typeparam> /// <param name="builder">The builder containing the type of database context to get the keys for</param> /// <returns>The properties that make up the primary key, in order</returns> private static List <KeyProperty> GetPrimaryKey <TModel, TUser>(RestModelOptionsBuilder <TModel, TUser> builder) where TModel : class where TUser : class { if (!(builder is IOrmRestModelOptionsBuilder <TModel, TUser> OrmBuilder)) { throw new OptionsException( "GetPrimaryKey can only be called on a builder that inherits from IOrmRestModelOptionsBuilder"); } return(OrmBuilder.GetPrimaryKey()); }
/// <summary> /// Sets this route up to handle a DELETE request using an ORM /// </summary> /// <typeparam name="TModel">The model type that the API is being built for</typeparam> /// <typeparam name="TUser">The type of authenticated user context</typeparam> /// <param name="builder">The options builder to perform the operation on</param> /// <param name="routePattern">The route pattern to set up the request for</param> /// <param name="optionsHandler">A handler for the route options</param> /// <returns>This <see cref="RestModelOptionsBuilder{TModel, TUser}" /> object, for chaining</returns> /// <remarks> /// If not used with any filters, this route will drop all models in the dataset /// </remarks> public static RestModelOptionsBuilder <TModel, TUser> Delete <TModel, TUser>( this RestModelOptionsBuilder <TModel, TUser> builder, string routePattern, Action <RestModelOptionsBuilder <TModel, TUser> >?optionsHandler = null) where TModel : class where TUser : class { if (!(builder is IOrmRestModelOptionsBuilder <TModel, TUser> OrmBuilder)) { throw new OptionsException( $"Delete may only be called on a builder that inherits from {nameof(IOrmRestModelOptionsBuilder<TModel, TUser>)}"); } IOperation <TModel, TUser> DeleteOperation = OrmBuilder.GetDeleteOperation(); return(builder.SetupDelete( routePattern, o => { o.UseOperation(DeleteOperation); optionsHandler?.Invoke(o); })); }
/// <summary> /// Sets this route up to handle a POST creation request using an ORM /// </summary> /// <typeparam name="TModel">The model type that the API is being built for</typeparam> /// <typeparam name="TUser">The type of authenticated user context</typeparam> /// <param name="builder">The options builder to perform the operation on</param> /// <param name="routePattern">The route pattern to set up the request for</param> /// <param name="optionsHandler">A handler for the route options</param> /// <returns>This <see cref="SeltzrOptionsBuilder{TModel, TUser}" /> object, for chaining</returns> public static SeltzrOptionsBuilder <TModel, TUser> PostCreate <TModel, TUser>( this SeltzrOptionsBuilder <TModel, TUser> builder, string routePattern, Action <SeltzrOptionsBuilder <TModel, TUser> >?optionsHandler = null) where TModel : class where TUser : class { if (!(builder is IOrmSeltzrOptionsBuilder <TModel, TUser> OrmBuilder)) { throw new OptionsException( $"PostCreate may only be called on a builder that inherits from {nameof(IOrmSeltzrOptionsBuilder<TModel, TUser>)}"); } IOperation <TModel, TUser> CreateOperation = OrmBuilder.GetCreateOperation(); return(builder.SetupPost( routePattern, o => { o.IgnorePrimaryKey(); o.UseOperation(CreateOperation); optionsHandler?.Invoke(o); })); }