Files
mapo-core/MP.Stats/Components/ModalSearchMacc.razor.cs
T

101 lines
2.4 KiB
C#

using Microsoft.AspNetCore.Components;
using MP.Data.DbModels;
using MP.Stats.Data;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MP.Stats.Components
{
public partial class ModalSearchMacc
{
#region Public Properties
[Parameter]
public List<AutocompleteModel> AllRecords { get; set; } = null!;
[Parameter]
public EventCallback<bool> EC_CloseSearch { get; set; }
#endregion Public Properties
#region Protected Properties
protected string CssReset
{
get => string.IsNullOrEmpty(SearchVal) ? "btn-outline-secondary" : "btn-primary";
}
protected List<AutocompleteModel> ListRecords { get; set; } = null!;
protected string SearchVal
{
get => _searchVal;
set
{
if (_searchVal != value)
{
_searchVal = value;
ReloadData();
}
}
}
#endregion Protected Properties
#region Protected Methods
protected override void OnParametersSet()
{
totalCount = AllRecords.Count;
ReloadData();
}
protected void ReloadData()
{
ListRecords = AllRecords
.Where(x => string.IsNullOrEmpty(SearchVal) || x.LabelField.Contains(SearchVal, System.StringComparison.InvariantCultureIgnoreCase))
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
protected void ResetSearch()
{
SearchVal = "";
ReloadData();
}
protected void SetNumRec(int newNum)
{
numRecord = newNum;
ReloadData();
}
protected void SetPage(int newNum)
{
currPage = newNum;
ReloadData();
}
#endregion Protected Methods
#region Private Fields
private string _searchVal = "";
private int currPage = 1;
private int numRecord = 10;
private int totalCount = 0;
#endregion Private Fields
#region Private Methods
private async Task SearchMaccToggle()
{
await EC_CloseSearch.InvokeAsync(true);
}
#endregion Private Methods
}
}