diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ApiBaseViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ApiBaseViewModel.cs index 6021bd2..350febe 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ApiBaseViewModel.cs +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ApiBaseViewModel.cs @@ -13,11 +13,83 @@ public class ApiBaseViewModel : BaseViewModel /// /// /// + /// /// + /// /// /// /// - public async virtual Task ExecuteApi(Func> getServerResult, Func, Task> onSuccess, Func onError = default) + public async virtual Task ExecuteMapApi(Func> getServerResult, Func> mapResult, Func, Task> onSuccess, Func onError = default) + { + try + { + Busy(); + var result = await getServerResult(); + + var response = result.ToContract(); + + if (response.IsSuccess) + await onSuccess(response); + else + await OnServerErrorHandling(response.Error); + } + catch (Exception ex) + { + if (onError != null) + await onError(ex); + else + await OnError(ex); + } + finally + { + UnBusy(); + } + } + + /// + /// + /// + /// + /// + /// + /// + /// + public async virtual Task ExecuteMapApi(Func> getServerResult, Func, Task> onSuccess, Func onError = default) + { + try + { + Busy(); + var result = await getServerResult(); + + var response = result.ToContract(); + + if (response.IsSuccess) + await onSuccess(response); + else + await OnServerErrorHandling(response.Error); + } + catch (Exception ex) + { + if (onError != null) + await onError(ex); + else + await OnError(ex); + } + finally + { + UnBusy(); + } + } + + /// + /// + /// + /// + /// + /// + /// + /// + public async virtual Task ExecuteApi(Func> getServerResult, Func, Task> onSuccess, Func onError = default) { try { diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj index 1bdaa15..488f2bf 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.17 + 0.0.0.18 Model View View Model EasyMicroservices@gmail.com mvvm,mvpvm,modelview,modelviewviewmodel