Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing Performance and Responsiveness with Asynchronous Operations in Refactored Code #1179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/Infrastructure/Data/ApplicationDbContextInitialiser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Runtime.InteropServices;
using CleanArchitecture.Domain.Constants;
using CleanArchitecture.Domain.Constants;
using CleanArchitecture.Domain.Entities;
using CleanArchitecture.Infrastructure.Identity;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -70,28 +69,28 @@ public async Task TrySeedAsync()
// Default roles
var administratorRole = new IdentityRole(Roles.Administrator);

if (_roleManager.Roles.All(r => r.Name != administratorRole.Name))
if (await _roleManager.Roles.AllAsync(r => r.Name != administratorRole.Name))
{
await _roleManager.CreateAsync(administratorRole);
}

// Default users
var administrator = new ApplicationUser { UserName = "administrator@localhost", Email = "administrator@localhost" };

if (_userManager.Users.All(u => u.UserName != administrator.UserName))
if (await _userManager.Users.AllAsync(u => u.UserName != administrator.UserName))
{
await _userManager.CreateAsync(administrator, "Administrator1!");
if (!string.IsNullOrWhiteSpace(administratorRole.Name))
{
await _userManager.AddToRolesAsync(administrator, new [] { administratorRole.Name });
await _userManager.AddToRolesAsync(administrator, new[] { administratorRole.Name });
}
}

// Default data
// Seed, if necessary
if (!_context.TodoLists.Any())
if (!await _context.TodoLists.AnyAsync())
{
_context.TodoLists.Add(new TodoList
await _context.TodoLists.AddAsync(new TodoList
{
Title = "Todo List",
Items =
Expand Down