using LiMan.DB.DBModels; using LiMan.UI.Data; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace LiMan.UI.Components { public partial class ListReleases { #region Public Properties [Parameter] public ApplicativoModel CurrRecord { get; set; } [Parameter] public EventCallback DataReset { get; set; } #endregion Public Properties #region Public Methods public string checkSelect(int idxRel) { string answ = ""; if (recordEdit != null) { try { answ = (recordEdit.IdxRel == idxRel) ? "table-info" : ""; } catch { } } return answ; } #endregion Public Methods #region Protected Properties [Inject] protected MessageService AppMServ { get; set; } = null!; [Inject] protected LiManDataService DataService { get; set; } #endregion Protected Properties #region Protected Methods protected void AddNew() { recordEdit = new ReleaseModel() { CodApp = CurrRecord.CodApp, VersNum = "0.0.0.0", VersText = "a.b.c", ReleaseDate = DateTime.Today }; } protected async Task DoDelete(ReleaseModel rec2del) { if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare il record?")) return; await DataService.ReleaseDelete(rec2del); await ReloadAllData(); } protected void DoEdit(ReleaseModel selRecord) { recordEdit = selRecord; } protected async Task DoSave() { recordEdit = null; await ReloadAllData(); } protected override async Task OnInitializedAsync() { } protected override async Task OnAfterRenderAsync(bool firstRender) { numRecord = await AppMServ.NumRowGridGet(gridKey); } protected override async Task OnParametersSetAsync() { isLoading = true; ListRecords = null; await ReloadAllData(); } protected async Task SetNumRec(int newNum) { currPage = 1; numRecord = newNum; await AppMServ.NumRowGridSet(gridKey, newNum); await ReloadAllData(); isLoading = false; } protected async Task SetPage(int newNum) { currPage = newNum; await ReloadAllData(); isLoading = false; } #endregion Protected Methods #region Private Fields private string gridKey = "ListRelease"; private List ListRecords; private ReleaseModel recordEdit = null; private List SearchRecords; #endregion Private Fields #region Private Properties private int currPage { get; set; } = 1; private bool isLoading { get; set; } = false; [Inject] private IJSRuntime JSRuntime { get; set; } private int numRecord { get; set; } = 10; private int totalCount { get; set; } = 0; #endregion Private Properties #region Private Methods private async Task DoClose() { await DataReset.InvokeAsync(0); } private async Task ReloadAllData() { isLoading = true; SearchRecords = await DataService.ReleaseGetByApp(CurrRecord.CodApp); // ordino DESC SearchRecords = SearchRecords.OrderByDescending(x => x.VersVal).ToList(); totalCount = SearchRecords.Count(); ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); isLoading = false; } #endregion Private Methods } }