Beispiel #1
0
 /// <summary>
 ///     Filter's this route's dataset by a request parameter that is compared to the primary key of 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 options builder to perform the operation on</param>
 /// <param name="parameters">The parameters to filter by</param>
 /// <returns>This <see cref="RestModelOptionsBuilder{TModel, TUser}" /> object, for chaining</returns>
 public static RestModelOptionsBuilder <TModel, TUser> FilterByPrimaryKey <TModel, TUser>(
     this RestModelOptionsBuilder <TModel, TUser> builder,
     params ParameterRetriever[] parameters)
     where TModel : class where TUser : class
 {
     return(builder.AddFilter(new PrimaryKeyFilter <TModel>(RestModelOptionsBuilderExtensions.GetPrimaryKey(builder), parameters)));
 }
Beispiel #2
0
 /// <summary>
 ///     Ensures that the primary key of the <typeparamref name="TModel" /> will be omitted from the response body
 /// </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="RestModelOptionsBuilder{TModel, TUser}" /> object, for chaining</returns>
 public static RestModelOptionsBuilder <TModel, TUser> OmitPrimaryKey <TModel, TUser>(
     this RestModelOptionsBuilder <TModel, TUser> builder)
     where TModel : class where TUser : class
 {
     foreach (KeyProperty Property in RestModelOptionsBuilderExtensions.GetPrimaryKey(builder))
     {
         builder.Omit(Property.PropertyInfo);
     }
     return(builder);
 }
Beispiel #3
0
        /// <summary>
        ///		Gets camelCased versions of the names of the primary key properties
        /// </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>camelCased versions of the primary key property names, in order</returns>
        private static string[] GetKeyNames <TModel, TUser>(RestModelOptionsBuilder <TModel, TUser> builder)
            where TModel : class where TUser : class
        {
            List <KeyProperty> KeyProperties = RestModelOptionsBuilderExtensions.GetPrimaryKey(builder);

            IEnumerable <string> Names =
                KeyProperties.Select(p => RestModelOptionsBuilderExtensions.CamelCase(p.Name));

            return(Names.ToArray());
        }