public static CommandResult ValidateModel(this Object model)
        {
            if (model == null) return new CommandResult(null, "The model cannot be null");

            var result = new CommandResult();

            var validationResults = new List<ValidationResult>();
            var ctx = new ValidationContext(model, null, null);
            Validator.TryValidateObject(model, ctx, validationResults, true);

            if (validationResults.Count > 0)
            {
                result = new CommandResult(null, "There were errors reported", validationResults)
                {
                    Errors = validationResults.Select(x => new ErrorMessage
                    {
                        PropertyName = x.MemberNames.FirstOrDefault(),
                        Reason = x.ErrorMessage
                    })
                        .ToList()
                };
            }

            return result;
        }
Example #2
0
        public CommandResult Send(MailMessage message, string attachmentPath)
        {
            if (message == null) return new CommandResult(String.Empty, "There is no message to send.");

            var result = new CommandResult();

            _sender.Send(message, attachmentPath);

            return result;
        }
Example #3
0
 public CommandResult Add(CommandResult domainResult)
 {
     Warnings.AddRange(domainResult.Warnings);
     Errors.AddRange(domainResult.Errors);
     return this;
 }