From db5be8683405cbe6c76443a90e1f6cb93dde2346 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 13 May 2021 15:23:01 +0300 Subject: Updated add feature script such that Index.cshtml shows all available objects in database and Details.cshtml shows everything about a particular object --- tools/add-feature-template.sh | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/add-feature-template.sh b/tools/add-feature-template.sh index e5433f3..dd3d764 100755 --- a/tools/add-feature-template.sh +++ b/tools/add-feature-template.sh @@ -224,6 +224,26 @@ subdir="$dir/Views/$feature_name" mkdir -p $subdir cat > $subdir/Index.cshtml<< EOF +@model IEnumerable<${feature_name}WebModel> +@{ + ViewData["Title"] = "${feature_name}s"; +} + +
+ @foreach (var item in Model) + { +
+$( +for feature in "${features[@]}"; do +echo -e "\t\t\t
\n\t\t\t\t@item.$(echo $feature | cut -d ' ' -f 2-)\n\t\t\t
" +done +) +
+ } +
+EOF + +cat > $subdir/Details.cshtml<< EOF @model ${feature_name}WebModel @{ ViewData["Title"] = "$feature_name"; @@ -307,6 +327,8 @@ using $project_name.Services.Interfaces; using $project_name.Services.Models.$feature_name; using $project_name.Web.Models.$feature_name; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Linq; namespace $project_name.Web.Controllers { @@ -322,7 +344,18 @@ namespace $project_name.Web.Controllers } [HttpGet] - public async Task Index(string id) + public async Task Index() + { + List<${feature_name}ServiceModel> serviceModels = await this._service.GetAllAsync(); + + List<${feature_name}WebModel> webModel = serviceModels + .Select(x => this._autoMapper.Map<${feature_name}WebModel>(x)) + .ToList(); + return View(webModel); + } + + [HttpGet] + public async Task Details(string id) { ${feature_name}ServiceModel serviceModel = await this._service.GetByIdAsync(Guid.Parse(id)); @@ -333,6 +366,7 @@ namespace $project_name.Web.Controllers return View(webModel); } + [HttpGet] public IActionResult Create() { -- cgit v1.2.3