diff --git a/src/CSharp/EasyMicroservices.UI.Core.Mvvm/BaseViewModel.cs b/src/CSharp/EasyMicroservices.UI.Core.Mvvm/BaseViewModel.cs index 395dc0f..76fe373 100644 --- a/src/CSharp/EasyMicroservices.UI.Core.Mvvm/BaseViewModel.cs +++ b/src/CSharp/EasyMicroservices.UI.Core.Mvvm/BaseViewModel.cs @@ -62,12 +62,13 @@ public virtual void UnBusy() /// /// /// - public async virtual Task ExecuteApi(Func> getServerResult, Func onSuccess, Func onError = default) + public async virtual Task ExecuteApi(Func> getServerResult, Func onSuccess, Func onError = default) { try { Busy(); var result = await getServerResult(); + var response = result.ToContract(); if (response.IsSuccess) @@ -95,12 +96,31 @@ public async virtual Task ExecuteApi(Func> getServerResul /// /// /// - public virtual Task ExecuteApi(Func> getServerResult, Func onSuccess, Func onError = default) + public virtual async Task ExecuteApi(Func> getServerResult, Func onSuccess, Func onError = default) { - return ExecuteApi(getServerResult, async (x) => + try { - await onSuccess(); - }, onError); + Busy(); + var result = await getServerResult(); + + var response = result.ToContract(); + + if (response.IsSuccess) + await onSuccess(); + else + await DisplayFetchError(response.Error); + } + catch (Exception ex) + { + if (onError != null) + await onError(ex); + else + await DisplayError(ex.ToString()); + } + finally + { + UnBusy(); + } } /// diff --git a/src/CSharp/EasyMicroservices.UI.Core.Mvvm/EasyMicroservices.UI.Core.Mvvm.csproj b/src/CSharp/EasyMicroservices.UI.Core.Mvvm/EasyMicroservices.UI.Core.Mvvm.csproj index 40b5ade..960a983 100644 --- a/src/CSharp/EasyMicroservices.UI.Core.Mvvm/EasyMicroservices.UI.Core.Mvvm.csproj +++ b/src/CSharp/EasyMicroservices.UI.Core.Mvvm/EasyMicroservices.UI.Core.Mvvm.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.2 + 0.0.0.3 Model View View Model EasyMicroservices@gmail.com mvvm,mvpvm,modelview,modelviewviewmodel