Example #1
0
        private async Task UpdateFormAsync(FormUpdateModel updateForm, OwnerChooseModel ownerChooseModel)
        {
            IsFocus = false;
            bool validationResult = updateForm != null ? await ValidateCreationOrEditOfFormAsync(updateForm.FormNr, updateForm.OldFormNr, updateForm.IdForm) : false;

            if (validationResult)
            {
                bool shouldClose = true;
                try
                {
                    UpdateFormEventArgs updateFormEventArgs = new UpdateFormEventArgs();
                    busyIndicator.BlockUI();
                    var result = await requestManager.PatchAsync(RoutingConstants.FormRoute, updateForm);

                    if (result.IsError)
                    {
                        bool isMissing = result.ErrorCode == (int)TMErrorCode.ObjectNotFoundError;
                        if (!isMissing)
                        {
                            notificationManager.Alert(result.ErrorMessage, result.IsFatalError);
                            shouldClose = false;

                            if (result.StatusCode == HttpStatusCode.Conflict && updateForm.IdForm != null)
                            {
                                EditedForm.IsValid        = false;
                                EditedForm.IsValidEnabled = false;
                                ReceiveModel(await GetFormAsync(updateForm.IdForm));
                                updateFormEventArgs = NewUpdateFormEventArgs(EditedForm.IdForm, ownerChooseModel, false);
                            }
                        }
                    }
                    else
                    {
                        updateFormEventArgs = NewUpdateFormEventArgs(EditedForm.IdForm, ownerChooseModel, false);
                    }

                    eventAggregator.PublishOnUIThread(updateFormEventArgs);
                }
                finally
                {
                    busyIndicator.UnblockUI();
                }

                if (shouldClose)
                {
                    BtnCancel();
                }
            }
            IsFocus = true;
        }