private static void AddErrorMessage(ModelStateDictionary modelStateDictionary, MessageGroup messageGroup)
 {
     foreach (var errorMessage in messageGroup.Messages)
     {
         modelStateDictionary.AddModelError(string.Empty, errorMessage);
     }
 }
 public static void MergeWith(this ExecutionResult executionResult, ModelStateDictionary modelStateDictionary)
 {
     if (executionResult == null || modelStateDictionary == null) return;
     foreach (var item in modelStateDictionary)
     {
         var messageGroup = new MessageGroup(item.Value.Errors.Select(e => e.ErrorMessage).ToList(), item.Key);
         executionResult.Add(MessageCategory.BrokenBusinessRule, messageGroup);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Add a list of message description for a message category
        /// </summary>
        /// <param name="messageCategory">type of message which can fall into 4 categories (informative, warning, broken bussiness rule and fatal system exception</param>
        /// <param name="messageGroup">List of messages to be added to this message type</param>
        public void Add(MessageCategory messageCategory, MessageGroup messageGroup)
        {
            if ((messageGroup == null) || (!messageGroup.Messages.Any()))
            {
                messageCategory = MessageCategory.FatalException;

                String message;
                if (messageGroup == null)
                {
                    message = "No message description has been specified";
                    messageGroup = new MessageGroup();
                }
                else
                {
                    message = messageGroup.Messages.Any(String.IsNullOrWhiteSpace)
                                  ? "All message description must be specified"
                                  : "No message type has been specified";
                }
                messageGroup.Messages.Add(message);
            }

            if (_messages.ContainsKey(messageCategory))
            {
                foreach (var m in messageGroup.Messages)
                {
                    if (!_messages[messageCategory].Messages.Contains(m))
                    {
                        _messages[messageCategory].Messages.Add(m);
                    }
                }

            }
            else
            {
                _messages.Add(messageCategory, messageGroup.Clone());
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Build a new application message with a list of message description for a message category
 /// </summary>
 /// <param name="messageCategory">type of message which can fall into 4 categories (informative, warning, broken bussiness rule and fatal system exception</param>
 /// <param name="message">List of messages to be added to this message type</param>
 public ExecutionResult(MessageCategory messageCategory, MessageGroup messageGroup)
 {
     Add(messageCategory, messageGroup);
 }