Content-Length: 480142 | pFad | http://github.com/coderserdar/WeatherStackNetCore/commit/ad4dd52c0c17ee9cf52dd070224160dca9a2e8e7

EE Model Validation has been done with an attribute and source code has … · coderserdar/WeatherStackNetCore@ad4dd52 · GitHub
Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ad4dd52

Browse files
committedApr 5, 2023
Model Validation has been done with an attribute and source code has been updated with the new way
1 parent f643c70 commit ad4dd52

16 files changed

+26
-3
lines changed
 
Binary file not shown.
Binary file not shown.

‎SourceCode/WeatherStackNetCore/Controllers/AutoCompleteController.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ public IActionResult IndexWithModel(AutoCompleteViewModel? model)
7575
//github.com/ <param name="model">Location Search Page Elements</param>
7676
//github.com/ <returns>Result Page</returns>
7777
[HttpPost]
78+
[ValidateModel]
7879
public async Task<IActionResult> GetLocationsWithModel(AutoCompleteViewModel model)
7980
{
8081
try
8182
{
82-
if (!ModelState.IsValid) return View("IndexWithModel", model);
83+
// if (!ModelState.IsValid) return View("IndexWithModel", model);
8384

8485
var autoComplete = await CallAutoCompleteFromAPI(model.PlaceName);
8586

‎SourceCode/WeatherStackNetCore/Controllers/CurrentWeatherController.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ public IActionResult IndexWithModel(CurrentWeatherViewModel? model)
7777
//github.com/ <param name="model">Current Weather Search Page Elements</param>
7878
//github.com/ <returns>Result Page</returns>
7979
[HttpPost]
80+
[ValidateModel]
8081
public async Task<IActionResult> GetCurrentWeatherWithModel(CurrentWeatherViewModel model)
8182
{
8283
try
8384
{
84-
if (!ModelState.IsValid) return View("IndexWithModel", model);
85+
// if (!ModelState.IsValid) return View("IndexWithModel", model);
8586

8687
var currentWeather = await GetCurrentWeatherFromAPI(model.PlaceName, model.Unit, model.Language);
8788

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.Filters;
3+
4+
namespace WeatherStackNetCore.Utils;
5+
6+
//github.com/ <summary>
7+
//github.com/ Model Validation Attribute Class
8+
//github.com/ </summary>
9+
public class ValidateModelAttribute : ActionFilterAttribute
10+
{
11+
//github.com/ <summary>
12+
//github.com/ In this method, if model is not valid
13+
//github.com/ App sends automatically bad request
14+
//github.com/ </summary>
15+
//github.com/ <param name="context">Context Info</param>
16+
public override void OnActionExecuting(ActionExecutingContext context)
17+
{
18+
if (!context.ModelState.IsValid)
19+
context.Result = new BadRequestResult();
20+
}
21+
}
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5300ac7f6b00b873d53bec5906d9fd96c024f011
1+
41acd01dd78252a159bc2235c4bb70e8548fb52f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)
Failed to load comments.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/coderserdar/WeatherStackNetCore/commit/ad4dd52c0c17ee9cf52dd070224160dca9a2e8e7

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy