protected override Task <IDictionary <string, IEnumerable> > ValidateInternalAsync(string propertyName, CancellationToken token) { if (!MemberNameEqual(propertyName, () => model => model.Login)) { return(EmptyResult); } // To simulate the long-term operation. return(Task <IDictionary <string, IEnumerable> > .Factory.StartNew(() => { ToolkitExtensions.Sleep(500); if (token.IsCancellationRequested) { return null; } if (_userRepository.GetUsers().Any(model => model != Instance && model.Login == Instance.Login)) { return new Dictionary <string, IEnumerable> { { propertyName, $"The user with login {Instance.Login}, already exists." } } } ; return null; }, token)); }
/// <summary> /// Updates information about errors in the specified property. /// </summary> /// <param name="propertyName">The specified property name.</param> /// <returns> /// The result of validation. /// </returns> protected override Task <IDictionary <string, IEnumerable> > ValidateInternalAsync(string propertyName) { if (!PropertyNameEqual(propertyName, model => model.Login)) { return(EmptyResult); } // To simulate the long-term operation. return(Task <IDictionary <string, IEnumerable> > .Factory.StartNew(() => { ToolkitExtensions.Sleep(500); if (_userRepository.GetUsers().Any(model => model != Instance && model.Login == Instance.Login)) { return new Dictionary <string, IEnumerable> { { propertyName, string.Format("The user with login {0}, already exists.", Instance.Login) } } } ; return null; })); }