diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-05-13 15:35:57 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-05-13 15:35:57 +0300 |
| commit | 2a07c006a1f7ea9a7493af4f114300a829f4dc6f (patch) | |
| tree | e21797f9da2e71b9d4589e1b2d6a846b5fa917e0 | |
| parent | 1bf0c255644e18dea50018a7d425ddf7c220ac91 (diff) | |
| download | it-kariera-exam-template-2a07c006a1f7ea9a7493af4f114300a829f4dc6f.tar it-kariera-exam-template-2a07c006a1f7ea9a7493af4f114300a829f4dc6f.tar.gz it-kariera-exam-template-2a07c006a1f7ea9a7493af4f114300a829f4dc6f.zip | |
Added view error messages to unsuccessful creation and edit of an object in form feature script
| -rwxr-xr-x | tools/add-feature-template.sh | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/add-feature-template.sh b/tools/add-feature-template.sh index 3a8695b..51f1990 100755 --- a/tools/add-feature-template.sh +++ b/tools/add-feature-template.sh @@ -274,6 +274,13 @@ done <input type="submit" value="Create"> </form> + +@if (Model != null) +{ + <p class="form-error"> + Couldn't create ${feature_name}! + </p> +} EOF cat > $subdir/Edit.cshtml<< EOF @@ -294,6 +301,13 @@ done <input type="submit" value="Edit"> </form> + +@if (Model != null) +{ + <p class="form-error"> + Couldn't edit ${feature_name}! + </p> +} EOF cat > $subdir/Delete.cshtml<< EOF @@ -373,6 +387,9 @@ namespace $project_name.Web.Controllers [HttpPost] public async Task<IActionResult> Create(Create${feature_name}WebModel webModel) { + if (!ModelState.IsValid) + return View(editUserViewModel); + ${feature_name}ServiceModel serviceModel = this._autoMapper.Map<${feature_name}ServiceModel>(webModel); bool result = await this._service.CreateAsync(serviceModel); @@ -395,6 +412,9 @@ namespace $project_name.Web.Controllers [HttpPost] public async Task<IActionResult> Edit(Edit${feature_name}WebModel webModel) { + if (!ModelState.IsValid) + return View(webModel); + ${feature_name}ServiceModel serviceModel = this._autoMapper.Map<${feature_name}ServiceModel>(webModel); bool result = await this._service.EditAsync(serviceModel); |
