-
Notifications
You must be signed in to change notification settings - Fork 0
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
8 changed files
with
57 additions
and
31 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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Nezam.Modular.ESS.Identity.Domain.Shared.User; | ||
using Nezam.Modular.ESS.Identity.Domain.User; | ||
using Payeh.SharedKernel.UnitOfWork; | ||
|
@@ -7,35 +8,37 @@ namespace Nezam.Modular.ESS.Infrastructure.Data.Seeds; | |
|
||
public class IdentitySeedService : BackgroundService | ||
{ | ||
private readonly IUserDomainService _domainService; | ||
private readonly IUnitOfWork _unitOfWorkManager; | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public IdentitySeedService(IUserDomainService domainService, IUnitOfWork unitOfWorkManager) | ||
public IdentitySeedService(IServiceProvider serviceProvider) | ||
{ | ||
_domainService = domainService; | ||
_unitOfWorkManager = unitOfWorkManager; | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
|
||
var find = await _domainService.GetUserByUsernameAsync(new UserNameValue("admin")); | ||
|
||
if (find.IsSuccess) | ||
{ | ||
var user = find.Data; | ||
user.UpdateProfile(new UserProfileValue("/default","admin","administrator")); | ||
await _domainService.UpdateAsync(user); | ||
} | ||
else | ||
using (var scope = _serviceProvider.CreateScope()) | ||
{ | ||
var profile = new UserProfileValue("/default","admin","administrator"); | ||
var user = new UserEntity(UserId.NewId(), new UserNameValue("admin"), new UserPasswordValue("Admin@123456"), | ||
profile, new UserEmailValue("[email protected]")); | ||
await _domainService.Create(user); | ||
} | ||
var domainService = scope.ServiceProvider.GetRequiredService<IUserDomainService>(); | ||
var unitOfWorkManager = scope.ServiceProvider.GetRequiredService<IUnitOfWork>(); | ||
|
||
var find = await domainService.GetUserByUsernameAsync(new UserNameValue("admin")); | ||
|
||
await _unitOfWorkManager.CommitAsync(); | ||
if (find.IsSuccess) | ||
{ | ||
var user = find.Data; | ||
user.UpdateProfile(new UserProfileValue("/default", "admin", "administrator")); | ||
await domainService.UpdateAsync(user); | ||
} | ||
else | ||
{ | ||
var profile = new UserProfileValue("/default", "admin", "administrator"); | ||
var user = new UserEntity(UserId.NewId(), new UserNameValue("admin"), | ||
new UserPasswordValue("Admin@123456"), profile, new UserEmailValue("[email protected]")); | ||
await domainService.Create(user); | ||
} | ||
|
||
await unitOfWorkManager.CommitAsync(); | ||
} | ||
} | ||
} |
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