From 0699d0a7b8b9a9b18d8fa498105e284ffe6c150b Mon Sep 17 00:00:00 2001 From: Paulius Date: Fri, 28 Apr 2017 18:39:39 +0200 Subject: WebAPI created. Database updated --- ApartmentManager/ApartmentManager.sln | 26 +- .../HousingWebAPI/App_Start/BundleConfig.cs | 28 + .../HousingWebAPI/App_Start/FilterConfig.cs | 13 + .../HousingWebAPI/App_Start/RouteConfig.cs | 23 + .../HousingWebAPI/App_Start/WebApiConfig.cs | 24 + .../HousingWebAPI/ApplicationInsights.config | 79 + .../Areas/HelpPage/ApiDescriptionExtensions.cs | 39 + .../Areas/HelpPage/App_Start/HelpPageConfig.cs | 113 + .../Areas/HelpPage/Controllers/HelpController.cs | 63 + .../HousingWebAPI/Areas/HelpPage/HelpPage.css | 134 + .../Areas/HelpPage/HelpPageAreaRegistration.cs | 26 + .../HelpPage/HelpPageConfigurationExtensions.cs | 467 + .../CollectionModelDescription.cs | 7 + .../ComplexTypeModelDescription.cs | 14 + .../DictionaryModelDescription.cs | 6 + .../ModelDescriptions/EnumTypeModelDescription.cs | 15 + .../ModelDescriptions/EnumValueDescription.cs | 11 + .../IModelDocumentationProvider.cs | 12 + .../KeyValuePairModelDescription.cs | 9 + .../HelpPage/ModelDescriptions/ModelDescription.cs | 16 + .../ModelDescriptions/ModelDescriptionGenerator.cs | 451 + .../ModelDescriptions/ModelNameAttribute.cs | 18 + .../HelpPage/ModelDescriptions/ModelNameHelper.cs | 36 + .../ModelDescriptions/ParameterAnnotation.cs | 11 + .../ModelDescriptions/ParameterDescription.cs | 21 + .../SimpleTypeModelDescription.cs | 6 + .../Areas/HelpPage/Models/HelpPageApiModel.cs | 108 + .../SampleGeneration/HelpPageSampleGenerator.cs | 444 + .../HelpPage/SampleGeneration/HelpPageSampleKey.cs | 172 + .../Areas/HelpPage/SampleGeneration/ImageSample.cs | 41 + .../HelpPage/SampleGeneration/InvalidSample.cs | 37 + .../HelpPage/SampleGeneration/ObjectGenerator.cs | 456 + .../HelpPage/SampleGeneration/SampleDirection.cs | 11 + .../Areas/HelpPage/SampleGeneration/TextSample.cs | 37 + .../Areas/HelpPage/Views/Help/Api.cshtml | 22 + .../Views/Help/DisplayTemplates/ApiGroup.cshtml | 41 + .../CollectionModelDescription.cshtml | 6 + .../ComplexTypeModelDescription.cshtml | 3 + .../DictionaryModelDescription.cshtml | 4 + .../EnumTypeModelDescription.cshtml | 24 + .../Help/DisplayTemplates/HelpPageApiModel.cshtml | 67 + .../Views/Help/DisplayTemplates/ImageSample.cshtml | 4 + .../Help/DisplayTemplates/InvalidSample.cshtml | 13 + .../KeyValuePairModelDescription.cshtml | 4 + .../DisplayTemplates/ModelDescriptionLink.cshtml | 26 + .../Views/Help/DisplayTemplates/Parameters.cshtml | 48 + .../Views/Help/DisplayTemplates/Samples.cshtml | 30 + .../SimpleTypeModelDescription.cshtml | 3 + .../Views/Help/DisplayTemplates/TextSample.cshtml | 6 + .../Areas/HelpPage/Views/Help/Index.cshtml | 38 + .../Areas/HelpPage/Views/Help/ResourceModel.cshtml | 19 + .../Areas/HelpPage/Views/Shared/_Layout.cshtml | 12 + .../HousingWebAPI/Areas/HelpPage/Views/Web.config | 41 + .../Areas/HelpPage/Views/_ViewStart.cshtml | 4 + .../Areas/HelpPage/XmlDocumentationProvider.cs | 161 + ApartmentManager/HousingWebAPI/Content/Site.css | 17 + .../HousingWebAPI/Content/bootstrap.css | 6816 ++++++++++++++ .../HousingWebAPI/Content/bootstrap.min.css | 20 + .../Controllers/ApartmentsController.cs | 133 + .../HousingWebAPI/Controllers/DefectsController.cs | 133 + .../HousingWebAPI/Controllers/HomeController.cs | 18 + .../Controllers/ResidentsController.cs | 133 + .../HousingWebAPI/Controllers/UsersController.cs | 133 + .../HousingWebAPI/Controllers/ValuesController.cs | 39 + ApartmentManager/HousingWebAPI/Global.asax | 1 + ApartmentManager/HousingWebAPI/Global.asax.cs | 23 + .../HousingWebAPI/HousingWebAPI.csproj | 316 + .../HousingWebAPI/Models/Apartments.cs | 39 + .../HousingWebAPI/Models/ApartmentsDataContext.cs | 114 + ApartmentManager/HousingWebAPI/Models/Defects.cs | 45 + .../HousingWebAPI/Models/PastContractOwners.cs | 17 + ApartmentManager/HousingWebAPI/Models/Residents.cs | 58 + ApartmentManager/HousingWebAPI/Models/Users.cs | 38 + ApartmentManager/HousingWebAPI/Project_Readme.html | 149 + .../HousingWebAPI/Properties/AssemblyInfo.cs | 35 + .../HousingWebAPI/Scripts/_references.js | Bin 0 -> 600 bytes .../HousingWebAPI/Scripts/bootstrap.js | 2014 ++++ .../HousingWebAPI/Scripts/bootstrap.min.js | 21 + .../Scripts/jquery-1.10.2.intellisense.js | 2671 ++++++ .../HousingWebAPI/Scripts/jquery-1.10.2.js | 9803 ++++++++++++++++++++ .../HousingWebAPI/Scripts/jquery-1.10.2.min.js | 23 + .../HousingWebAPI/Scripts/jquery-1.10.2.min.map | 1 + .../HousingWebAPI/Scripts/modernizr-2.6.2.js | 1416 +++ ApartmentManager/HousingWebAPI/Scripts/respond.js | 340 + .../HousingWebAPI/Scripts/respond.min.js | 20 + .../HousingWebAPI/Views/Home/Index.cshtml | 24 + .../HousingWebAPI/Views/Shared/Error.cshtml | 13 + .../HousingWebAPI/Views/Shared/_Layout.cshtml | 41 + ApartmentManager/HousingWebAPI/Views/Web.config | 43 + .../HousingWebAPI/Views/_ViewStart.cshtml | 3 + ApartmentManager/HousingWebAPI/Web.Debug.config | 30 + ApartmentManager/HousingWebAPI/Web.Release.config | 31 + ApartmentManager/HousingWebAPI/Web.config | 86 + ApartmentManager/HousingWebAPI/favicon.ico | Bin 0 -> 32038 bytes .../fonts/glyphicons-halflings-regular.eot | Bin 0 -> 14079 bytes .../fonts/glyphicons-halflings-regular.svg | 228 + .../fonts/glyphicons-halflings-regular.ttf | Bin 0 -> 29512 bytes .../fonts/glyphicons-halflings-regular.woff | Bin 0 -> 16448 bytes ApartmentManager/HousingWebAPI/packages.config | 30 + 99 files changed, 28663 insertions(+), 2 deletions(-) create mode 100644 ApartmentManager/HousingWebAPI/App_Start/BundleConfig.cs create mode 100644 ApartmentManager/HousingWebAPI/App_Start/FilterConfig.cs create mode 100644 ApartmentManager/HousingWebAPI/App_Start/RouteConfig.cs create mode 100644 ApartmentManager/HousingWebAPI/App_Start/WebApiConfig.cs create mode 100644 ApartmentManager/HousingWebAPI/ApplicationInsights.config create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ApiDescriptionExtensions.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/App_Start/HelpPageConfig.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Controllers/HelpController.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPage.css create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPageAreaRegistration.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPageConfigurationExtensions.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/CollectionModelDescription.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/ComplexTypeModelDescription.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/DictionaryModelDescription.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/EnumTypeModelDescription.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/EnumValueDescription.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/IModelDocumentationProvider.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/KeyValuePairModelDescription.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/ModelDescription.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/ModelDescriptionGenerator.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/ModelNameAttribute.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/ModelNameHelper.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/ParameterAnnotation.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/ParameterDescription.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/ModelDescriptions/SimpleTypeModelDescription.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Models/HelpPageApiModel.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/SampleGeneration/HelpPageSampleGenerator.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/SampleGeneration/HelpPageSampleKey.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/SampleGeneration/ImageSample.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/SampleGeneration/InvalidSample.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/SampleGeneration/ObjectGenerator.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/SampleGeneration/SampleDirection.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/SampleGeneration/TextSample.cs create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/Api.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/ApiGroup.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/CollectionModelDescription.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/ComplexTypeModelDescription.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/DictionaryModelDescription.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/EnumTypeModelDescription.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/HelpPageApiModel.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/ImageSample.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/InvalidSample.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/KeyValuePairModelDescription.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/ModelDescriptionLink.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/Parameters.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/Samples.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/SimpleTypeModelDescription.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/DisplayTemplates/TextSample.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/Index.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Help/ResourceModel.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Shared/_Layout.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/Web.config create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/Views/_ViewStart.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Areas/HelpPage/XmlDocumentationProvider.cs create mode 100644 ApartmentManager/HousingWebAPI/Content/Site.css create mode 100644 ApartmentManager/HousingWebAPI/Content/bootstrap.css create mode 100644 ApartmentManager/HousingWebAPI/Content/bootstrap.min.css create mode 100644 ApartmentManager/HousingWebAPI/Controllers/ApartmentsController.cs create mode 100644 ApartmentManager/HousingWebAPI/Controllers/DefectsController.cs create mode 100644 ApartmentManager/HousingWebAPI/Controllers/HomeController.cs create mode 100644 ApartmentManager/HousingWebAPI/Controllers/ResidentsController.cs create mode 100644 ApartmentManager/HousingWebAPI/Controllers/UsersController.cs create mode 100644 ApartmentManager/HousingWebAPI/Controllers/ValuesController.cs create mode 100644 ApartmentManager/HousingWebAPI/Global.asax create mode 100644 ApartmentManager/HousingWebAPI/Global.asax.cs create mode 100644 ApartmentManager/HousingWebAPI/HousingWebAPI.csproj create mode 100644 ApartmentManager/HousingWebAPI/Models/Apartments.cs create mode 100644 ApartmentManager/HousingWebAPI/Models/ApartmentsDataContext.cs create mode 100644 ApartmentManager/HousingWebAPI/Models/Defects.cs create mode 100644 ApartmentManager/HousingWebAPI/Models/PastContractOwners.cs create mode 100644 ApartmentManager/HousingWebAPI/Models/Residents.cs create mode 100644 ApartmentManager/HousingWebAPI/Models/Users.cs create mode 100644 ApartmentManager/HousingWebAPI/Project_Readme.html create mode 100644 ApartmentManager/HousingWebAPI/Properties/AssemblyInfo.cs create mode 100644 ApartmentManager/HousingWebAPI/Scripts/_references.js create mode 100644 ApartmentManager/HousingWebAPI/Scripts/bootstrap.js create mode 100644 ApartmentManager/HousingWebAPI/Scripts/bootstrap.min.js create mode 100644 ApartmentManager/HousingWebAPI/Scripts/jquery-1.10.2.intellisense.js create mode 100644 ApartmentManager/HousingWebAPI/Scripts/jquery-1.10.2.js create mode 100644 ApartmentManager/HousingWebAPI/Scripts/jquery-1.10.2.min.js create mode 100644 ApartmentManager/HousingWebAPI/Scripts/jquery-1.10.2.min.map create mode 100644 ApartmentManager/HousingWebAPI/Scripts/modernizr-2.6.2.js create mode 100644 ApartmentManager/HousingWebAPI/Scripts/respond.js create mode 100644 ApartmentManager/HousingWebAPI/Scripts/respond.min.js create mode 100644 ApartmentManager/HousingWebAPI/Views/Home/Index.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Views/Shared/Error.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Views/Shared/_Layout.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Views/Web.config create mode 100644 ApartmentManager/HousingWebAPI/Views/_ViewStart.cshtml create mode 100644 ApartmentManager/HousingWebAPI/Web.Debug.config create mode 100644 ApartmentManager/HousingWebAPI/Web.Release.config create mode 100644 ApartmentManager/HousingWebAPI/Web.config create mode 100644 ApartmentManager/HousingWebAPI/favicon.ico create mode 100644 ApartmentManager/HousingWebAPI/fonts/glyphicons-halflings-regular.eot create mode 100644 ApartmentManager/HousingWebAPI/fonts/glyphicons-halflings-regular.svg create mode 100644 ApartmentManager/HousingWebAPI/fonts/glyphicons-halflings-regular.ttf create mode 100644 ApartmentManager/HousingWebAPI/fonts/glyphicons-halflings-regular.woff create mode 100644 ApartmentManager/HousingWebAPI/packages.config diff --git a/ApartmentManager/ApartmentManager.sln b/ApartmentManager/ApartmentManager.sln index aa41e57..97a72ca 100644 --- a/ApartmentManager/ApartmentManager.sln +++ b/ApartmentManager/ApartmentManager.sln @@ -1,20 +1,25 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26403.7 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApartmentManager", "ApartmentManager\ApartmentManager.csproj", "{95401ED6-D03C-417D-8897-81B5454D2426}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HousingWebAPI", "HousingWebAPI\HousingWebAPI.csproj", "{E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU Debug|ARM = Debug|ARM Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU Release|ARM = Release|ARM Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {95401ED6-D03C-417D-8897-81B5454D2426}.Debug|Any CPU.ActiveCfg = Debug|x86 {95401ED6-D03C-417D-8897-81B5454D2426}.Debug|ARM.ActiveCfg = Debug|ARM {95401ED6-D03C-417D-8897-81B5454D2426}.Debug|ARM.Build.0 = Debug|ARM {95401ED6-D03C-417D-8897-81B5454D2426}.Debug|ARM.Deploy.0 = Debug|ARM @@ -24,6 +29,7 @@ Global {95401ED6-D03C-417D-8897-81B5454D2426}.Debug|x86.ActiveCfg = Debug|x86 {95401ED6-D03C-417D-8897-81B5454D2426}.Debug|x86.Build.0 = Debug|x86 {95401ED6-D03C-417D-8897-81B5454D2426}.Debug|x86.Deploy.0 = Debug|x86 + {95401ED6-D03C-417D-8897-81B5454D2426}.Release|Any CPU.ActiveCfg = Release|x86 {95401ED6-D03C-417D-8897-81B5454D2426}.Release|ARM.ActiveCfg = Release|ARM {95401ED6-D03C-417D-8897-81B5454D2426}.Release|ARM.Build.0 = Release|ARM {95401ED6-D03C-417D-8897-81B5454D2426}.Release|ARM.Deploy.0 = Release|ARM @@ -33,6 +39,22 @@ Global {95401ED6-D03C-417D-8897-81B5454D2426}.Release|x86.ActiveCfg = Release|x86 {95401ED6-D03C-417D-8897-81B5454D2426}.Release|x86.Build.0 = Release|x86 {95401ED6-D03C-417D-8897-81B5454D2426}.Release|x86.Deploy.0 = Release|x86 + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Debug|ARM.ActiveCfg = Debug|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Debug|ARM.Build.0 = Debug|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Debug|x64.ActiveCfg = Debug|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Debug|x64.Build.0 = Debug|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Debug|x86.ActiveCfg = Debug|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Debug|x86.Build.0 = Debug|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Release|Any CPU.Build.0 = Release|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Release|ARM.ActiveCfg = Release|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Release|ARM.Build.0 = Release|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Release|x64.ActiveCfg = Release|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Release|x64.Build.0 = Release|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Release|x86.ActiveCfg = Release|Any CPU + {E57E89D2-7DEA-433B-B7D3-CF27D6FDDE47}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ApartmentManager/HousingWebAPI/App_Start/BundleConfig.cs b/ApartmentManager/HousingWebAPI/App_Start/BundleConfig.cs new file mode 100644 index 0000000..12902e6 --- /dev/null +++ b/ApartmentManager/HousingWebAPI/App_Start/BundleConfig.cs @@ -0,0 +1,28 @@ +using System.Web; +using System.Web.Optimization; + +namespace HousingWebAPI +{ + public class BundleConfig + { + // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 + public static void RegisterBundles(BundleCollection bundles) + { + bundles.Add(new ScriptBundle("~/bundles/jquery").Include( + "~/Scripts/jquery-{version}.js")); + + // Use the development version of Modernizr to develop with and learn from. Then, when you're + // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. + bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( + "~/Scripts/modernizr-*")); + + bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( + "~/Scripts/bootstrap.js", + "~/Scripts/respond.js")); + + bundles.Add(new StyleBundle("~/Content/css").Include( + "~/Content/bootstrap.css", + "~/Content/site.css")); + } + } +} diff --git a/ApartmentManager/HousingWebAPI/App_Start/FilterConfig.cs b/ApartmentManager/HousingWebAPI/App_Start/FilterConfig.cs new file mode 100644 index 0000000..cc37135 --- /dev/null +++ b/ApartmentManager/HousingWebAPI/App_Start/FilterConfig.cs @@ -0,0 +1,13 @@ +using System.Web; +using System.Web.Mvc; + +namespace HousingWebAPI +{ + public class FilterConfig + { + public static void RegisterGlobalFilters(GlobalFilterCollection filters) + { + filters.Add(new HandleErrorAttribute()); + } + } +} diff --git a/ApartmentManager/HousingWebAPI/App_Start/RouteConfig.cs b/ApartmentManager/HousingWebAPI/App_Start/RouteConfig.cs new file mode 100644 index 0000000..6440cfb --- /dev/null +++ b/ApartmentManager/HousingWebAPI/App_Start/RouteConfig.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using System.Web.Routing; + +namespace HousingWebAPI +{ + public class RouteConfig + { + public static void RegisterRoutes(RouteCollection routes) + { + routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); + + routes.MapRoute( + name: "Default", + url: "{controller}/{action}/{id}", + defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } + ); + } + } +} diff --git a/ApartmentManager/HousingWebAPI/App_Start/WebApiConfig.cs b/ApartmentManager/HousingWebAPI/App_Start/WebApiConfig.cs new file mode 100644 index 0000000..a49bdaf --- /dev/null +++ b/ApartmentManager/HousingWebAPI/App_Start/WebApiConfig.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web.Http; + +namespace HousingWebAPI +{ + public static class WebApiConfig + { + public static void Register(HttpConfiguration config) + { + // Web API configuration and services + + // Web API routes + config.MapHttpAttributeRoutes(); + + config.Routes.MapHttpRoute( + name: "DefaultApi", + routeTemplate: "api/{controller}/{id}", + defaults: new { id = RouteParameter.Optional } + ); + } + } +} diff --git a/ApartmentManager/HousingWebAPI/ApplicationInsights.config b/ApartmentManager/HousingWebAPI/ApplicationInsights.config new file mode 100644 index 0000000..2e0a49a --- /dev/null +++ b/ApartmentManager/HousingWebAPI/ApplicationInsights.config @@ -0,0 +1,79 @@ + + + + + + + + + + + search|spider|crawl|Bot|Monitor|AlwaysOn + + + + + + + + + + + + + + + + + + + + + + System.Web.Handlers.TransferRequestHandler + Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler + System.Web.StaticFileHandler + System.Web.Handlers.AssemblyResourceLoader + System.Web.Optimization.BundleHandler + System.Web.Script.Services.ScriptHandlerFactory + System.Web.Handlers.TraceHandler + System.Web.Services.Discovery.DiscoveryRequestHandler + System.Web.HttpDebugHandler + + + + + + + + 5 + + + + \ No newline at end of file diff --git a/ApartmentManager/HousingWebAPI/Areas/HelpPage/ApiDescriptionExtensions.cs b/ApartmentManager/HousingWebAPI/Areas/HelpPage/ApiDescriptionExtensions.cs new file mode 100644 index 0000000..83077cb --- /dev/null +++ b/ApartmentManager/HousingWebAPI/Areas/HelpPage/ApiDescriptionExtensions.cs @@ -0,0 +1,39 @@ +using System; +using System.Text; +using System.Web; +using System.Web.Http.Description; + +namespace HousingWebAPI.Areas.HelpPage +{ + public static class ApiDescriptionExtensions + { + /// + /// Generates an URI-friendly ID for the . E.g. "Get-Values-id_name" instead of "GetValues/{id}?name={name}" + /// + /// The . + /// The ID as a string. + public static string GetFriendlyId(this ApiDescription description) + { + string path = description.RelativePath; + string[] urlParts = path.Split('?'); + string localPath = urlParts[0]; + string queryKeyString = null; + if (urlParts.Length > 1) + { + string query = urlParts[1]; + string[] queryKeys = HttpUtility.ParseQueryString(query).AllKeys; + queryKeyString = String.Join("_", queryKeys); + } + + StringBuilder friendlyPath = new StringBuilder(); + friendlyPath.AppendFormat("{0}-{1}", + description.HttpMethod.Method, + localPath.Replace("/", "-").Replace("{", String.Empty).Replace("}", String.Empty)); + if (queryKeyString != null) + { + friendlyPath.AppendFormat("_{0}", queryKeyString.Replace('.', '-')); + } + return friendlyPath.ToString(); + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebAPI/Areas/HelpPage/App_Start/HelpPageConfig.cs b/ApartmentManager/HousingWebAPI/Areas/HelpPage/App_Start/HelpPageConfig.cs new file mode 100644 index 0000000..7044013 --- /dev/null +++ b/ApartmentManager/HousingWebAPI/Areas/HelpPage/App_Start/HelpPageConfig.cs @@ -0,0 +1,113 @@ +// Uncomment the following to provide samples for PageResult. Must also add the Microsoft.AspNet.WebApi.OData +// package to your project. +////#define Handle_PageResultOfT + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Net.Http.Headers; +using System.Reflection; +using System.Web; +using System.Web.Http; +#if Handle_PageResultOfT +using System.Web.Http.OData; +#endif + +namespace HousingWebAPI.Areas.HelpPage +{ + /// + /// Use this class to customize the Help Page. + /// For example you can set a custom to supply the documentation + /// or you can provide the samples for the requests/responses. + /// + public static class HelpPageConfig + { + [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", + MessageId = "HousingWebAPI.Areas.HelpPage.TextSample.#ctor(System.String)", + Justification = "End users may choose to merge this string with existing localized resources.")] + [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", + MessageId = "bsonspec", + Justification = "Part of a URI.")] + public static void Register(HttpConfiguration config) + { + //// Uncomment the following to use the documentation from XML documentation file. + //config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml"))); + + //// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type. + //// Also, the string arrays will be used for IEnumerable. The sample objects will be serialized into different media type + //// formats by the available formatters. + //config.SetSampleObjects(new Dictionary + //{ + // {typeof(string), "sample string"}, + // {typeof(IEnumerable), new string[]{"sample 1", "sample 2"}} + //}); + + // Extend the following to provide factories for types not handled automatically (those lacking parameterless + // constructors) or for which you prefer to use non-default property values. Line below provides a fallback + // since automatic handling will fail and GeneratePageResult handles only a single type. +#if Handle_PageResultOfT + config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult); +#endif + + // Extend the following to use a preset object directly as the sample for all actions that support a media + // type, regardless of the body parameter or return type. The lines below avoid display of binary content. + // The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object. + config.SetSampleForMediaType( + new TextSample("Binary JSON content. See http://bsonspec.org for details."), + new MediaTypeHeaderValue("application/bson")); + + //// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format + //// and have IEnumerable as the body parameter or return type. + //config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable)); + + //// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values" + //// and action named "Put". + //config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put"); + + //// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png" + //// on the controller named "Values" and action named "Get" with parameter "id". + //config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id"); + + //// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent. + //// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter. + //config.SetActualRequestType(typeof(string), "Values", "Get"); + + //// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent. + //// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string. + //config.SetActualResponseType(typeof(string), "Values", "Post"); + } + +#if Handle_PageResultOfT + private static object GeneratePageResult(HelpPageSampleGenerator sampleGenerator, Type type) + { + if (type.IsGenericType) + { + Type openGenericType = type.GetGenericTypeDefinition(); + if (openGenericType == typeof(PageResult<>)) + { + // Get the T in PageResult + Type[] typeParameters = type.GetGenericArguments(); + Debug.Assert(typeParameters.Length == 1); + + // Create an enumeration to pass as the first parameter to the PageResult constuctor + Type itemsType = typeof(List<>).MakeGenericType(typeParameters); + object items = sampleGenerator.GetSampleObject(itemsType); + + // Fill in the other information needed to invoke the PageResult constuctor + Type[] parameterTypes = new Type[] { itemsType, typeof(Uri), typeof(long?), }; + object[] parameters = new object[] { items, null, (long)ObjectGenerator.DefaultCollectionSize, }; + + // Call PageResult(IEnumerable items, Uri nextPageLink, long? count) constructor + ConstructorInfo constructor = type.GetConstructor(parameterTypes); + return constructor.Invoke(parameters); + } + } + + return null; + } +#endif + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebAPI/Areas/HelpPage/Controllers/HelpController.cs b/ApartmentManager/HousingWebAPI/Areas/HelpPage/Controllers/HelpController.cs new file mode 100644 index 0000000..36674bc --- /dev/null +++ b/ApartmentManager/HousingWebAPI/Areas/HelpPage/Controllers/HelpController.cs @@ -0,0 +1,63 @@ +using System; +using System.Web.Http; +using System.Web.Mvc; +using HousingWebAPI.Areas.HelpPage.ModelDescriptions; +using HousingWebAPI.Areas.HelpPage.Models; + +namespace HousingWebAPI.Areas.HelpPage.Controllers +{ + /// + /// The controller that will handle requests for the help page. + /// + public class HelpController : Controller + { + private const string ErrorViewName = "Error"; + + public HelpController() + : this(GlobalConfiguration.Configuration) + { + } + + public HelpController(HttpConfiguration config) + { + Configuration = config; + } + + public HttpConfiguration Configuration { get; private set; } + + public ActionResult Index() + { + ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider(); + return View(Configuration.Services.GetApiExplorer().ApiDescriptions); + } + + public ActionResult Api(string apiId) + { + if (!String.IsNullOrEmpty(apiId)) + { + HelpPageApiModel apiModel = Configuration.GetHelpPageApiModel(apiId); + if (apiModel != null) + { + return View(apiModel); + } + } + + return View(ErrorViewName); + } + + public ActionResult ResourceModel(string modelName) + { + if (!String.IsNullOrEmpty(modelName)) + { + ModelDescriptionGenerator modelDescriptionGenerator = Configuration.GetModelDescriptionGenerator(); + ModelDescription modelDescription; + if (modelDescriptionGenerator.GeneratedModels.TryGetValue(modelName, out modelDescription)) + { + return View(modelDescription); + } + } + + return View(ErrorViewName); + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPage.css b/ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPage.css new file mode 100644 index 0000000..aff2230 --- /dev/null +++ b/ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPage.css @@ -0,0 +1,134 @@ +.help-page h1, +.help-page .h1, +.help-page h2, +.help-page .h2, +.help-page h3, +.help-page .h3, +#body.help-page, +.help-page-table th, +.help-page-table pre, +.help-page-table p { + font-family: "Segoe UI Light", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif; +} + +.help-page pre.wrapped { + white-space: -moz-pre-wrap; + white-space: -pre-wrap; + white-space: -o-pre-wrap; + white-space: pre-wrap; +} + +.help-page .warning-message-container { + margin-top: 20px; + padding: 0 10px; + color: #525252; + background: #EFDCA9; + border: 1px solid #CCCCCC; +} + +.help-page-table { + width: 100%; + border-collapse: collapse; + text-align: left; + margin: 0px 0px 20px 0px; + border-top: 1px solid #D4D4D4; +} + +.help-page-table th { + text-align: left; + font-weight: bold; + border-bottom: 1px solid #D4D4D4; + padding: 5px 6px 5px 6px; +} + +.help-page-table td { + border-bottom: 1px solid #D4D4D4; + padding: 10px 8px 10px 8px; + vertical-align: top; +} + +.help-page-table pre, +.help-page-table p { + margin: 0px; + padding: 0px; + font-family: inherit; + font-size: 100%; +} + +.help-page-table tbody tr:hover td { + background-color: #F3F3F3; +} + +.help-page a:hover { + background-color: transparent; +} + +.help-page .sample-header { + border: 2px solid #D4D4D4; + background: #00497E; + color: #FFFFFF; + padding: 8px 15px; + border-bottom: none; + display: inline-block; + margin: 10px 0px 0px 0px; +} + +.help-page .sample-content { + display: block; + border-width: 0; + padding: 15px 20px; + background: #FFFFFF; + border: 2px solid #D4D4D4; + margin: 0px 0px 10px 0px; +} + +.help-page .api-name { + width: 40%; +} + +.help-page .api-documentation { + width: 60%; +} + +.help-page .parameter-name { + width: 20%; +} + +.help-page .parameter-documentation { + width: 40%; +} + +.help-page .parameter-type { + width: 20%; +} + +.help-page .parameter-annotations { + width: 20%; +} + +.help-page h1, +.help-page .h1 { + font-size: 36px; + line-height: normal; +} + +.help-page h2, +.help-page .h2 { + font-size: 24px; +} + +.help-page h3, +.help-page .h3 { + font-size: 20px; +} + +#body.help-page { + font-size: 14px; + line-height: 143%; + color: #333; +} + +.help-page a { + color: #0000EE; + text-decoration: none; +} diff --git a/ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPageAreaRegistration.cs b/ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPageAreaRegistration.cs new file mode 100644 index 0000000..a3c0ce1 --- /dev/null +++ b/ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPageAreaRegistration.cs @@ -0,0 +1,26 @@ +using System.Web.Http; +using System.Web.Mvc; + +namespace HousingWebAPI.Areas.HelpPage +{ + public class HelpPageAreaRegistration : AreaRegistration + { + public override string AreaName + { + get + { + return "HelpPage"; + } + } + + public override void RegisterArea(AreaRegistrationContext context) + { + context.MapRoute( + "HelpPage_Default", + "Help/{action}/{apiId}", + new { controller = "Help", action = "Index", apiId = UrlParameter.Optional }); + + HelpPageConfig.Register(GlobalConfiguration.Configuration); + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPageConfigurationExtensions.cs b/ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPageConfigurationExtensions.cs new file mode 100644 index 0000000..f384280 --- /dev/null +++ b/ApartmentManager/HousingWebAPI/Areas/HelpPage/HelpPageConfigurationExtensions.cs @@ -0,0 +1,467 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Web.Http; +using System.Web.Http.Controllers; +using System.Web.Http.Description; +using HousingWebAPI.Areas.HelpPage.ModelDescriptions; +using HousingWebAPI.Areas.HelpPage.Models; + +namespace HousingWebAPI.Areas.HelpPage +{ + public static class HelpPageConfigurationExtensions + { + private const string ApiModelPrefix = "MS_HelpPageApiModel_"; + + /// + /// Sets the documentation provider for help page. + /// + /// The . + /// The documentation provider. + public static void SetDocumentationProvider(this HttpConfiguration config, IDocumentationProvider documentationProvider) + { + config.Services.Replace(typeof(IDocumentationProvider), documentationProvider); + } + + /// + /// Sets the objects that will be used by the formatters to produce sample requests/responses. + /// + /// The . + /// The sample objects. + public static void SetSampleObjects(this HttpConfiguration config, IDictionary sampleObjects) + { + config.GetHelpPageSampleGenerator().SampleObjects = sampleObjects; + } + + /// + /// Sets the sample request directly for the specified media type and action. + /// + /// The . + /// The sample request. + /// The media type. + /// Name of the controller. + /// Name of the action. + public static void SetSampleRequest(this HttpConfiguration config, object sample, MediaTypeHeaderValue mediaType, string controllerName, string actionName) + { + config.GetHelpPageSampleGenerator().ActionSamples.Add(new HelpPageSampleKey(mediaType, SampleDirection.Request, controllerName, actionName, new[] { "*" }), sample); + } + + /// + /// Sets the sample request directly for the specified media type and action with parameters. + /// + /// The . + /// The sample request. + /// The media type. + /// Name of the controller. + /// Name of the action. + /// The parameter names. + public static void SetSampleRequest(this HttpConfiguration config, object sample, MediaTypeHeaderValue mediaType, string controllerName, string actionName, params string[] parameterNames) + { + config.GetHelpPageSampleGenerator().ActionSamples.Add(new HelpPageSampleKey(mediaType, SampleDirection.Request, controllerName, actionName, parameterNames), sample); + } + + /// + /// Sets the sample request directly for the specified media type of the action. + /// + /// The . + /// The sample response. + /// The media type. + /// Name of the controller. + /// Name of the action. + public static void SetSampleResponse(this HttpConfiguration config, object sample, MediaTypeHeaderValue mediaType, string controllerName, string actionName) + { + config.GetHelpPageSampleGenerator().ActionSamples.Add(new HelpPageSampleKey(mediaType, SampleDirection.Response, controllerName, actionName, new[] { "*" }), sample); + } + + /// + /// Sets the sample response directly for the specified media type of the action with specific parameters. + /// + /// The . + /// The sample response. + /// The media type. + /// Name of the controller. + /// Name of the action. + /// The parameter names. + public static void SetSampleResponse(this HttpConfiguration config, object sample, MediaTypeHeaderValue mediaType, string controllerName, string actionName, params string[] parameterNames) + { + config.GetHelpPageSampleGenerator().ActionSamples.Add(new HelpPageSampleKey(mediaType, SampleDirection.Response, controllerName, actionName, parameterNames), sample); + } + + /// + /// Sets the sample directly for all actions with the specified media type. + /// + /// The . + /// The sample. + /// The media type. + public static void SetSampleForMediaType(this HttpConfiguration config, object sample, MediaTypeHeaderValue mediaType) + { + config.GetHelpPageSampleGenerator().ActionSamples.Add(new HelpPageSampleKey(mediaType), sample); + } + + /// + /// Sets the sample directly for all actions with the specified type and media type. + /// + /// The . + /// The sample. + /// The media type. + /// The parameter type or return type of an action. + public static void SetSampleForType(this HttpConfiguration config, object sample, MediaTypeHeaderValue mediaType, Type type) + { + config.GetHelpPageSampleGenerator().ActionSamples.Add(new HelpPageSampleKey(mediaType, type), sample); + } + + /// + /// Specifies the actual type of passed to the in an action. + /// The help page will use this information to produce more accurate request samples. + /// + /// The . + /// The type. + /// Name of the controller. + /// Name of the action. + public static void SetActualRequestType(this HttpConfiguration config, Type type, string controllerName, string actionName) + { + config.GetHelpPageSampleGenerator().ActualHttpMessageTypes.Add(new HelpPageSampleKey(SampleDirection.Request, controllerName, actionName, new[] { "*" }), type); + } + + /// + /// Specifies the actual type of passed to the in an action. + /// The help page will use this information to produce more accurate request samples. + /// + /// The . + /// The type. + /// Name of the controller. + /// Name of the action. + /// The parameter names. + public static void SetActualRequestType(this HttpConfiguration config, Type type, string controllerName, string actionName, params string[] parameterNames) + { + config.GetHelpPageSampleGenerator().ActualHttpMessageTypes.Add(new HelpPageSampleKey(SampleDirection.Request, controllerName, actionName, parameterNames), type); + } + + /// + /// Specifies the actual type of returned as part of the in an action. + /// The help page will use this information to produce more accurate response samples. + /// + /// The . + /// The type. + /// Name of the controller. + /// Name of the action. + public static void SetActualResponseType(this HttpConfiguration config, Type type, string controllerName, string actionName) + { + config.GetHelpPageSampleGenerator().ActualHttpMessageTypes.Add(new HelpPageSampleKey(SampleDirection.Response, controllerName, actionName, new[] { "*" }), type); + } + + /// + /// Specifies the actual type of returned as part of the in an action. + /// The help page will use this information to produce more accurate response samples. + /// + /// The . + /// The type. + /// Name of the controller. + /// Name of the action. + /// The parameter names. + public static void SetActualResponseType(this HttpConfiguration config, Type type, string controllerName, string actionName, params string[] parameterNames) + { + config.GetHelpPageSampleGenerator().ActualHttpMessageTypes.Add(new HelpPageSampleKey(SampleDirection.Response, controllerName, actionName, parameterNames), type); + } + + /// + /// Gets the help page sample generator. + /// + /// The . + /// The help page sample generator. + public static HelpPageSampleGenerator GetHelpPageSampleGenerator(this HttpConfiguration config) + { + return (HelpPageSampleGenerator)config.Properties.GetOrAdd( + typeof(HelpPageSampleGenerator), + k => new HelpPageSampleGenerator()); + } + + /// + /// Sets the help page sample generator. + /// + /// The . + /// The help page sample generator. + public static void SetHelpPageSampleGenerator(this HttpConfiguration config, HelpPageSampleGenerator sampleGenerator) + { + config.Properties.AddOrUpdate( + typeof(HelpPageSampleGenerator), + k => sampleGenerator, + (k, o) => sampleGenerator); + } + + /// + /// Gets the model description generator. + /// + /// The configuration. + /// The + public static ModelDescriptionGenerator GetModelDescriptionGenerator(this HttpConfiguration config) + { + return (ModelDescriptionGenerator)config.Properties.GetOrAdd( + typeof(ModelDescriptionGenerator), + k => InitializeModelDescriptionGenerator(config)); + } + + /// + /// Gets the model that represents an API displayed on the help page. The model is initialized on the first call and cached for subsequent calls. + /// + /// The . + /// The ID. + /// + /// An + /// + public static HelpPageApiModel GetHelpPageApiModel(this HttpConfiguration config, string apiDescriptionId) + { + object model; + string modelId = ApiModelPrefix + apiDescriptionId; + if (!config.Properties.TryGetValue(modelId, out model)) + { + Collection apiDescriptions = config.Services.GetApiExplorer().ApiDescriptions; + ApiDescription apiDescription = apiDescriptions.FirstOrDefault(api => String.Equals(api.GetFriendlyId(), apiDescriptionId, StringComparison.OrdinalIgnoreCase)); + if (apiDescription != null) + { + model = GenerateApiModel(apiDescription, config); + config.Properties.TryAdd(modelId, model); + } + } + + return (HelpPageApiModel)model; + } + + private static HelpPageApiModel GenerateApiModel(ApiDescription apiDescription, HttpConfiguration config) + { + HelpPageApiModel apiModel = new HelpPageApiModel() + { + ApiDescription = apiDescription, + }; + + ModelDescriptionGenerator modelGenerator = config.GetModelDescriptionGenerator(); + HelpPageSampleGenerator sampleGenerator = config.GetHelpPageSampleGenerator(); + GenerateUriParameters(apiModel, modelGenerator); + GenerateRequestModelDescription(apiModel, modelGenerator, sampleGenerator); + GenerateResourceDescription(apiModel, modelGenerator); + GenerateSamples(apiModel, sampleGenerator); + + return apiModel; + } + + private static void GenerateUriParameters(HelpPageApiModel apiModel, ModelDescriptionGenerator modelGenerator) + { + ApiDescription apiDescription = apiModel.ApiDescription; + foreach (ApiParameterDescription apiParameter in apiDescription.ParameterDescriptions) + { + if (apiParameter.Source == ApiParameterSource.FromUri) + { + HttpParameterDescriptor parameterDescriptor = apiParameter.ParameterDescriptor; + Type parameterType = null; + ModelDescription typeDescription = null; + ComplexTypeModelDescription complexTypeDescription = null; + if (parameterDescriptor != null) + { + parameterType = parameterDescriptor.ParameterType; + typeDescription = modelGenerator.GetOrCreateModelDescription(parameterType); + complexTypeDescription = typeDescription as ComplexTypeModelDescription; + } + + // Example: + // [TypeConverter(typeof(PointConverter))] + // public class Point + // { + // public Point(int x, int y) + // { + // X = x; + // Y = y; + // } + // public int X { get; set; } + // public int Y { get; set; } + // } + // Class Point is bindable with a TypeConverter, so Point will be added to UriParameters collection. + // + // public class Point + // { + // public int X { get; set; } + // public int Y { get; set; } + // } + // Regular complex class Point will have properties X and Y added to UriParameters collection. + if (complexTypeDescription != null + && !IsBindableWithTypeConverter(parameterType)) + { + foreach (ParameterDescription uriParameter in complexTypeDescription.Properties) + { + apiModel.UriParameters.Add(uriParameter); + } + } + else if (parameterDescriptor != null) + { + ParameterDescription uriParameter = + AddParameterDescription(apiModel, apiParameter, typeDescription); + + if (!parameterDescriptor.IsOptional) + { + uriParameter.Annotations.Add(new ParameterAnnotation() { Documentation = "Required" }); + } + + object defaultValue = parameterDescriptor.DefaultValue; + if (defaultValue != null) + { + uriParameter.Annotations.Add(new ParameterAnnotation() { Documentation = "Default value is " + Convert.ToString(defaultValue, CultureInfo.InvariantCulture) }); + } + } + else + { + Debug.Assert(parameterDescriptor == null); + + // If parameterDescriptor is null, this is an undeclared route parameter which only occurs + // when source is FromUri. Ignored in request model and among resource parameters but listed + // as a simple string here. + ModelDescription modelDescription = modelGenerator.GetOrCreateModelDescription(typeof(string)); + AddParameterDescription(apiModel, apiParameter, modelDescription); + } + } + } + } + + private static bool IsBindableWithTypeConverter(Type parameterType) + { + if (parameterType == null) + { + return false; + } + + return TypeDescriptor.GetConverter(parameterType).CanConvertFrom(typeof(string)); + } + + private static ParameterDescription AddParameterDescription(HelpPageApiModel apiModel, + ApiParameterDescription apiParameter, ModelDescription typeDescription) + { + ParameterDescription parameterDescription = new ParameterDescription + { + Name = apiParameter.Name, + Documentation = apiParameter.Documentation, + TypeDescription = typeDescription, + }; + + apiModel.UriParameters.Add(parameterDescription); + return parameterDescription; + } + + private static void GenerateRequestModelDescription(HelpPageApiModel apiModel, ModelDescriptionGenerator modelGenerator, HelpPageSampleGenerator sampleGenerator) + { + ApiDescription apiDescription = apiModel.ApiDescription; + foreach (ApiParameterDescription apiParameter in apiDescription.ParameterDescriptions) + { + if (apiParameter.Source == ApiParameterSource.FromBody) + { + Type parameterType = apiParameter.ParameterDescriptor.ParameterType; + apiModel.RequestModelDescription = modelGenerator.GetOrCreateModelDescription(parameterType); + apiModel.RequestDocumentation = apiParameter.Documentation; + } + else if (apiParameter.ParameterDescriptor != null && + apiParameter.ParameterDescriptor.ParameterType == typeof(HttpRequestMessage)) + { + Type parameterType = sampleGenerator.ResolveHttpRequestMessageType(apiDescription); + + if (parameterType != null) + { + apiModel.RequestModelDescription = modelGenerator.GetOrCreateModelDescription(parameterType); + } + } + } + } + + private static void GenerateResourceDescription(HelpPageApiModel apiModel, ModelDescriptionGenerator modelGenerator) + { + ResponseDescription response = apiModel.ApiDescription.ResponseDescription; + Type responseType = response.ResponseType ?? response.DeclaredType; + if (responseType != null && responseType != typeof(void)) + { + apiModel.ResourceDescription = modelGenerator.Ge