コード例 #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            CustomerInfoEntities db = new CustomerInfoEntities();

            if (!this.是否已刪除)
            {
                var checkEmailduplicate = db.客戶聯絡人
                                          .Where(w => w.客戶Id == this.客戶Id &&
                                                 w.Email == this.Email &&
                                                 w.是否已刪除 == false)
                                          .AsQueryable();

                if (this.Id == default(int))
                {
                    if (checkEmailduplicate != null && checkEmailduplicate.Count() >= 1)
                    {
                        yield return(new ValidationResult("Email重複", new string[] { "Email" }));
                    }
                }
                else
                {
                    checkEmailduplicate = checkEmailduplicate.Where(w => w.Id != this.Id);

                    if (checkEmailduplicate != null && checkEmailduplicate.Count() >= 1)
                    {
                        yield return(new ValidationResult("Email重複", new string[] { "Email" }));
                    }
                }
            }
        }