65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using Blazored.LocalStorage;
|
|
using MP.Core.DTO;
|
|
using NLog;
|
|
|
|
namespace MP.INVE.Data
|
|
{
|
|
public class MessageService
|
|
{
|
|
protected ILocalStorageService localStorage { get; set; } = null!;
|
|
|
|
public MessageService(ILocalStorageService genLocalStorage)
|
|
{
|
|
localStorage = genLocalStorage;
|
|
}
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
/// <summary>
|
|
/// Effettua pulizia localstorage
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> clearLocalStorageAsync()
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
await localStorage.ClearAsync();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in clearLocalStorage{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce il record OperatoreDTO da localstorage
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<OperatoreDTO> getCurrOperDtoAsync()
|
|
{
|
|
OperatoreDTO answ = new OperatoreDTO();
|
|
var result = await localStorage.GetItemAsync<OperatoreDTO>("Opr");
|
|
if (result != null)
|
|
{
|
|
answ = result;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// scrive il record OperatoreDTO nel localstorage
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> setCurrOperDtoAsync(OperatoreDTO opr)
|
|
{
|
|
bool answ = false;
|
|
await localStorage.SetItemAsync("Opr", opr);
|
|
answ = true;
|
|
return answ;
|
|
}
|
|
|
|
}
|
|
} |