コード例 #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (!Emails.Any())
            {
                yield return(new ValidationResult("An email is required."));
            }

            if (Emails.Count() > 20)
            {
                yield return(new ValidationResult("You can only invite up to 20 users at a time."));
            }

            var attr = new EmailAddressAttribute();

            for (var i = 0; i < Emails.Count(); i++)
            {
                var email = Emails.ElementAt(i);
                if (!attr.IsValid(email) || email.Contains(" ") || email.Contains("<"))
                {
                    yield return(new ValidationResult($"Email #{i + 1} is not valid.",
                                                      new string[] { nameof(Emails) }));
                }
                else if (email.Length > 256)
                {
                    yield return(new ValidationResult($"Email #{i + 1} is longer than 256 characters.",
                                                      new string[] { nameof(Emails) }));
                }
            }
        }
コード例 #2
0
ファイル: Person.cs プロジェクト: Alttaf/UCosmicPreview
        public EmailAddress AddEmail(string value)
        {
            // email may already exist
            var email = Emails.ByValue(value);

            if (email != null)
            {
                return(email);
            }

            // create email
            email = new EmailAddress
            {
                // if person does not already have a default email, this is it
                IsDefault = (Emails.Count(a => a.IsDefault) == 0),
                Value     = value,
                Person    = this,
                Number    = Emails.NextNumber(),
            };

            // add & return email
            Emails.Add(email);

            return(email);
        }
コード例 #3
0
        public JsonResult Get(int pageIndex, int pageSize, string pageOrder)
        {
            var list = Emails.Get(pageIndex, pageSize, pageOrder);

            int total     = Emails.Count();
            int totalPage = (int)Math.Ceiling((decimal)total / pageSize);

            if (pageSize > total)
            {
                pageSize = total;
            }

            if (list.Count < pageSize)
            {
                pageSize = list.Count;
            }

            JsonResult result = new JsonResult()
            {
                Data = new
                {
                    TotalPages = totalPage,
                    PageIndex  = pageIndex,
                    PageSize   = pageSize,
                    Rows       = list
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            return(result);
        }
コード例 #4
0
ファイル: ContactBase.cs プロジェクト: nodet/GContactSync
 public override string ToString()
 {
     if (string.IsNullOrEmpty(FullName))
     {
         if (Emails.Count() > 0)
         {
             return(Emails.ElementAt(0));
         }
         else
         {
             return("[Empty contact]");
         }
     }
     else
     {
         return(FullName);
     }
 }
コード例 #5
0
        public static SimpleSmtpServer EnsureAllEmailsPickedUp()
        {
            // Track those messages in the Email Test Server that the test didn't "handle"
            var unhandledEmailsAtTestCompletion = Emails?.Count();

            // Now clear the emails ready for the next test.
            DiscardAllEmails();


            // Last thing is to fail if there were unprocessed messages
            // Done last to ensure the tear downs have happened and
            // the following tests start with a clean slate.
            if (unhandledEmailsAtTestCompletion != 0)
            {
                Assert.Fail("{0} unexpected Email Messages at service test completion.\nAdd tests for emails and call 'EmailTestServer.DiscardAllEmails()' at end of service test.", unhandledEmailsAtTestCompletion);
            }

            return(FluentDummyInstance);
        }
コード例 #6
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (!Emails.Any())
            {
                yield return(new ValidationResult("An email is required."));
            }

            if (Emails.Count() > 20)
            {
                yield return(new ValidationResult("You can only invite up to 20 users at a time."));
            }

            var attr = new EmailAddressAttribute();

            for (int i = 0; i < Emails.Count(); i++)
            {
                if (!attr.IsValid(Emails.ElementAt(i)))
                {
                    yield return(new ValidationResult($"Email #{i + 1} is not valid.", new string[] { nameof(Emails) }));
                }
            }
        }