diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/.template.config/dotnetcli.host.json b/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/.template.config/dotnetcli.host.json new file mode 100644 index 000000000000..94f4ee10148d --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/.template.config/dotnetcli.host.json @@ -0,0 +1,3 @@ +{ + "$schema": "http://json.schemastore.org/dotnetcli.host" +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/.template.config/localize/templatestrings.en.json b/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/.template.config/localize/templatestrings.en.json new file mode 100644 index 000000000000..5046461e45b8 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/.template.config/localize/templatestrings.en.json @@ -0,0 +1,9 @@ +{ + "author": "Microsoft", + "name": "API Controller", + "description": "API Controller with or without read/write actions", + "symbols/namespace/description": "namespace for the generated code", + "symbols/actions/description": "create controller with read/write actions", + "symbols/actions/displayName": "Add ReadWrite Actions", + "postActions/openInEditor/description": "Opens ValueController.cs in the editor" +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/.template.config/template.json b/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/.template.config/template.json new file mode 100644 index 000000000000..b2cf79254082 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/.template.config/template.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "Microsoft", + "classifications": [ "Web", "ASP.NET" ], + "name": "API Controller", + "generatorVersions": "[1.0.0.0-*)", + "description": "API Controller with or without read/write actions", + "tags": { + "language": "C#", + "type": "item" + }, + "groupIdentity": "Microsoft.AspNetCore.Mvc.ApiController", + "precedence": "9800", + "identity": "Microsoft.AspNetCore.Mvc.ApiController.8.0", + "shortName": "apicontroller", + "sourceName": "ValueController", + "primaryOutputs": [ + { + "path": "ValueController.cs" + } + ], + "defaultName": "ValueController", + "symbols": { + "namespace": { + "description": "namespace for the generated code", + "replaces": "MyApp.Namespace", + "type": "parameter" + }, + "actions": { + "description": "create controller with read/write actions", + "displayName": "Add ReadWrite Actions", + "type": "parameter", + "datatype": "bool", + "defaultValue": "false" + }, + "HostIdentifier": { + "type": "bind", + "binding": "HostIdentifier" + }, + "NameIsController": { + "type": "computed", + "value": "(name == \"ControllerBase\")" + } + }, + "postActions": [ + { + "id": "openInEditor", + "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", + "description": "Opens the created controller in the editor", + "manualInstructions": [ ], + "actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", + "args": { + "files": "0" + }, + "continueOnError": true + } + ] +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/ValueController.cs b/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/ValueController.cs new file mode 100644 index 000000000000..e6a4670ed470 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/ApiController/ValueController.cs @@ -0,0 +1,48 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace MyApp.Namespace +{ + [Route("api/[controller]")] + [ApiController] + #if NameIsController + public class ValuesController : Microsoft.AspNetCore.Mvc.ControllerBase + #else + public class ValuesController : ControllerBase + #endif + { + #if(actions) + // GET: api/ + [HttpGet] + public IEnumerable Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api//5 + [HttpGet("{id}")] + public string Get(int id) + { + return "value"; + } + + // POST api/ + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api//5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api//5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + #endif + } +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/.template.config/dotnetcli.host.json b/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/.template.config/dotnetcli.host.json new file mode 100644 index 000000000000..94f4ee10148d --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/.template.config/dotnetcli.host.json @@ -0,0 +1,3 @@ +{ + "$schema": "http://json.schemastore.org/dotnetcli.host" +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/.template.config/localize/templatestrings.en.json b/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/.template.config/localize/templatestrings.en.json new file mode 100644 index 000000000000..34e6bebd0542 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/.template.config/localize/templatestrings.en.json @@ -0,0 +1,9 @@ +{ + "author": "Microsoft", + "name": "MVC Controller", + "description": "MVC Controller with or without read/write actions", + "symbols/namespace/description": "namespace for the generated code", + "symbols/actions/description": "create controller with read/write actions", + "symbols/actions/displayName": "Add ReadWrite Actions", + "postActions/openInEditor/description": "Opens HomeController.cs in the editor" +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/.template.config/template.json b/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/.template.config/template.json new file mode 100644 index 000000000000..92917953eab3 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/.template.config/template.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "Microsoft", + "classifications": [ "Web", "ASP.NET" ], + "name": "MVC Controller", + "generatorVersions": "[1.0.0.0-*)", + "description": "MVC Controller with or without read/write actions", + "tags": { + "language": "C#", + "type": "item" + }, + "groupIdentity": "Microsoft.AspNetCore.Mvc.MvcController", + "precedence": "9800", + "identity": "Microsoft.AspNetCore.Mvc.MvcController.8.0", + "shortName": "mvccontroller", + "sourceName": "HomeController", + "primaryOutputs": [ + { + "path": "HomeController.cs" + } + ], + "defaultName": "HomeController", + "symbols": { + "namespace": { + "description": "namespace for the generated code", + "replaces": "MyApp.Namespace", + "type": "parameter" + }, + "actions": { + "description": "create controller with read/write actions", + "displayName": "Add ReadWrite Actions", + "type": "parameter", + "datatype": "bool", + "defaultValue": "false" + }, + "HostIdentifier": { + "type": "bind", + "binding": "HostIdentifier" + }, + "NameIsController": { + "type": "computed", + "value": "(name == \"Controller\")" + } + }, + "postActions": [ + { + "id": "openInEditor", + "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", + "description": "Opens the created controller in the editor", + "manualInstructions": [ ], + "actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", + "args": { + "files": "0" + }, + "continueOnError": true + } + ] +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/HomeController.cs b/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/HomeController.cs new file mode 100644 index 000000000000..470119f928f6 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/MvcController/HomeController.cs @@ -0,0 +1,88 @@ +using Microsoft.AspNetCore.Mvc; + +namespace MyApp.Namespace +{ + #if NameIsController + public class HomeController : Microsoft.AspNetCore.Mvc.Controller + #else + public class HomeController : Controller + #endif + { + // GET: HomeController + public ActionResult Index() + { + return View(); + } + + #if(actions) + // GET: HomeController/Details/5 + public ActionResult Details(int id) + { + return View(); + } + + // GET: HomeController/Create + public ActionResult Create() + { + return View(); + } + + // POST: HomeController/Create + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Create(IFormCollection collection) + { + try + { + return RedirectToAction(nameof(Index)); + } + catch + { + return View(); + } + } + + // GET: HomeController/Edit/5 + public ActionResult Edit(int id) + { + return View(); + } + + // POST: HomeController/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Edit(int id, IFormCollection collection) + { + try + { + return RedirectToAction(nameof(Index)); + } + catch + { + return View(); + } + } + + // GET: HomeController/Delete/5 + public ActionResult Delete(int id) + { + return View(); + } + + // POST: HomeController/Delete/5 + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Delete(int id, IFormCollection collection) + { + try + { + return RedirectToAction(nameof(Index)); + } + catch + { + return View(); + } + } + #endif + } +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/dotnetcli.host.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/dotnetcli.host.json new file mode 100644 index 000000000000..94f4ee10148d --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/dotnetcli.host.json @@ -0,0 +1,3 @@ +{ + "$schema": "http://json.schemastore.org/dotnetcli.host" +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/localize/templatestrings.en.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/localize/templatestrings.en.json new file mode 100644 index 000000000000..4035fb703792 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/localize/templatestrings.en.json @@ -0,0 +1,6 @@ +{ + "author": "Microsoft", + "name": "Razor View", + "description": "A Razor view without a page model", + "postActions/openInEditor/description": "Opens Index.cshtml in the editor" +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/template.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/template.json new file mode 100644 index 000000000000..602f10bc76c1 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/template.json @@ -0,0 +1,40 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "Microsoft", + "classifications": [ "Web", "ASP.NET" ], + "name": "Razor View", + "generatorVersions": "[1.0.0.0-*)", + "description": "Am empty razor view", + "tags": { + "language": "C#", + "type": "item" + }, + "groupIdentity": "Microsoft.AspNetCore.Mvc.RazorView", + "precedence": "9800", + "identity": "Microsoft.AspNetCore.Mvc.RazorView.8.0", + "shortName": "view", + "sourceName": "Index", + "primaryOutputs": [ + { "path": "Index.cshtml" } + ], + "defaultName": "Index", + "symbols": { + "HostIdentifier": { + "type": "bind", + "binding": "HostIdentifier" + } + }, + "postActions": [ + { + "id": "openInEditor", + "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", + "description": "Opens the created view in the editor", + "manualInstructions": [ ], + "actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", + "args": { + "files": "0" + }, + "continueOnError": true + } + ] +} diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/Index.cshtml b/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/Index.cshtml new file mode 100644 index 000000000000..e1dd794fdb1c --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorView/Index.cshtml @@ -0,0 +1,5 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ +}