-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Migrations): Complete Migrations (#23)
* first commit * Add initial data. * Complete & Fix Migrations project. * add permissions. --------- Co-authored-by: sadq <[email protected]>
- Loading branch information
1 parent
fba7e29
commit b90c915
Showing
14 changed files
with
137 additions
and
57 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,79 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using RelationshipAnalysis.Context; | ||
using RelationshipAnalysis.Models.Auth; | ||
using RelationshipAnalysis.Services.UserPanelServices.Abstraction.AuthServices; | ||
|
||
namespace RelationAnalysis.Migrations; | ||
|
||
public class InitialRecordsCreator(ApplicationDbContext context, IConfiguration configuration) | ||
{ | ||
public async Task AddInitialRecords() | ||
{ | ||
var roles = new List<Role>() | ||
{ | ||
new Role() | ||
{ | ||
Name = "Admin", | ||
Permissions = | ||
"'[\"/api/Access/GetPermissions\",\"/api/Admin/GetUser/{id}\",\"/api/Admin/GetAllUser\",\"/api/Admin/GetAllRoles\",\"/api/Admin/UpdateUser/{id}\",\"/api/Admin/UpdatePassword/{id}\",\"/api/Admin/DeleteUser/{id}\",\"/api/Admin/CreateUser\",\"/api/Admin/UpdateRoles/{id}\",\"/api/Auth/Login\", \"/api/User/GetUser\",\"/api/User/UpdateUser\",\"/api/User/UpdatePassword\",\"/api/User/Logout\"]'", | ||
Id = 1 | ||
}, | ||
new Role() | ||
{ | ||
Name = "DataAdmin", | ||
Permissions = | ||
"'[\"/api/Access/GetPermissions\",\"/api/Auth/Login\",\"/api/User/GetUser\",\"/api/User/UpdateUser\",\"/api/User/UpdatePassword\",\"/api/User/Logout\"]'", | ||
Id = 2 | ||
}, | ||
new Role() | ||
{ | ||
Name = "DataAnalyst", | ||
Permissions = | ||
"'[\"/api/Access/GetPermissions\",\"/api/Auth/Login\",\"/api/User/GetUser\",\"/api/User/UpdateUser\",\"/api/User/UpdatePassword\",\"/api/User/Logout\"]'", | ||
Id = 3 | ||
} | ||
}; | ||
var userRoles = new List<UserRole>() | ||
{ | ||
new UserRole() | ||
{ | ||
UserId = 1, | ||
RoleId = 1 | ||
}, | ||
new UserRole() | ||
{ | ||
UserId = 1, | ||
RoleId = 2 | ||
}, | ||
new UserRole() | ||
{ | ||
UserId = 1, | ||
RoleId = 3 | ||
} | ||
}; | ||
var users = new List<User>() | ||
{ | ||
new User() | ||
{ | ||
Username = "admin", | ||
PasswordHash = new CustomPasswordHasher() | ||
.HashPassword(configuration.GetValue<string>("DefaultPassword")), | ||
FirstName = "FirstName", | ||
LastName = "LastName", | ||
Email = "[email protected]", | ||
Id = 1, | ||
} | ||
}; | ||
try | ||
{ | ||
await context.Roles.AddRangeAsync(roles); | ||
await context.Users.AddRangeAsync(users); | ||
await context.UserRoles.AddRangeAsync(userRoles); | ||
await context.SaveChangesAsync(); | ||
} | ||
catch | ||
{ | ||
Console.WriteLine("Data already exists!"); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"DefaultPassword": "admin" | ||
} |
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 |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
public interface IPasswordHasher | ||
{ | ||
string HashPassword(string input); | ||
string HashPassword(string? input); | ||
} |
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