public override void RaiseValidationFailedEvent(
            string displayMessage = null, ValidationFailedEventArgs.FlashLevelType severity = ValidationFailedEventArgs.FlashLevelType.Error)
        {
            this.ValidationEventHasFired = true;

            Console.WriteLine("RaiseValidationFailedEvent fired");

            foreach (var validationRule in this.GetFailures().Where(x => !string.IsNullOrWhiteSpace(x.Message)))
            {
                Console.WriteLine(validationRule.Message);
            }

            TestValidationHelper.Write(this.GetFailures());
        }
Ejemplo n.º 2
0
 public virtual void RaiseValidationFailedEvent(
     string displayMessage = null,
     ValidationFailedEventArgs.FlashLevelType severity = ValidationFailedEventArgs.FlashLevelType.Error)
 {
     // It is possible that there are no subscribers if the repository is not run from a controller implementing IUseGeneralBroker.
     if (this.ValidationFailedEvent != null)
     {
         this.ValidationFailedEvent(this, new ValidationFailedEventArgs(displayMessage, severity));
     }
     else
     {
         // IMPROVE: Log
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        ///   Is subscribed to the EventBroker validation failed event. 
        ///   Pushes failures to the View.
        /// </summary>
        protected void ValidationFailedEvent(object sender, ValidationFailedEventArgs eventArgs)
        {
            this.AddValidationErrorToModelState(this._eventBroker.GetFailures());

            foreach (var failure in this.EventBroker.GetFailures().Where(x => x.Exception != null))
            {
                this.WriteExceptionToModelState(failure.Exception, 1);
            }

            // Don't display message in flash if the key is set
            if (eventArgs.HasMessage && string.IsNullOrWhiteSpace(eventArgs.Key))
            {
                switch (eventArgs.FlashLevel)
                {
                    case ValidationFailedEventArgs.FlashLevelType.Error:
                        this.FlashError(eventArgs.DisplayMessage);
                        break;
                    case ValidationFailedEventArgs.FlashLevelType.Warning:
                        this.FlashWarning(eventArgs.DisplayMessage);
                        break;
                    case ValidationFailedEventArgs.FlashLevelType.Info:
                        this.FlashInfo(eventArgs.DisplayMessage);
                        break;
                }
            }
            else
            {
                this.FlashError("Validation Error");

                // IMPROVE: This is likely problematic.
                // it works for partials where the validation does not match, but will display these extra messages
                // even when the model state matches.
                foreach (var failure in this.EventBroker.GetFailures().Where(x => !string.IsNullOrWhiteSpace(x.Message)))
                {
                    this.FlashError(failure.Message);
                }
            }
        }
 /// <summary>
 ///   Publishes Broken Rules and an optional DisplayMessage to subscribers (typically BaseController) via GeneralBroker
 /// </summary>
 /// <param name = "displayMessage">Message that will Flash in the View</param>
 /// <param name="severity">Determines the color of message flashed to the user</param>
 public static void RaiseValidationFailedEvent(this IUseEventBroker implementsEventBroker, string displayMessage = null, ValidationFailedEventArgs.FlashLevelType severity = ValidationFailedEventArgs.FlashLevelType.Error)
 {
     implementsEventBroker.EventBroker.RaiseValidationFailedEvent(displayMessage, severity);
 }