Esempio n. 1
0
        public IEnumerable <IHateoasLink> GetLinksFor <TModel>(TModel data)
        {
            var registrations = _httpConfiguration
                                .GetRegistrationsFor <TModel>()
                                .Where(p => !p.IsCollection);

            return(_linkFactory.CreateLinks(registrations, data));
        }
Esempio n. 2
0
 /// <summary>
 /// Returns the HATEOAS registrations for a specific model. Returns a (registered) empty list when the model could not be found.
 /// </summary>
 /// <param name="configuration">HTTP configuration</param>
 /// <param name="model">The model to get HATEOAS registrations for</param>
 /// <param name="isCollection"></param>
 /// <returns>HATEOAS registrations for the model specified</returns>
 public static List <IHateoasRegistration <TModel> > GetRegistrationsFor <TModel>(this IHttpConfiguration configuration)
 {
     return(configuration
            .GetRegistrationsFor(typeof(TModel))
            .Cast <IHateoasRegistration <TModel> >()
            .ToList());
 }
Esempio n. 3
0
        /// <summary>
        /// Returns the HATEOASregistration for a specific model and relation. Returns null when the combination of model and relation could not be found.
        /// </summary>
        /// <param name="configuration">HTTP configuration</param>
        /// <param name="model">The model to get an HATEOAS registration for</param>
        /// <param name="relation">Relation to the model</param>
        /// <param name="isCollection">Indicates wether the source registration is s collection</param>
        /// <returns>HATEOAS registration for the model and relation specified</returns>
        public static IHateoasRegistration GetRegistrationFor(this IHttpConfiguration configuration, Type model, string relation, bool isCollection)
        {
            var definitions = configuration.GetRegistrationsFor(model);
            var definition  = definitions.SingleOrDefault(def => def.Model == model && def.Relation == relation && def.IsCollection == isCollection);

            //if (definition == null)
            //{
            //    // TODO Maybe implement AddOrUpdate behavior?
            //    throw new HateoasException($"No registration found for model {model} and relation {relation}");
            //}

            return(definition);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds an HATEOAS registration
        /// </summary>
        /// <param name="configuration">HTTP configuration</param>
        /// <param name="registration">HATEOAS registration</param>
        public static void AddRegistration(this IHttpConfiguration configuration, IHateoasRegistration registration)
        {
            var definitions = configuration.GetRegistrationsFor(registration.Model);

            definitions.Add(registration);
        }