Skip to content

Commit

Permalink
fix api call
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Nov 11, 2023
1 parent edc120d commit 5f2a060
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
30 changes: 25 additions & 5 deletions src/CSharp/EasyMicroservices.UI.Core.Mvvm/BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ public virtual void UnBusy()
/// <param name="onSuccess"></param>
/// <param name="onError"></param>
/// <returns></returns>
public async virtual Task ExecuteApi<TResult>(Func<Task<TResult>> getServerResult, Func<TResult, Task> onSuccess, Func<Exception, Task> onError = default)
public async virtual Task ExecuteApi<TResult>(Func<Task<object>> getServerResult, Func<TResult, Task> onSuccess, Func<Exception, Task> onError = default)
{
try
{
Busy();
var result = await getServerResult();

var response = result.ToContract<TResult>();

if (response.IsSuccess)
Expand Down Expand Up @@ -95,12 +96,31 @@ public async virtual Task ExecuteApi<TResult>(Func<Task<TResult>> getServerResul
/// <param name="onSuccess"></param>
/// <param name="onError"></param>
/// <returns></returns>
public virtual Task ExecuteApi(Func<Task<ErrorContract>> getServerResult, Func<Task> onSuccess, Func<Exception, Task> onError = default)
public virtual async Task ExecuteApi(Func<Task<object>> getServerResult, Func<Task> onSuccess, Func<Exception, Task> 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();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.2</Version>
<Version>0.0.0.3</Version>
<Description>Model View View Model</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>mvvm,mvpvm,modelview,modelviewviewmodel</PackageTags>
Expand Down

0 comments on commit 5f2a060

Please sign in to comment.