internal static async Task UpdateUser(RivingtonContext context, UserManager <ApplicationUser> userManager, UserForSeeder userForSeeder) { var existingUser = await userManager.FindByNameAsync(userForSeeder.AppUser.UserName); if (existingUser == null) { await CreateUser(userManager, userForSeeder); } else { existingUser.LastModifiedDate = DateTime.Now; existingUser.UserName = userForSeeder.AppUser.UserName; existingUser.Email = userForSeeder.AppUser.Email; existingUser.EmailConfirmed = userForSeeder.AppUser.EmailConfirmed; existingUser.LockoutEnabled = userForSeeder.AppUser.LockoutEnabled; existingUser.PasswordHash = userForSeeder.AppUser.PasswordHash; var existingRoles = await userManager.GetRolesAsync(existingUser); await userManager.RemoveFromRolesAsync(existingUser, existingRoles); foreach (var role in userForSeeder.Roles) { await userManager.AddToRoleAsync(existingUser, role); } await userManager.UpdateAsync(existingUser); } await context.SaveChangesAsync(); }
public static void Seed(RivingtonContext context, UserManager <ApplicationUser> userManager) { CreateSystemUser(context, userManager) .GetAwaiter() .GetResult(); }
private static async Task CreateSystemUser(RivingtonContext context, UserManager <ApplicationUser> userManager) { // local variables var dateNow = DateTime.Now; // Create the "System" ApplicationUser account { var apiSystemUser = UserSeeder.Configuration.GetSection("ApiSystemUser"); await UserSeeder.UpdateUser(context, userManager, new UserForSeeder { AppUser = new ApplicationUser() { SecurityStamp = Guid.NewGuid().ToString(), UserName = apiSystemUser["UserName"], Email = UserSeeder.CreateEmail(Roles.System), CreatedDate = dateNow, LastModifiedDate = dateNow, EmailConfirmed = true, LockoutEnabled = false }, Password = apiSystemUser["Password"], Roles = new [] { Roles.System } }); } await context.SaveChangesAsync(); }
public TokenController( RivingtonContext context, RoleManager <ApplicationRole> roleManager, UserManager <ApplicationUser> userManager, IConfiguration configuration, IInspectionOrderRepository inspectionOrderRepository) : base(context, roleManager, userManager, configuration) { _inspectionOrderRepository = inspectionOrderRepository; }
public static void Seed(RivingtonContext context, UserManager <ApplicationUser> userManager) { if (!context.Users.Any(u => !u.UserName.Equals(Roles.System))) { CreateUsers(context, userManager) .GetAwaiter() .GetResult(); } }
public static void Seed(RivingtonContext context, RoleManager <ApplicationRole> roleManager) { if (!context.Role.Any()) { CreateRoles(context, roleManager) .GetAwaiter() .GetResult(); } }
public ThirdPartyPolicyRepository(RivingtonContext context, ICityRepository cityRepository, IStateRepository stateRepository, IMapService mapService, UserManager <ApplicationUser> userManager) : base(context) { _context = context; _cityRepository = cityRepository; _userManager = userManager; _stateRepository = stateRepository; _mapService = mapService; }
public InpsectionOrderNotesController( IInspectionOrderNotesRepository inspectionOrderNotesRepository, IInspectionOrderNotesService inspectionOrderNotesService, RivingtonContext context, RoleManager <ApplicationRole> roleManager, UserManager <ApplicationUser> userManager, IConfiguration configuration) : base(context, roleManager, userManager, configuration) { this.inspectionOrderNotesRepository = inspectionOrderNotesRepository; this.inspectionOrderNotesService = inspectionOrderNotesService; }
public AccountController( RivingtonContext context, RoleManager <ApplicationRole> roleManager, UserManager <ApplicationUser> userManager, IConfiguration configuration, IAccountcontrollerService accountcontrollerService, IForgotPasswordService forgotPasswordService, IForgotPasswordRepository forgotPasswordRepository ) : base(context, roleManager, userManager, configuration) { this.accountcontrollerService = accountcontrollerService; this.forgotPasswordService = forgotPasswordService; this.forgotPasswordRepository = forgotPasswordRepository; }
public InspectionOrderController( IInspectionOrderRepository inspectionOrderRepository, IInspectionOrderService inspectionOrderService, InspectionOrderMitigationController inspectionOrderMitigationController, IWkHtmlToPdfService wkHtmlToPdfService, RivingtonContext rivingtonContext, IInspectionOrderLog inspectionOrderLog ) { _inspectionOrderRepository = inspectionOrderRepository; _inspectionOrderService = inspectionOrderService; _inspectionOrderMitigationController = inspectionOrderMitigationController; _wkHtmlToPdfService = wkHtmlToPdfService; _rivingtonContext = rivingtonContext; _inspectionOrderLog = inspectionOrderLog; }
public BaseApiController( RivingtonContext context, RoleManager <ApplicationRole> roleManager, UserManager <ApplicationUser> userManager, IConfiguration configuration ) { // Instantiate the required classes through DI DbContext = context; RoleManager = roleManager; DbContext = context; UserManager = userManager; Configuration = configuration; // Instantiate a single JsonSerializerSettings object // that can be reused multiple times. JsonSettings = new JsonSerializerSettings() { Formatting = Formatting.Indented }; }
public UserController( RivingtonContext context, RoleManager <ApplicationRole> roleManager, UserManager <ApplicationUser> userManager, IConfiguration configuration, IAccountRepository accountRepository, IAccountRoleRepository accountRoleRepository, IAccountUserRoleRepository accountUserRoleRepository, IInspectionOrderMitigationRepository ioMitigationRepository, IImageService imageService ) : base(context, roleManager, userManager, configuration) { _accountRepository = accountRepository; _accountRoleRepository = accountRoleRepository; _accountUserRoleRepository = accountUserRoleRepository; _ioMitigationRepository = ioMitigationRepository; _imageService = imageService; }
private static async Task CreateRoles(RivingtonContext context, RoleManager <ApplicationRole> roleManager) { //Enum.GetNames(typeof(Roles)).ToList().ForEach(async role => //{ // //Create Roles (if they doesn't exist yet) // if (!await roleManager.RoleExistsAsync(role)) { // await roleManager.CreateAsync(new ApplicationRole(role)); // } //}); var roles = new[] { Roles.System, Roles.Administrator, Roles.UnderWriter, Roles.InspectorManager, Roles.Inspector, Roles.Insured, Roles.ReadOnly }; foreach (var role in roles) { //Create Roles (if they doesn't exist yet) if (!await roleManager.RoleExistsAsync(role)) { await roleManager.CreateAsync(new ApplicationRole(role)); } } await context.SaveChangesAsync(); }
private static async Task CreateUsers(RivingtonContext context, UserManager <ApplicationUser> userManager) { // local variables var createdDate = DateTime.Now; var lastModifiedDate = createdDate; //#if DEBUG // Create sample user account for each role var users = new [] { new UserForSeeder { AppUser = new ApplicationUser { SecurityStamp = Guid.NewGuid().ToString(), UserName = $"{Roles.Administrator.ToLower()}_user", Email = CreateEmail(Roles.Administrator), CreatedDate = createdDate, LastModifiedDate = lastModifiedDate, EmailConfirmed = true, LockoutEnabled = false }, Password = $"P@ss4{Roles.Administrator}", Roles = new[] { Roles.Administrator } }, new UserForSeeder { AppUser = new ApplicationUser { SecurityStamp = Guid.NewGuid().ToString(), UserName = $"{Roles.UnderWriter.ToLower()}_user", Email = CreateEmail(Roles.UnderWriter), CreatedDate = createdDate, LastModifiedDate = lastModifiedDate, EmailConfirmed = true, LockoutEnabled = false }, Password = $"P@ss4{Roles.UnderWriter}", Roles = new[] { Roles.UnderWriter } }, new UserForSeeder { AppUser = new ApplicationUser { SecurityStamp = Guid.NewGuid().ToString(), UserName = $"{Roles.InspectorManager.ToLower()}_user", Email = CreateEmail(Roles.InspectorManager), CreatedDate = createdDate, LastModifiedDate = lastModifiedDate, EmailConfirmed = true, LockoutEnabled = false }, Password = $"P@ss4{Roles.InspectorManager}", Roles = new[] { Roles.InspectorManager } }, new UserForSeeder { AppUser = new ApplicationUser { SecurityStamp = Guid.NewGuid().ToString(), UserName = $"{Roles.Inspector.ToLower()}_user", Email = CreateEmail(Roles.Inspector), CreatedDate = createdDate, LastModifiedDate = lastModifiedDate, EmailConfirmed = true, LockoutEnabled = false }, Password = $"P@ss4{Roles.Inspector}", Roles = new[] { Roles.Inspector } } }; foreach (var user in users) { await CreateUser(userManager, user); } //#endif await context.SaveChangesAsync(); }
public StaticContentRepository(RivingtonContext context) : base(context) { _context = context; }
public UtilityController(IStateRepository stateRepository, RivingtonContext context) { _stateRepository = stateRepository; _context = context; }