public static void AddErrors(this ModelStateDictionary modelState, IdentityManagerResult result)
        {
            if (modelState == null) throw new ArgumentNullException("modelState");
            if (result == null) throw new ArgumentNullException("result");

            foreach (var error in result.Errors)
            {
                modelState.AddModelError("", error);
            }
        }
        public static ErrorModel ToError(this IdentityManagerResult result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            return(new ErrorModel
            {
                Errors = result.Errors.ToArray()
            });
        }
        private IM.IdentityManagerResult ToIdentityManagerResult(UserManagementResult result)
        {
            IM.IdentityManagerResult identityManagerResult;

            if (result.IsError)
            {
                identityManagerResult = new IM.IdentityManagerResult(result.Errors.ToArray());
            }
            else
            {
                identityManagerResult = IM.IdentityManagerResult.Success;
            }

            return(identityManagerResult);
        }
        public static bool TrySet(this PropertyMetadata property, object instance, string value, out IdentityManagerResult result)
        {
            if (property == null) throw new ArgumentNullException("property");
            result = null;

            var executableProperty = property as ExecutablePropertyMetadata;
            if (executableProperty != null)
            {
                result = executableProperty.Set(instance, value);
                return true;
            }

            return false;
        }
        public static bool TrySet(this IEnumerable<PropertyMetadata> properties, object instance, string type, string value, out IdentityManagerResult result)
        {
            if (properties == null) throw new ArgumentNullException("properties");
            result = null;

            var executableProperty = properties.Where(x => x.Type == type).SingleOrDefault() as ExecutablePropertyMetadata;
            if (executableProperty != null)
            {
                return executableProperty.TrySet(instance, value, out result);
            }
            
            return false;
        }
        public static bool TrySet(this PropertyMetadata property, object instance, string value, out IdentityManagerResult result)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }
            result = null;

            var executableProperty = property as ExecutablePropertyMetadata;

            if (executableProperty != null)
            {
                result = executableProperty.Set(instance, value);
                return(true);
            }

            return(false);
        }
        public static bool TrySet(this IEnumerable <PropertyMetadata> properties, object instance, string type, string value, out IdentityManagerResult result)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }
            result = null;

            var executableProperty = properties.Where(x => x.Type == type).SingleOrDefault() as ExecutablePropertyMetadata;

            if (executableProperty != null)
            {
                return(executableProperty.TrySet(instance, value, out result));
            }

            return(false);
        }