Rename salesbook
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
|
||||
namespace salesbook.Shared.Core.Services;
|
||||
|
||||
public class AppAuthenticationStateProvider : AuthenticationStateProvider
|
||||
{
|
||||
private readonly IUserSession _userSession;
|
||||
private readonly IUserAccountService _userAccountService;
|
||||
|
||||
|
||||
public AppAuthenticationStateProvider(IUserSession userSession, IUserAccountService userAccountService)
|
||||
{
|
||||
_userSession = userSession;
|
||||
_userAccountService = userAccountService;
|
||||
|
||||
userAccountService.ExpiredUserSession += (_, _) =>
|
||||
NotifyAuthenticationStateChanged(LoadAuthenticationState());
|
||||
}
|
||||
|
||||
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||
{
|
||||
return await LoadAuthenticationState();
|
||||
}
|
||||
|
||||
public async Task SignOut()
|
||||
{
|
||||
await _userAccountService.Logout();
|
||||
NotifyAuthenticationState();
|
||||
}
|
||||
|
||||
public void NotifyAuthenticationState()
|
||||
{
|
||||
NotifyAuthenticationStateChanged(LoadAuthenticationState());
|
||||
}
|
||||
|
||||
private async Task<AuthenticationState> LoadAuthenticationState()
|
||||
{
|
||||
if (!await _userSession.IsLoggedIn() || !await _userSession.IsRefreshTokenValid())
|
||||
{
|
||||
return new AuthenticationState(
|
||||
new ClaimsPrincipal(
|
||||
new ClaimsIdentity()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
var claimIdentity = new ClaimsIdentity(_userSession.JwtToken!.Claims, "jwt");
|
||||
var user = new ClaimsPrincipal(claimIdentity);
|
||||
|
||||
|
||||
var authenticationState = new AuthenticationState(user);
|
||||
return authenticationState;
|
||||
}
|
||||
}
|
||||
70
salesbook.Shared/Core/Services/IntegryApiService.cs
Normal file
70
salesbook.Shared/Core/Services/IntegryApiService.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account;
|
||||
using IntegryApiClient.Core.Domain.RestClient.Contacts;
|
||||
using salesbook.Shared.Core.Dto;
|
||||
using salesbook.Shared.Core.Entity;
|
||||
using salesbook.Shared.Core.Interface;
|
||||
|
||||
namespace salesbook.Shared.Core.Services;
|
||||
|
||||
public class IntegryApiService(IIntegryApiRestClient integryApiRestClient, IUserSession userSession)
|
||||
: IIntegryApiService
|
||||
{
|
||||
public Task<List<StbActivity>?> RetrieveActivity(string? dateFilter)
|
||||
{
|
||||
var queryParams = new Dictionary<string, object> { { "dateFilter", dateFilter ?? "2020-01-01" } };
|
||||
|
||||
return integryApiRestClient.AuthorizedGet<List<StbActivity>?>("crm/retrieveActivity", queryParams);
|
||||
}
|
||||
|
||||
public Task<List<JtbComt>?> RetrieveAllCommesse(string? dateFilter)
|
||||
{
|
||||
var queryParams = new Dictionary<string, object>();
|
||||
|
||||
if (dateFilter != null)
|
||||
{
|
||||
queryParams.Add("dateFilter", dateFilter);
|
||||
}
|
||||
|
||||
return integryApiRestClient.AuthorizedGet<List<JtbComt>?>("crm/retrieveCommesse", queryParams);
|
||||
}
|
||||
|
||||
public Task<TaskSyncResponseDTO> RetrieveAnagClie(string? dateFilter)
|
||||
{
|
||||
var queryParams = new Dictionary<string, object>();
|
||||
|
||||
if (dateFilter != null)
|
||||
{
|
||||
queryParams.Add("dateFilter", dateFilter);
|
||||
}
|
||||
|
||||
return integryApiRestClient.AuthorizedGet<TaskSyncResponseDTO>("crm/retrieveClienti", queryParams)!;
|
||||
}
|
||||
|
||||
public Task<TaskSyncResponseDTO> RetrieveProspect(string? dateFilter)
|
||||
{
|
||||
var queryParams = new Dictionary<string, object>();
|
||||
|
||||
if (dateFilter != null)
|
||||
{
|
||||
queryParams.Add("dateFilter", dateFilter);
|
||||
}
|
||||
|
||||
return integryApiRestClient.AuthorizedGet<TaskSyncResponseDTO>("crm/retrieveProspect", queryParams)!;
|
||||
}
|
||||
|
||||
public Task<SettingsResponseDTO> RetrieveSettings() =>
|
||||
integryApiRestClient.AuthorizedGet<SettingsResponseDTO>("crm/retrieveSettings")!;
|
||||
|
||||
public Task DeleteActivity(string activityId)
|
||||
{
|
||||
var queryParams = new Dictionary<string, object>
|
||||
{
|
||||
{ "activityId", activityId }
|
||||
};
|
||||
|
||||
return integryApiRestClient.AuthorizedGet<object>($"activity/delete", queryParams);
|
||||
}
|
||||
|
||||
public Task<List<StbActivity>?> SaveActivity(ActivityDTO activity) =>
|
||||
integryApiRestClient.AuthorizedPost<List<StbActivity>?>("crm/saveActivity", activity);
|
||||
}
|
||||
Reference in New Issue
Block a user