Exemple #1
0
 /// <summary>
 ///     Sets this route up to handle a GET request by query parameters using an ORM. The names of the query
 ///     parameters will be camelCased names of the primary key of the entity
 /// </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> GetByPrimaryKeyQuery <TModel, TUser>(
     this SeltzrOptionsBuilder <TModel, TUser> builder,
     string routePattern,
     Action <SeltzrOptionsBuilder <TModel, TUser> >?optionsHandler = null)
     where TModel : class where TUser : class =>
 builder.GetByPrimaryKeyQuery(
     routePattern,
     SeltzrOrmOptionsBuilderExtensions.GetKeyNames(builder),
     optionsHandler);
Exemple #2
0
        /// <summary>
        ///     Sets this route up to handle a GET request by route values using an ORM. The names of the route values
        ///     will be camelCased versions of the C# property name. If these route parameters do not already exist they will be
        ///     added in order, e.g. /key1/key2.
        /// </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> GetByPrimaryKey <TModel, TUser>(
            this SeltzrOptionsBuilder <TModel, TUser> builder,
            string routePattern,
            Action <SeltzrOptionsBuilder <TModel, TUser> >?optionsHandler = null)
            where TModel : class where TUser : class
        {
            string UpdatedPattern = routePattern;

            string[] ExistingNames = TemplateParser.Parse(routePattern).Parameters.Select(p => p.Name).ToArray();
            string[] KeyNames      = SeltzrOrmOptionsBuilderExtensions.GetKeyNames(builder);

            foreach (string KeyName in KeyNames.Except(ExistingNames))
            {
                if (!UpdatedPattern.EndsWith("/"))
                {
                    UpdatedPattern += "/";
                }
                UpdatedPattern += $"{{{KeyName}}}/";
            }

            return(builder.GetByPrimaryKey(UpdatedPattern, KeyNames, optionsHandler));
        }
        /// <summary>
        ///     Sets this route up to handle a DELETE request by route values using an ORM. The names of the route values
        ///     will be camelCased versions of the C# property name. If these route parameters do not already exist they will be
        ///     added in order, e.g. /key1/key2.
        /// </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="optionsHandler">A handler for the route options</param>
        /// <returns>This <see cref="SeltzrOptionsBuilder{TModel, TUser}" /> object, for chaining</returns>
        public static SeltzrOptionsBuilder <TModel, TUser> DeleteByPrimaryKey <TModel, TUser>(
            this SeltzrOptionsBuilder <TModel, TUser> builder,
            Action <SeltzrOptionsBuilder <TModel, TUser> >?optionsHandler)
            where TModel : class where TUser : class
        {
            string UpdatedPattern = string.Empty;
            IEnumerable <string> ExistingNames =
                TemplateParser.Parse(builder.RoutePattern).Parameters.Select(p => p.Name);

            string[] KeyNames = SeltzrOrmOptionsBuilderExtensions.GetKeyNames(builder);

            foreach (string KeyName in KeyNames.Except(ExistingNames))
            {
                if (!UpdatedPattern.EndsWith("/"))
                {
                    UpdatedPattern += "/";
                }
                UpdatedPattern += $"{{{KeyName}}}/";
            }

            return(builder.DeleteByPrimaryKey(UpdatedPattern, KeyNames, optionsHandler));
        }
 /// <summary>
 ///     Filter's this route's dataset by route values compared to the primary key of the model. The query parameters' names
 ///     will be camelCased versions of their C# property name
 /// </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>
 /// <returns>This <see cref="SeltzrOptionsBuilder{TModel, TUser}" /> object, for chaining</returns>
 public static SeltzrOptionsBuilder <TModel, TUser> FilterByPrimaryKeyRoute <TModel, TUser>(
     this SeltzrOptionsBuilder <TModel, TUser> builder)
     where TModel : class where TUser : class =>
 builder.FilterByPrimaryKeyRoute(SeltzrOrmOptionsBuilderExtensions.GetKeyNames(builder));
 /// <summary>
 ///     Sets this route up to handle a DELETE request by query parameters on the same route pattern using an ORM.
 ///     The names of the query parameters will be camelCased names of the primary key of the entity
 /// </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="optionsHandler">A handler for the route options</param>
 /// <returns>This <see cref="SeltzrOptionsBuilder{TModel, TUser}" /> object, for chaining</returns>
 public static SeltzrOptionsBuilder <TModel, TUser> DeleteByPrimaryKeyQuery <TModel, TUser>(
     this SeltzrOptionsBuilder <TModel, TUser> builder,
     Action <SeltzrOptionsBuilder <TModel, TUser> >?optionsHandler = null)
     where TModel : class where TUser : class =>
 builder.DeleteByPrimaryKeyQuery("", SeltzrOrmOptionsBuilderExtensions.GetKeyNames(builder), optionsHandler);