public Task <bool> CallLocalSubmit(bool pUserInteracted) { var args = new MFormContainerContextSubmitArgs() { UserInterated = pUserInteracted }; return(CascadedFormContext_OnFormSubmit(this, args)); }
public void CallLocalSubmit(bool pUserInteracted) { var args = new MFormContainerContextSubmitArgs() { UserInterated = pUserInteracted }; CascadedFormContext_OnFormSubmit(null, args); }
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); }
public async Task <bool> NotifySubmit(IStringLocalizer <MComponentsLocalization> pLocalizer) { if (OnFormSubmit == null) { return(true); } bool submitSuccessful = true; try { await mLocker.WaitAsync(); var args = new MFormContainerContextSubmitArgs() { UserInterated = true }; foreach (AsyncEventHandler <MFormContainerContextSubmitArgs> handler in OnFormSubmit.GetInvocationList()) { try { await handler(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; } } if (FormContainer.OnAfterAllFormsSubmitted.HasDelegate) { await FormContainer.OnAfterAllFormsSubmitted.InvokeAsync(new MFormContainerAfterAllFormsSubmittedArgs() { AllFormsSuccessful = submitSuccessful }); } Notificator.InvokeNotification(false, pLocalizer["Gespeichert!"]); } finally { mLocker.Release(); } return(submitSuccessful); }