init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
41
KretaWeb/Helpers/ModelStateDictionaryExtenstions.cs
Normal file
41
KretaWeb/Helpers/ModelStateDictionaryExtenstions.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System.Linq;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Web.Helpers
|
||||
{
|
||||
public static class ModelStateDictionaryExtenstions
|
||||
{
|
||||
public static void AddModelStateErrorsFromString(this ModelStateDictionary modelState, string errors)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(errors))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var errorContent = JsonConvert.DeserializeObject<HttpClientErrorContent>(errors);
|
||||
|
||||
if (errorContent != null)
|
||||
{
|
||||
var errorList = errorContent.Message.Split(';');
|
||||
if (errorList.Any())
|
||||
{
|
||||
int i = 1;
|
||||
foreach (var error in errorList)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
modelState.AddModelError(i.ToString(), error);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class HttpClientErrorContent
|
||||
{
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue