コード例 #1
0
        protected virtual async Task OnShellNavigatingOut(string sender, ShellNavigatingEventArgs args)
        {
            ShellNavigatingEventArgs = args;

            AppErrorService.ClearInlineValidators();
        }
コード例 #2
0
        protected virtual bool Validate(Dictionary <string, object> properties = null, Dictionary <string, string> propertiesDisplayName = null, List <Tuple <string, bool, string> > validators = null)
        {
            // clean any inline val property
            AppErrorService.ClearInlineValidators();

            if (properties?.Count > 0)
            {
                if (ValidatePropertyList(properties, propertiesDisplayName, validators))
                {
                    return(true);
                }
            }
            else
            {
                var isValid = ValidateProperties(null, validators);

                if (isValid)
                {
                    return(true);
                }
            }

            string formattedErrors = "";
            var    errors          = GetAllErrors();

            // invalid but no errors: move on
            if (!errors.Any())
            {
                return(true);
            }

            foreach (var key in errors.Keys)
            {
                // TODO we would need to replace the CamelCase filed key with a globalized name
                // in the meantime, we de-camel case
                //formattedErrors += $"\n\u2022 {key.SplitCamelCase()} : {string.Join("\n", errors[key])}";
                if (errors.Keys.Count == 1)
                {
                    formattedErrors = string.Join("\n", errors[errors.Keys.First()]);
                }
                else
                {
                    formattedErrors += $"\u2022 {string.Join("\n", errors[key])}\n";
                }

                // replace property name with display name
                if (propertiesDisplayName != null)
                {
                    formattedErrors = propertiesDisplayName.Aggregate(formattedErrors, (current, propertyDisplayName) => current.Replace(propertyDisplayName.Key, propertyDisplayName.Value));
                }

                // split camel case
                formattedErrors = formattedErrors.SplitCamelCase();
            }

            formattedErrors = formattedErrors.ReplaceLast("\n", "");

            AppErrorService.AddError(formattedErrors, ViewModelError.ErrorAction.Display, ViewModelError.ErrorSeverity.Warning, errors: errors);

            AppErrorService.ProcessErrors();

            return(false);
        }