102 lines
2.5 KiB
C#
102 lines
2.5 KiB
C#
using EgwCoreLib.Lux.Data.Services.General;
|
|
using EgwCoreLib.Razor;
|
|
using Radzen.Blazor.Markdown;
|
|
|
|
namespace Lux.UI.Components.Pages
|
|
{
|
|
public partial class Resources
|
|
{
|
|
|
|
#region Protected Methods
|
|
|
|
protected override Task OnInitializedAsync()
|
|
{
|
|
return ReloadDataAsync();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<ResourceModel> AllRecords = new List<ResourceModel>();
|
|
|
|
private bool isLoading = false;
|
|
|
|
private BootstrapModal Modal = new();
|
|
private string mTitle = "";
|
|
private string mMessage = "";
|
|
private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND;
|
|
private Dictionary<bool, string> modalOpt = new Dictionary<bool, string>();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private IResourceService ResService { get; set; } = null!;
|
|
|
|
private string searchVal { get; set; } = string.Empty;
|
|
|
|
private string btnResetCss
|
|
{
|
|
get => string.IsNullOrEmpty(searchVal) ? "btn-outline-secondary" : "btn-primary";
|
|
}
|
|
|
|
private string SearchVal
|
|
{
|
|
get => searchVal;
|
|
set
|
|
{
|
|
if (searchVal != value)
|
|
{
|
|
searchVal = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task ReloadDataAsync()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = await ResService.GetAllAsync();
|
|
isLoading = false;
|
|
}
|
|
|
|
private void ResetSearch()
|
|
{
|
|
SearchVal = "";
|
|
}
|
|
|
|
private async Task DoAdd()
|
|
{
|
|
mTitle = "Attenzione";
|
|
mMessage = "Confermi di voler aggiungere un nuovo record risorsa?";
|
|
mMode = BootstrapModal.ModalMode.Confirm;
|
|
modalOpt = new();
|
|
modalOpt.Add(true, "Si");
|
|
modalOpt.Add(false, "No");
|
|
if (!await Modal!.ShowAsync<bool>())
|
|
return;
|
|
|
|
var newRecord = new ResourceModel()
|
|
{
|
|
Name = $"Nuova Risorsa | {DateTime.Now:yyyy.MM.dd-HH.mm.ss}",
|
|
CostDriverID = 1
|
|
};
|
|
|
|
await ResService.UpsertAsync(newRecord);
|
|
await ReloadDataAsync();
|
|
}
|
|
|
|
private Task DoDelete(bool args)
|
|
{
|
|
return ReloadDataAsync();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
}
|
|
} |