@page "/lottohistory" @using BlazorLottoPicker.Data.Model; @using BlazorLottoPicker.Data.Services; @inject HistoryService _historyService;

LottoHistory

Please set start and end lottery

@if (_showPopup) { } @if (_loading) {

Loading...

} else if (_stats == null) { } else {

Searched count: @_stats.Count

@foreach (var stat in _stats) { }
Ball number Count
@stat.BallNumber @stat.Count
} @code { List _histories; List _stats; int _start = 0; int _end = 20; bool _loading = false; bool _showPopup; void OpenPopup() { _showPopup = true; } void ClosePopup() { _showPopup = false; } async void SearchHistory() { ClosePopup(); _loading = true; _histories = await _historyService.GetHistoryListAsync(_start, _end); if (_histories == null || _histories.Count < 1) { _loading = false; return; } List hist = new List(6 * (_end - _start + 1)); foreach (HistoryResult history in _histories) { hist.AddRange(GetBallValues(history)); } hist.Sort(); Dictionary historyCounts = new Dictionary(); for (int i = 0; i < hist.Count; i++) { string key = $"No.{hist[i].ToString()}"; if (!historyCounts.ContainsKey(key)) historyCounts.Add(key, 0); historyCounts[key]++; } _stats = new List(); foreach (var histCount in historyCounts) { _stats.Add(new HistoryStatistics() { BallNumber = histCount.Key, Count = histCount.Value }); } _loading = false; StateHasChanged(); } List GetBallValues(HistoryResult result) { List values = new List(); values.Add(result.drwtNo1); values.Add(result.drwtNo2); values.Add(result.drwtNo3); values.Add(result.drwtNo4); values.Add(result.drwtNo5); values.Add(result.drwtNo6); return values; } }