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) })); } } }
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); }
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); }
public override string ToString() { if (string.IsNullOrEmpty(FullName)) { if (Emails.Count() > 0) { return(Emails.ElementAt(0)); } else { return("[Empty contact]"); } } else { return(FullName); } }
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); }
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) })); } } }