From 2a07c006a1f7ea9a7493af4f114300a829f4dc6f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 13 May 2021 15:35:57 +0300 Subject: Added view error messages to unsuccessful creation and edit of an object in form feature script --- tools/add-feature-template.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tools/add-feature-template.sh') 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 + +@if (Model != null) +{ +

+ Couldn't create ${feature_name}! +

+} EOF cat > $subdir/Edit.cshtml<< EOF @@ -294,6 +301,13 @@ done + +@if (Model != null) +{ +

+ Couldn't edit ${feature_name}! +

+} EOF cat > $subdir/Delete.cshtml<< EOF @@ -373,6 +387,9 @@ namespace $project_name.Web.Controllers [HttpPost] public async Task 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 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); -- cgit v1.2.3