-
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.
Merge pull request #3 from tungcbh/feat/multiImage
Feat/multi image
- Loading branch information
Showing
79 changed files
with
4,438 additions
and
611 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Bulky.DataAccess.Data; | ||
using Bulky.Models; | ||
using Bulky.Utility; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Bulky.DataAccess.DBInitializer | ||
{ | ||
public class DBInitializer : IDBInitializer | ||
{ | ||
private readonly UserManager<IdentityUser> _userManager; | ||
private readonly RoleManager<IdentityRole> _roleManager; | ||
private readonly ApplicationDbContext _db; | ||
|
||
public DBInitializer(UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, ApplicationDbContext db) | ||
{ | ||
_userManager = userManager; | ||
_roleManager = roleManager; | ||
_db = db; | ||
} | ||
|
||
public void Initialize() | ||
{ | ||
//Migrate | ||
try | ||
{ | ||
if (_db.Database.GetPendingMigrations().Count() > 0) | ||
{ | ||
_db.Database.Migrate(); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
||
} | ||
|
||
//Create roles | ||
if (!_roleManager.RoleExistsAsync(SD.Role_Customer).GetAwaiter().GetResult()) | ||
{ | ||
_roleManager.CreateAsync(new IdentityRole(SD.Role_Customer)).GetAwaiter().GetResult(); | ||
_roleManager.CreateAsync(new IdentityRole(SD.Role_Company)).GetAwaiter().GetResult(); | ||
_roleManager.CreateAsync(new IdentityRole(SD.Role_Employee)).GetAwaiter().GetResult(); | ||
_roleManager.CreateAsync(new IdentityRole(SD.Role_Admin)).GetAwaiter().GetResult(); | ||
|
||
//Create admin user | ||
_userManager.CreateAsync(new ApplicationUser | ||
{ | ||
UserName = "admin", | ||
Email = "[email protected]", | ||
Name = "Admin", | ||
PhoneNumber = "1234567890", | ||
StreetAddress = "ABC", | ||
State = "DEF", | ||
PostalCode = "1234567890", | ||
City = "NewYork", | ||
}, "Abcd1234@@").GetAwaiter().GetResult(); | ||
|
||
ApplicationUser user = _db.ApplicationUsers.FirstOrDefault(u => u.UserName == "admin"); | ||
_userManager.AddToRoleAsync(user, SD.Role_Admin).GetAwaiter().GetResult(); | ||
} | ||
return; | ||
} | ||
} | ||
} |
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,7 @@ | ||
namespace Bulky.DataAccess.DBInitializer | ||
{ | ||
public interface IDBInitializer | ||
{ | ||
void Initialize(); | ||
} | ||
} |
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
Oops, something went wrong.