/// <summary> /// Gets the list of products. /// </summary> /// <param name="count"> /// Number of products to return. /// </param> /// <returns> /// Returns the list of products. /// </returns> public static List<Product> GetProducts(int count) { var products = new List<Product>(); for (var i = 0; i < count; i++) { var link = new Link("self", "/products/" + (i + 1)); var links = new List<Link>() { link, new Link("product", "/products/{productId}"), new Link("products", "/products"), }; var product = new Product() { ProductId = i + 1, Name = "Product " + (i + 1), ProductType = (ProductType)((i + 1) % Enum.GetNames(typeof(ProductType)).Length), Rel = "product", Href = link.Href, Links = links, }; products.Add(product); } return products; }
protected override void CreateHypermedia() { Href = new Link("Document", "/api/Document/{id}").CreateLink(this.Id).Href; Links.Add(new Link { Href = Href, Rel = "self" }); Links.Add(new Link("Document", "/api/DownloadDocument/{id}").CreateLink(new { id=Id })); }
/// <summary> /// Gets the list of salutations. /// </summary> /// <returns>Returns the list of salutations.</returns> public static List<SalutationModel> GetSalutations() { var link = new Link("salutations", "/api/salutations"); var salutations = new List<SalutationModel>() { new SalutationModel("Mr", "Mr") { Rel = link.Rel, Href = link.Href, Links = new List<Link>() { link } }, new SalutationModel("Mrs", "Mrs") { Rel = link.Rel, Href = link.Href, Links = new List<Link>() { link } }, new SalutationModel("Ms", "Ms") { Rel = link.Rel, Href = link.Href, Links = new List<Link>() { link } }, new SalutationModel("Mx", "Mx") { Rel = link.Rel, Href = link.Href, Links = new List<Link>() { link } }, }; return salutations; }
private static IHypermediaResolver BuildHypermediaConfiguration() { var builder = Hypermedia.CreateBuilder(); // // Define the self-links var curie = new CuriesLink("beerco", "http://api.beerco.com/docs{?rel}"); var selfLink = curie.CreateLink<Model>("self", "~/api/value"); var helpLink = new Link("help", "http://www.iana.org/assignments/link-relations/link-relations.xhtml"); // // Register things with the container builder.Register(selfLink, new ModelAppender(), helpLink); return builder.Build(); }
/// <summary> /// Gets the product. /// </summary> /// <param name="productId"> /// The product Id. /// </param> /// <returns> /// Returns the product. /// </returns> public static Product GetProduct(int productId) { var link = new Link("self", "/products/" + productId); var links = new List<Link>() { link, new Link("template", "/products/{productId}"), new Link("products", "/products"), }; var product = new Product() { ProductId = productId, Name = "Product " + productId, ProductType = (ProductType)(productId % Enum.GetNames(typeof(ProductType)).Length), Rel = "product", Href = link.Href, Links = links, }; return product; }
private void WriteLink(JsonWriter writer, Link link) { writer.WriteStartObject(); foreach (PropertyInfo propertyInfo in link.GetType().GetProperties()) { switch (propertyInfo.Name.ToLowerInvariant()) { case "href": writer.WritePropertyName("href"); writer.WriteValue(ResolveUri(link.Href)); goto case "rel"; case "rel": break; case "istemplated": if (link.IsTemplated) { writer.WritePropertyName("templated"); writer.WriteValue(true); } goto case "rel"; default: if (propertyInfo.PropertyType == typeof(string)) { string str = propertyInfo.GetValue(link) as string; if (!string.IsNullOrEmpty(str)) { writer.WritePropertyName(propertyInfo.Name.ToLowerInvariant()); writer.WriteValue(str); } break; } goto case "rel"; } } writer.WriteEndObject(); }
public ApiVersion(string versionNumber) { VersionNumber = versionNumber; _link = new Link("apiversion", "~/api/apiversion/{id}"); }
public DocumentRepresentation() { Rel = new Link("Document", "/api/Document/{id}").Rel; }