private UpdateFormEventArgs NewUpdateFormEventArgs(Guid idForm, OwnerChooseModel ownerChooseModel, bool isNew) { UpdateFormEventArgs updateFormEventArgs = new UpdateFormEventArgs() { FormId = idForm, OwnerChooseModel = ownerChooseModel, IsNew = isNew }; return(updateFormEventArgs); }
public async void Handle(UpdateFormEventArgs updatedFormArgs) { if (updatedFormArgs == null || updatedFormArgs.FormId == null) { await InitializeAsync(false); } else { await UpdateGridAsync(updatedFormArgs); } UpdateHeaderView(); }
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; }
private async Task UpdateGridAsync(UpdateFormEventArgs updatedFormArgs) { Guid callingOwnerId = updatedFormArgs.OwnerChooseModel.Id; Guid?formId = updatedFormArgs.FormId; string path = string.Format("{0}/{1}", RoutingConstants.FormRoute, formId.ToString()); try { BusyIndicator.BlockUI(); var result = await requestManager.GetAsync <FormModel>(path); if (result.Data == null || result.IsError) { await InitializeAsync(true); } else { FormModel resultForm = result.Data; if (updatedFormArgs.IsNew) { bool scrollToFirst = false; if (OwnerChooseModel != null) { if (OwnerChooseModel.Id == callingOwnerId) { FormModels.Add(resultForm); SelectedForm = FormModels.FirstOrDefault(x => x.IdForm.Equals(resultForm.IdForm)); } else { scrollToFirst = true; } } else { FormModels.Add(resultForm); SelectedForm = FormModels.FirstOrDefault(x => x.IdForm.Equals(resultForm.IdForm)); } ScrollOrRefreshGrid(this, new CleanFilterEventArgs() { ScrollToFirst = scrollToFirst }); } else { FormModel editedFormModel = FormModels.FirstOrDefault(x => x.IdForm == formId); if (editedFormModel != null) { if (OwnerChooseModel != null && callingOwnerId != OwnerChooseModel.Id) { if (FormModels.Any()) { FormModels.Remove(editedFormModel); } } else { int editedFormModelIndex = FormModels.IndexOf(editedFormModel); if (editedFormModelIndex != -1) { FormModels[editedFormModelIndex] = resultForm; } } } } } } finally { BusyIndicator.UnblockUI(); } }