-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
894 additions
and
888 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using BlogTemplate.Application.Abstractions; | ||
using BlogTemplate.Domain; | ||
using BlogTemplate.Domain.Models; | ||
using BlogTemplate.Infrastructure.Data; | ||
|
||
using Microsoft.AspNetCore.Identity; | ||
|
||
namespace BlogTemplate.Infrastructure; | ||
|
||
public class DatabaseInitialBuilder : IDatabaseInitialBuilder | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
private readonly IUserManagerProxy<ApplicationUser> _userManager; | ||
private readonly IRoleManagerProxy<IdentityRole> _roleManager; | ||
public DatabaseInitialBuilder(ApplicationDbContext context, | ||
IUserManagerProxy<ApplicationUser> userManager, | ||
IRoleManagerProxy<IdentityRole> roleManager) | ||
{ | ||
_context = context; | ||
_userManager = userManager; | ||
_roleManager = roleManager; | ||
if (!_roleManager.RoleExistsAsync(WebsiteRoles.WebsiteAdmin!).GetAwaiter().GetResult()) | ||
{ | ||
_roleManager.CreateAsync(new IdentityRole(WebsiteRoles.WebsiteAdmin!)).GetAwaiter().GetResult(); | ||
_roleManager.CreateAsync(new IdentityRole(WebsiteRoles.WebsiteAuthor!)).GetAwaiter().GetResult(); | ||
} | ||
} | ||
|
||
public IDatabaseInitialBuilder AddAdminUser() | ||
{ | ||
var user = new ApplicationUser() | ||
{ | ||
UserName = "Admin", | ||
Email = "[email protected]", | ||
FirstName = "TestName", | ||
LastName = "TestSurname" | ||
}; | ||
_userManager.CreateAsync(user, "Admin@1234").Wait(); | ||
_userManager.AddToRoleAsync(user, WebsiteRoles.WebsiteAdmin!).GetAwaiter().GetResult(); | ||
return this; | ||
} | ||
|
||
public IDatabaseInitialBuilder AddPages() | ||
{ | ||
_context.Pages!.AddRange(new List<Page>() | ||
{ | ||
new Page() | ||
{ | ||
Title = "About Us", | ||
Slug = "about" | ||
}, | ||
new Page() | ||
{ | ||
Title = "Contact Us", | ||
Slug = "contact" | ||
}, | ||
new Page() | ||
{ | ||
Title = "Privacy Policy", | ||
Slug = "privacy" | ||
} | ||
}); | ||
return this; | ||
} | ||
|
||
public IDatabaseInitialBuilder AddSettings() | ||
{ | ||
_context.Settings!.Add(new Setting | ||
{ | ||
SiteName = "Site Name", | ||
Title = "Site Title", | ||
ShortDescription = "Short Description of site" | ||
}); | ||
return this; | ||
} | ||
|
||
public void Build() | ||
{ | ||
_context.SaveChanges(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using BlogTemplate.Domain.Models; | ||
|
||
namespace BlogTemplate.Infrastructure; | ||
|
||
public interface IDatabaseInitialBuilder | ||
{ | ||
IDatabaseInitialBuilder AddAdminUser(); | ||
IDatabaseInitialBuilder AddPages(); | ||
IDatabaseInitialBuilder AddSettings(); | ||
void Build(); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.