public static void EnsureSeeded(this EZmsContext context, string basePath) { if (!context.Content.Any()) { var types = JsonConvert.DeserializeObject <List <Content> >( File.ReadAllTextAsync($"{basePath}{Path.DirectorySeparatorChar}seed{Path.DirectorySeparatorChar}contents.json").GetAwaiter().GetResult() ); context.AddRange(types); context.SaveChanges(); } if (!context.Roles.Any()) { var roles = JsonConvert.DeserializeObject <List <IdentityRole> >( File.ReadAllTextAsync($"{basePath}{Path.DirectorySeparatorChar}seed{Path.DirectorySeparatorChar}roles.json").GetAwaiter().GetResult() ); context.AddRange(roles); context.SaveChanges(); } if (!context.Users.Any()) { var users = JsonConvert.DeserializeObject <List <IdentityUser> >( File.ReadAllTextAsync($"{basePath}{Path.DirectorySeparatorChar}seed{Path.DirectorySeparatorChar}users.json").GetAwaiter().GetResult() ); context.AddRange(users); context.SaveChanges(); var userManager = ServiceLocator.Current.GetInstance <UserManager <IdentityUser> >(); var user = userManager.FindByIdAsync(users.First().Id).GetAwaiter().GetResult(); var token = userManager.GeneratePasswordResetTokenAsync(user).GetAwaiter().GetResult(); var result = userManager.ResetPasswordAsync(user, token, "EZmsAdmin2019!").GetAwaiter().GetResult(); } if (!context.UserRoles.Any()) { var userRoles = JsonConvert.DeserializeObject <List <IdentityUserRole <string> > >( File.ReadAllTextAsync($"{basePath}{Path.DirectorySeparatorChar}seed{Path.DirectorySeparatorChar}userroles.json").GetAwaiter().GetResult() ); context.AddRange(userRoles); context.SaveChanges(); } }
public UsersModel(UserManager <IdentityUser> userManager, EZmsContext context) { _userManager = userManager; _context = context; }
public ContentRepository(EZmsContext context, IMapper mapper, IRouteDataCache routeDataCache) { _context = context; _mapper = mapper; _routeDataCache = routeDataCache; }