//private readonly CourseworkContext _context; //private readonly UserManager<User> _userManager; public MemberSeed(CourseworkContext context, UserManager <User> userManager) { //_context = context; var user = new User { UserName = "******", Email = "*****@*****.**", FirstName = "Member", LastName = "1", }; if (!context.Users.Any(u => u.UserName == user.UserName)) { userManager.CreateAsync(user, "password"); userManager.AddToRoleAsync(user, "Admin"); } //var password = new PasswordHasher<User>(); //var hashed = password.HashPassword(user, "password"); // context.Users.Add(user); //await context.SaveChangesAsync(); //Seed(); }
public UserManagementController(CourseworkContext dbContext, UserManager <User> userManager, RoleManager <IdentityRole> roleManager) { _dbContext = dbContext; _userManager = userManager; _roleManager = roleManager; }
public AccountController(UserManager <User> userManager, SignInManager <User> signInManager, RoleManager <IdentityRole> roleManager, CourseworkContext context) { _userManager = userManager; _signInManager = signInManager; _roleManager = roleManager; _context = context; SeedUser(); }
private CourseworkContext CreateCourseworkContext() { var courseworkContext = new CourseworkContext(_dataContextSettings.ConnectionString); courseworkContext.Configuration.ProxyCreationEnabled = false; if (_explicitOpenConnection) { if (courseworkContext.Database.Connection.State != System.Data.ConnectionState.Open) { courseworkContext.Database.Connection.Open(); } } return(courseworkContext); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CourseworkContext context, UserManager <User> userManager) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( "404-PageNotFound", "{*url}", new { controller = "Home", action = "PageNotFound" }); }); context.Database.Migrate(); // Calls services needed to seed roles then calls seed method. new UserRoleSeed(app.ApplicationServices.GetService <RoleManager <IdentityRole> >()).Seed(); //new MemberSeed(context, userManager); // seeder.Seed(); }
//takes Coursework context and user manage for database management public AnnouncementsController(CourseworkContext context, UserManager <User> userManager) { _context = context; _userManager = userManager; }
public CommentsController(CourseworkContext context) { _context = context; }
public void SaveChanges() { CourseworkContext.SaveChanges(); }
public void Delete <TEntity>(TEntity entity) where TEntity : class { CourseworkContext.Set <TEntity>().Remove(entity); }
public void AttachModified <TEntity>(TEntity entity) where TEntity : class { CourseworkContext.Set <TEntity>().Attach(entity); CourseworkContext.Entry(entity).State = EntityState.Modified; }
public void Insert <TEntity>(TEntity entity) where TEntity : class { CourseworkContext.Set <TEntity>().Add(entity); }
public IQueryable <TEntity> Query <TEntity>() where TEntity : class { return(CourseworkContext.Set <TEntity>()); }