public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (!SelectedRoles.Any()) { yield return(new ValidationResult("An employee must belong to at least one role.")); } }
private void OnAddUserRoleButtonClick(object sender, RoutedEventArgs e) { var win = new WindowSelectRole(); win.Closed += (o, ea) => { if (win.DialogResult.HasValue && win.DialogResult.Value) { userInfoChanged = true; if (SelectedRoles == null) { SelectedRoles = new List <UserRoleRel>(); } foreach (var c in win.SelectedRole) { if (SelectedRoles.Any(uo => uo.RoleId == c.RoleId)) { continue; } SelectedRoles.Add(new UserRoleRel { Id = 0, UserId = AuthenticateStatus.CurrentUser.UserId, RoleId = c.RoleId, Role = c, StartTime = DateTime.Now.Date, ExpireTime = DateTime.Now.Date.AddYears(10), CreatedBy = AuthenticateStatus.CurrentUser.UserId, CreateTime = DateTime.Now, LastUpdateTime = DateTime.Now, LastUpdatedBy = AuthenticateStatus.CurrentUser.UserId, }); } UserRolesList.ItemsSource = null; UserRolesList.ItemsSource = SelectedRoles; } }; win.Show(); }