Example #1
0
        private async Task <bool> CascadedFormContext_OnFormSubmit(object sender, MFormContainerContextSubmitArgs e)
        {
            // Console.WriteLine("FormContextSubmit: " + typeof(T));

            var isValid = mEditContext.Validate(); // This will likely become ValidateAsync later

            if (!isValid)
            {
                Console.WriteLine(typeof(T) + ": Not valid");

                //       if (ContainerContext != null)
                //           throw new UserMessageException(L["Please check all forms. There is at least one validation error!"]);

                return(false);
            }

            Dictionary <string, object> changedDict = new Dictionary <string, object>();

            if (HasUnsavedChanges)
            {
                foreach (var entry in ChangedValues)
                {
                    var fullname = entry.GetFullName();

                    if (changedDict.ContainsKey(fullname))
                    {
                        continue;
                    }

                    object value = entry.GetValue(Model);
                    changedDict.Add(fullname, value);
                }

                ChangedValues.Clear();
            }

            if (OnValidSubmit.HasDelegate)
            {
                await OnValidSubmit.InvokeAsync(new MFormSubmitArgs(mEditContext, changedDict, Model, e.UserInterated));
            }

            return(true);
        }
Example #2
0
        private void CascadedFormContext_OnFormSubmit(object sender, MFormContainerContextSubmitArgs e)
        {
            // Console.WriteLine("FormContextSubmit: " + typeof(T));

            var isValid = mEditContext.Validate(); // This will likely become ValidateAsync later

            if (!isValid)
            {
                if (ContainerContext != null)
                {
                    throw new UserMessageException("Please check the values. There is at least one validation error!");
                }
                Console.WriteLine(typeof(T) + ": Not valid!");
                return;
            }

            Dictionary <string, object> changedDict = new Dictionary <string, object>();

            if (HasUnsavedChanges)
            {
                foreach (var entry in ChangedValues)
                {
                    string fieldname = entry.FieldName;

                    if (changedDict.ContainsKey(fieldname))
                    {
                        continue;
                    }

                    //01.08.2020 entry.Model is an old wrong version of the model in client side
                    object value = ReflectionHelper.GetPropertyValue(Model, entry.FieldName);
                    changedDict.Add(fieldname, value);
                }

                ChangedValues.Clear();
            }

            if (OnValidSubmit.HasDelegate)
            {
                var task = OnValidSubmit.InvokeAsync(new MFormSubmitArgs(mEditContext, changedDict, Model, e.UserInterated));
                task.Wait();
            }
        }