Esempio n. 1
0
        public void CallLocalSubmit(bool pUserInteracted)
        {
            var args = new MFormContainerContextSubmitArgs()
            {
                UserInterated = pUserInteracted
            };

            CascadedFormContext_OnFormSubmit(null, args);
        }
Esempio n. 2
0
        public bool NotifySubmit(IStringLocalizer <MComponentsLocalization> pLocalizer)
        {
            bool submitSuccessful = true;

            lock (mLocker)
            {
                if (OnFormSubmit == null)
                {
                    return(submitSuccessful);
                }

                var args = new MFormContainerContextSubmitArgs()
                {
                    UserInterated = true
                };

                foreach (var handler in OnFormSubmit.GetInvocationList())
                {
                    try
                    {
                        handler.Method.Invoke(handler.Target, new object[] { this, args });
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error in the handler {0}: {1}", handler.Method.Name, e.Message);

                        string msg = e.ToString();

                        if (e is TargetInvocationException te)
                        {
                            msg = te.InnerException.ToString();

                            if (te.InnerException is UserMessageException ue)
                            {
                                msg = ue.Message;
                            }
                        }

                        Notificator.InvokeNotification(true, msg);
                        submitSuccessful = false;
                    }
                }

                Notificator.InvokeNotification(false, pLocalizer["Gespeichert!"]);
            }

            return(submitSuccessful);
        }
Esempio n. 3
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();
            }
        }