public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { 客戶資料Entities db = new 客戶資料Entities(); var data = db.客戶聯絡人.Where(x => x.客戶Id == this.客戶Id && x.Email == this.Email && x.Id != this.Id).ToList(); if (data.Count >= 1) { yield return(new ValidationResult("Email重複", new string[] { "Email" })); } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { 客戶資料Entities db = new 客戶資料Entities(); if (!string.IsNullOrEmpty(this.帳號)) { var data = db.客戶資料.Where(x => x.帳號 == this.帳號 && x.Id != this.Id).ToList(); if (data.Count >= 1) { yield return(new ValidationResult("帳號重複", new string[] { "帳號" })); } } //if (!string.IsNullOrEmpty(this.帳號) && string.IsNullOrEmpty(this.密碼)) //{ // yield return new ValidationResult("密碼為空", new string[] { "密碼" }); //} if (string.IsNullOrEmpty(this.帳號) && !string.IsNullOrEmpty(this.密碼)) { yield return(new ValidationResult("帳號為空", new string[] { "帳號" })); } }