Load everything from database using async

dhcp-server
Pat Hartl 2023-08-25 19:25:28 -05:00
parent 08fff0c8d0
commit 4f76394bb5
9 changed files with 25 additions and 20 deletions

View File

@ -3,6 +3,7 @@ using LANCommander.Data.Models;
using LANCommander.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace LANCommander.Controllers.Api
{
@ -19,11 +20,11 @@ namespace LANCommander.Controllers.Api
}
[HttpGet]
public IEnumerable<Archive> Get()
public async Task<IEnumerable<Archive>> Get()
{
using (var repo = new Repository<Archive>(Context, HttpContext))
{
return repo.Get(a => true).ToList();
return await repo.Get(a => true).ToListAsync();
}
}

View File

@ -23,9 +23,9 @@ namespace LANCommander.Controllers.Api
}
[HttpGet]
public IEnumerable<Game> Get()
public async Task<IEnumerable<Game>> Get()
{
return GameService.Get();
return await GameService.Get();
}
[HttpGet("{id}")]

View File

@ -29,9 +29,9 @@ namespace LANCommander.Controllers.Api
}
[HttpGet]
public IEnumerable<GameSave> Get()
public async Task<IEnumerable<GameSave>> Get()
{
return GameSaveService.Get();
return await GameSaveService.Get();
}
[HttpGet("{id}")]

View File

@ -217,9 +217,9 @@ else
else
Game = await GameService.Get(Id);
Companies = CompanyService.Get();
Genres = GenreService.Get();
Tags = TagService.Get();
Companies = await CompanyService.Get();
Genres = await GenreService.Get();
Tags = await TagService.Get();
}
private async Task Save()

View File

@ -3,6 +3,7 @@
@using LANCommander.Extensions;
@using System.ComponentModel.DataAnnotations;
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
@using Microsoft.EntityFrameworkCore;
@attribute [Authorize]
@inject GameService GameService
@inject NavigationManager NavigationManager
@ -264,9 +265,9 @@
}
}
private void LoadData()
private async Task LoadData()
{
Games = GameService.Get(g => g.Title.ToLower().Contains(Search.ToLower().Trim()) || g.SortTitle.ToLower().Contains(Search.ToLower().Trim())).OrderBy(g => String.IsNullOrWhiteSpace(g.SortTitle) ? g.Title : g.SortTitle).ToList();
Games = await GameService.Get(g => g.Title.ToLower().Contains(Search.ToLower().Trim()) || g.SortTitle.ToLower().Contains(Search.ToLower().Trim())).OrderBy(g => String.IsNullOrWhiteSpace(g.SortTitle) ? g.Title : g.SortTitle).ToListAsync();
}
private bool FieldVisible(Field field)
@ -307,7 +308,7 @@
await GameService.Delete(game);
Games = GameService.Get().OrderBy(g => String.IsNullOrWhiteSpace(g.SortTitle) ? g.Title : g.SortTitle).ToList();
Games = await GameService.Get(x => true).OrderBy(g => String.IsNullOrWhiteSpace(g.SortTitle) ? g.Title : g.SortTitle).ToListAsync();
Loading = false;
}

View File

@ -1,6 +1,7 @@
@page "/Games/{id:guid}/Saves"
@using LANCommander.Models;
@using System.IO.Compression;
@using Microsoft.EntityFrameworkCore;
@attribute [Authorize(Roles = "Administrator")]
@inject GameService GameService
@inject CompanyService CompanyService
@ -41,7 +42,7 @@
protected override async Task OnInitializedAsync()
{
GameSaves = GameSaveService.Get(gs => gs.GameId == Id).OrderBy(gs => gs.User.UserName).ThenByDescending(gs => gs.CreatedOn).ToList();
GameSaves = await GameSaveService.Get(gs => gs.GameId == Id).OrderBy(gs => gs.User.UserName).ThenByDescending(gs => gs.CreatedOn).ToListAsync();
Loading = false;
}
@ -54,7 +55,7 @@
await GameSaveService.Delete(gameSave);
GameSaves = GameSaveService.Get(gs => gs.GameId == Id).OrderBy(gs => gs.User.UserName).ThenByDescending(gs => gs.CreatedOn).ToList();
GameSaves = await GameSaveService.Get(gs => gs.GameId == Id).OrderBy(gs => gs.User.UserName).ThenByDescending(gs => gs.CreatedOn).ToListAsync();
Loading = false;
}

View File

@ -166,7 +166,7 @@
if (Server.GameId.HasValue)
GameId = Server.GameId.Value;
Games = GameService.Get().ToList();
Games = await GameService.Get();
}
private async Task Save()

View File

@ -1,5 +1,6 @@
@page "/Servers"
@using LANCommander.Pages.Servers.Components
@using Microsoft.EntityFrameworkCore;
@attribute [Authorize]
@inject ServerService ServerService
@inject ServerProcessService ServerProcessService
@ -67,11 +68,11 @@
}
}
private void LoadData()
private async Task LoadData()
{
var fuzzySearch = Search.ToLower().Trim();
Servers = ServerService.Get(s => s.Name.ToLower().Contains(fuzzySearch) || (s.Game != null && (s.Game.Title.ToLower().Contains(fuzzySearch) || s.Game.SortTitle.ToLower().Contains(fuzzySearch)))).OrderBy(s => s.Name).ToList();
Servers = await ServerService.Get(s => s.Name.ToLower().Contains(fuzzySearch) || (s.Game != null && (s.Game.Title.ToLower().Contains(fuzzySearch) || s.Game.SortTitle.ToLower().Contains(fuzzySearch)))).OrderBy(s => s.Name).ToListAsync();
}
private void Add()
@ -92,7 +93,7 @@
await ServerService.Delete(server);
Servers = ServerService.Get().OrderBy(s => s.Name).ToList();
Servers = await ServerService.Get(x => true).OrderBy(s => s.Name).ToListAsync();
Loading = false;
}

View File

@ -1,5 +1,6 @@
using LANCommander.Data;
using LANCommander.Data.Models;
using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;
namespace LANCommander.Services
@ -14,9 +15,9 @@ namespace LANCommander.Services
HttpContext = httpContextAccessor.HttpContext;
}
public virtual ICollection<T> Get()
public virtual async Task<ICollection<T>> Get()
{
return Get(x => true).ToList();
return await Get(x => true).ToListAsync();
}
public virtual async Task<T> Get(Guid id)