Esempio n. 1
0
 /// <summary>
 /// Maps the violations.
 /// </summary>
 /// <param name="dto">The dto that is associated with the rule violations.</param>
 /// <param name="ruleViolations">The rule violations.</param>
 public static void MapViolations(this AbstractDataTransferObject dto, IEnumerable <RuleViolation> ruleViolations)
 {
     foreach (var ruleViolation in ruleViolations)
     {
         dto.AddDataErrorInfo(new DataErrorInfo(ruleViolation.Message, ErrorLevel.Error, ruleViolation.PropertyNames));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Maps the exception to <see cref="DataErrorInfo"/>.
        /// </summary>
        /// <param name="dto">
        /// The dto to which the <see cref="DataErrorInfo"/> belongs. 
        /// </param>
        /// <param name="exception">
        /// The exception. 
        /// </param>
        public static void MapExceptionToDataErrorInfo(
            AbstractDataTransferObject dto, 
            Exception exception )
        {
            DataErrorInfo error;
            if ( exception is ArgumentException )
            {
                string propertyName = ( exception as ArgumentException ).ParamName;

                var hasProperty = !string.IsNullOrEmpty ( propertyName ) && dto.GetType ().GetProperty ( propertyName ) != null;

                error = hasProperty
                            ? new DataErrorInfo ( exception.Message, ErrorLevel.Error, propertyName )
                            : new DataErrorInfo ( exception.Message, ErrorLevel.Error );
            }
            else
            {
                error = new DataErrorInfo ( exception.Message, ErrorLevel.Error );
            }

            dto.AddDataErrorInfo ( error );
        }
Esempio n. 3
0
        /// <summary>
        /// Maps the exception to <see cref="DataErrorInfo"/>.
        /// </summary>
        /// <param name="dto">
        /// The dto to which the <see cref="DataErrorInfo"/> belongs.
        /// </param>
        /// <param name="exception">
        /// The exception.
        /// </param>
        public static void MapExceptionToDataErrorInfo(
            AbstractDataTransferObject dto,
            Exception exception)
        {
            DataErrorInfo error;

            if (exception is ArgumentException)
            {
                string propertyName = (exception as ArgumentException).ParamName;

                var hasProperty = !string.IsNullOrEmpty(propertyName) && dto.GetType().GetProperty(propertyName) != null;

                error = hasProperty
                            ? new DataErrorInfo(exception.Message, ErrorLevel.Error, propertyName)
                            : new DataErrorInfo(exception.Message, ErrorLevel.Error);
            }
            else
            {
                error = new DataErrorInfo(exception.Message, ErrorLevel.Error);
            }

            dto.AddDataErrorInfo(error);
        }