public static void ResolveErrors(this IServiceErrorsProvider serviceErrorsProvider, ModelStateDictionary modelState) { if (modelState == null) { throw new ArgumentNullException(); } Contract.EndContractBlock(); if (serviceErrorsProvider.HasValidationError) { var validationErrors = serviceErrorsProvider.GetValidationErrors(); foreach (var error in validationErrors) { modelState.AddModelError(error.Key, error.Value); } } if (!string.IsNullOrEmpty(serviceErrorsProvider.ExceptionMessage)) { modelState.AddModelError("Exception", serviceErrorsProvider.ExceptionMessage); } }
public static void ResolveErrors(this IServiceErrorsProvider errorsProvider, Dictionary <string, string> validationDictionary, Action <string> exceptionMessageDelegate) { if (validationDictionary == null) { throw new ArgumentNullException(); } Contract.EndContractBlock(); if (errorsProvider.HasValidationError) { var errors = errorsProvider.GetValidationErrors(); foreach (var error in errors) { if (!validationDictionary.ContainsKey(error.Key)) { validationDictionary.Add(error.Key, error.Value); } } } if (!string.IsNullOrEmpty(errorsProvider.ExceptionMessage)) { exceptionMessageDelegate?.Invoke(errorsProvider.ExceptionMessage); } }