Beispiel #1
0
        public List<ValidationMessage> ValidateSystemEmailReq(EmailRequestDto email)
        {
            Logger.Instance.LogFunctionEntry(this.GetType().Name, "ValidateSystemEmailReq");

            var util = new Utilities();
            var result = new List<ValidationMessage>();
            if (AgentId == null && string.IsNullOrEmpty(DoNotReplyEmail))
            {
                result.Add(
                    new ValidationMessage(ValidationMessageType.MissingConfiguration, EmailDtoField.EmailSenderAddressForAgent));
                Logger.Instance.Error(this.GetType().Name, "ValidateEmailReq", string.Format("Missing EmailSenderAddressForAgent value from configuration"));
            }
            else if (AgentId == null && !util.IsValidEmail(DoNotReplyEmail))
            {
                result.Add(
                    new ValidationMessage(ValidationMessageType.InvalidConfiguration, EmailDtoField.EmailSenderAddressForAgent));
                Logger.Instance.Error(this.GetType().Name, "ValidateEmailReq", string.Format("Invalid EmailSenderAddressForAgent value from configuration = {0}", DoNotReplyEmail));
            }

            if (email != null)
            {
                if (email.To == null || email.To.Count() == 0)
                {
                    Logger.Instance.Error(this.GetType().Name, "ValidateSystemEmailReq", string.Format("Validation Error: Missing {0}", EmailDtoField.To.ToString()));
                    result.Add(
                        new ValidationMessage(ValidationMessageType.MissingEmailField, EmailDtoField.To));
                }
                else
                {
                    email.To.ForEach(e =>
                    {
                        if (string.IsNullOrEmpty(e.Address))
                        {
                            Logger.Instance.Error(this.GetType().Name, "ValidateSystemEmailReq", string.Format("Validation Error: Missing {0}", EmailDtoField.ToAddress.ToString()));
                            result.Add(new ValidationMessage(ValidationMessageType.MissingEmailField, EmailDtoField.ToAddress));
                        }
                        else if (!util.IsValidEmail(e.Address))
                        {
                            Logger.Instance.Error(this.GetType().Name, "ValidateSystemEmailReq", string.Format("Validation Error: Invalid {0} = {1}", EmailDtoField.ToAddress.ToString(), e.Address));
                            result.Add(
                                new ValidationMessage(ValidationMessageType.InvalidEmailField, EmailDtoField.ToAddress));
                        }
                    });
                }
                if (email.CC != null)
                {
                    email.CC.ForEach(e =>
                    {
                        if (string.IsNullOrEmpty(e.Address))
                        {
                            Logger.Instance.Error(this.GetType().Name, "ValidateSystemEmailReq", string.Format("Validation Error: Missing {0}", EmailDtoField.CCAddress.ToString()));
                            result.Add(new ValidationMessage(ValidationMessageType.MissingEmailField, EmailDtoField.CCAddress));
                        }
                        else if (!util.IsValidEmail(e.Address))
                        {
                            Logger.Instance.Error(this.GetType().Name, "ValidateSystemEmailReq", string.Format("Validation Error: Invalid {0} = {1}", EmailDtoField.CCAddress.ToString(), e.Address));
                            result.Add(
                                new ValidationMessage(ValidationMessageType.InvalidEmailField, EmailDtoField.CCAddress));
                        }
                    });
                }

                if (email.Bcc != null)
                {
                    email.Bcc.ForEach(e =>
                    {
                        if (string.IsNullOrEmpty(e.Address))
                        {
                            Logger.Instance.Error(this.GetType().Name, "ValidateSystemEmailReq", string.Format("Validation Error: Missing {0}", EmailDtoField.BccAddress.ToString()));
                            result.Add(new ValidationMessage(ValidationMessageType.MissingEmailField, EmailDtoField.BccAddress));
                        }
                        else if (!util.IsValidEmail(e.Address))
                        {
                            Logger.Instance.Error(this.GetType().Name, "ValidateSystemEmailReq", string.Format("Validation Error: Invalid {0} = {1}", EmailDtoField.BccAddress.ToString(), e.Address));
                            result.Add(
                                new ValidationMessage(ValidationMessageType.InvalidEmailField, EmailDtoField.BccAddress));
                        }
                    });
                }
                var attachments = email.Attachments.Where(a => a != null);
                foreach (var a in attachments)
                {
                    if (!util.IsValidFileName(a.FileName))
                    {
                        Logger.Instance.Error(this.GetType().Name, "ValidateSystemEmailReq", string.Format("Validation Error: Invalid {0} = {1}", EmailDtoField.AttachmentFileName.ToString(), a.FileName));
                        result.Add(
                            new ValidationMessage(ValidationMessageType.InvalidEmailField, EmailDtoField.AttachmentFileName));
                    }
                }
            }
            else
            {
                Logger.Instance.Error(this.GetType().Name, "ValidateSystemEmailReq", string.Format("Validation Error: Missing {0}", "Email Object"));
                result.Add(
                    new ValidationMessage(ValidationMessageType.MissingEmailField, EmailDtoField.Email));
            }

            Logger.Instance.LogFunctionExit(this.GetType().Name, "ValidateSystemEmailReq");
            return result;
        }
Beispiel #2
0
        public List<ValidationMessage> ValidateEmailReq(EmailRequestDto email)
        {
            Logger.Instance.LogFunctionEntry(this.GetType().Name, "ValidateEmailReq");

            var util = new Utilities();
            var result = this.ValidateSystemEmailReq(email);

            if (email != null)
            {
                if (email.EmailType == EmailTypes.Unknown)
                {
                    Logger.Instance.Error(this.GetType().Name, "ValidateEmailReq", string.Format("Validation Error: Invalid Email Type = {0}", EmailDtoField.EmailType.ToString()));
                    result.Add(
                        new ValidationMessage(ValidationMessageType.InvalidEmailField, EmailDtoField.EmailType));
                }

                if (email.QuoteId <= 0)
                {
                    Logger.Instance.Error(this.GetType().Name, "ValidateEmailReq", string.Format("Validation Error: Invalid QuoteId = ({0})", EmailDtoField.QuoteId.ToString()));
                    result.Add(
                        new ValidationMessage(ValidationMessageType.InvalidEmailField, EmailDtoField.QuoteId));
                }
            }

            Logger.Instance.LogFunctionExit(this.GetType().Name, "ValidateEmailReq");
            return result;
        }