init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
16
KretaWeb/Helpers/Error/KretaError.cs
Normal file
16
KretaWeb/Helpers/Error/KretaError.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Web.Helpers.Error
|
||||
{
|
||||
public class KretaError : Exception
|
||||
{
|
||||
public KretaError(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class KretaMissingTanoraException : Exception
|
||||
{
|
||||
public KretaMissingTanoraException(string message) : base(message) { }
|
||||
}
|
||||
}
|
47
KretaWeb/Helpers/Error/MVCModelState.cs
Normal file
47
KretaWeb/Helpers/Error/MVCModelState.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Kreta.Web.Helpers.Error
|
||||
{
|
||||
public static class ModelStateExtensions
|
||||
{
|
||||
public class MvcModelState
|
||||
{
|
||||
public MvcModelState()
|
||||
{
|
||||
MVCModelState = new List<Error>();
|
||||
}
|
||||
public List<Error> MVCModelState { get; set; }
|
||||
}
|
||||
|
||||
public class Error
|
||||
{
|
||||
public Error(string key, string message)
|
||||
{
|
||||
Key = key;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public string Key { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
public static MvcModelState AllErrors(this ModelStateDictionary modelState)
|
||||
{
|
||||
var result = new MvcModelState();
|
||||
var erroneousFields = modelState.Where(ms => ms.Value.Errors.Any())
|
||||
.Select(x => new { x.Key, x.Value.Errors });
|
||||
|
||||
foreach (var erroneousField in erroneousFields)
|
||||
{
|
||||
var fieldKey = erroneousField.Key;
|
||||
var fieldErrors = erroneousField.Errors
|
||||
.Select(error => new Error(fieldKey, error.ErrorMessage));
|
||||
result.MVCModelState.AddRange(fieldErrors);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
78
KretaWeb/Helpers/Error/StatusError.cs
Normal file
78
KretaWeb/Helpers/Error/StatusError.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Web.Routing;
|
||||
using Kreta.Enums.ManualEnums;
|
||||
|
||||
namespace Kreta.Web.Helpers.Error
|
||||
{
|
||||
public class StatusError : Exception
|
||||
{
|
||||
public int StatusCode { get; private set; }
|
||||
public object Json { get; set; }
|
||||
public Exception UnHandledException { get; set; }
|
||||
public RouteValueDictionary Redirect { get; set; }
|
||||
public string CloseFunction { get; set; }
|
||||
|
||||
public StatusError(int statusCode, string message) : base(message)
|
||||
{
|
||||
this.StatusCode = statusCode;
|
||||
}
|
||||
|
||||
public StatusError(HttpStatusCode statusCode, string message) : base(message)
|
||||
{
|
||||
this.StatusCode = (int)statusCode;
|
||||
}
|
||||
|
||||
public StatusError(CustomHTTPStatusEnum statusCode, string message) : base(message)
|
||||
{
|
||||
this.StatusCode = (int)statusCode;
|
||||
}
|
||||
|
||||
public StatusError(HttpStatusCode statusCode, string message, Exception ex) : base(message)
|
||||
{
|
||||
this.StatusCode = (int)statusCode;
|
||||
UnHandledException = ex;
|
||||
}
|
||||
}
|
||||
|
||||
public class ErrorModel
|
||||
{
|
||||
public ErrorModel()
|
||||
{
|
||||
IsStatusError = true;
|
||||
}
|
||||
|
||||
public bool IsStatusError { get; set; }
|
||||
public string Message { get; set; }
|
||||
public object Json { get; set; }
|
||||
public int Status { get; set; }
|
||||
public bool IsMvc { get; set; }
|
||||
public Guid? ErrorCode { get; set; }
|
||||
public string CloseFunction { get; set; }
|
||||
}
|
||||
|
||||
public class ClientErrorModel
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public string URL { get; set; }
|
||||
public string Line { get; set; }
|
||||
public string Column { get; set; }
|
||||
public string Error { get; set; }
|
||||
public string StackTrace { get; set; }
|
||||
public string Agent { get; set; }
|
||||
}
|
||||
|
||||
public class ClientError : Exception
|
||||
{
|
||||
public ClientError(ClientErrorModel model) : base(model.Message)
|
||||
{
|
||||
this.Data.Add("Line", model.Line);
|
||||
this.Data.Add("Column", model.Column);
|
||||
this.Data.Add("Error", model.Error);
|
||||
this.Data.Add("URL", model.URL);
|
||||
this.Data.Add("Agent", model.Agent);
|
||||
this.Data.Add("StackTrace", model.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
17
KretaWeb/Helpers/Error/StatusErrorFactory.cs
Normal file
17
KretaWeb/Helpers/Error/StatusErrorFactory.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Net;
|
||||
|
||||
namespace Kreta.Web.Helpers.Error
|
||||
{
|
||||
public static class StatusErrorFactory
|
||||
{
|
||||
public static StatusError GetSorolasStatusErrorWithReloadDDL(string message)
|
||||
{
|
||||
return new StatusError(HttpStatusCode.BadRequest, message) { CloseFunction = "KretaOsztalybaSorolasHelper.afterErrorReloadDDL();" };
|
||||
}
|
||||
|
||||
public static StatusError GetSorolasStatusError(string message)
|
||||
{
|
||||
return new StatusError(HttpStatusCode.BadRequest, message);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue