public override ValidationResult Validate(object value, CultureInfo cultureInfo) { QuestionCathegory cathegory = (value as BindingGroup).Items[0] as QuestionCathegory; if (cathegory.Name == null || cathegory.Name.Length == 0) { return(new ValidationResult(false, "The name value can't be empty")); } if (cathegory.Name != null && cathegory.Name.Length > 50) { return(new ValidationResult(false, "Cathegory name is too long. Length should be smaller than 50 characters")); } if (cathegory.ParentCathegory != null && cathegory.ParentCathegory.ToString() == cathegory.Id.ToString()) { return(new ValidationResult(false, "Cathegory can not be 'parent cathegory' for its self")); } AkinatorDatabaseEntities tempContext = new AkinatorDatabaseEntities(); if (tempContext.QuestionCathegories.Count(s => (s.Name == cathegory.Name) && (s.Id != cathegory.Id)) > 0) { return(new ValidationResult(false, "Cathegory names have to be unique")); } return(ValidationResult.ValidResult); }
private void QuestionCathegoryViewSourceFilter(object sender, FilterEventArgs e) { QuestionCathegory cat = e.Item as QuestionCathegory; if (cat != null) { e.Accepted = (cat.Name.ToUpper().Contains(QuestionCathegoriesSearchBox.Text.ToUpper())); } }