예제 #1
0
        //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();
        }
예제 #2
0
 public UserManagementController(CourseworkContext dbContext, UserManager <User> userManager,
                                 RoleManager <IdentityRole> roleManager)
 {
     _dbContext   = dbContext;
     _userManager = userManager;
     _roleManager = roleManager;
 }
예제 #3
0
 public AccountController(UserManager <User> userManager, SignInManager <User> signInManager, RoleManager <IdentityRole> roleManager,
                          CourseworkContext context)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _roleManager   = roleManager;
     _context       = context;
     SeedUser();
 }
예제 #4
0
        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);
        }
예제 #5
0
파일: Startup.cs 프로젝트: OmegaOnion/Aloha
        // 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();
        }
예제 #6
0
 //takes Coursework context and user manage for database management
 public AnnouncementsController(CourseworkContext context, UserManager <User> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
예제 #7
0
 public CommentsController(CourseworkContext context)
 {
     _context = context;
 }
예제 #8
0
 public void SaveChanges()
 {
     CourseworkContext.SaveChanges();
 }
예제 #9
0
 public void Delete <TEntity>(TEntity entity) where TEntity : class
 {
     CourseworkContext.Set <TEntity>().Remove(entity);
 }
예제 #10
0
 public void AttachModified <TEntity>(TEntity entity) where TEntity : class
 {
     CourseworkContext.Set <TEntity>().Attach(entity);
     CourseworkContext.Entry(entity).State = EntityState.Modified;
 }
예제 #11
0
 public void Insert <TEntity>(TEntity entity) where TEntity : class
 {
     CourseworkContext.Set <TEntity>().Add(entity);
 }
예제 #12
0
 public IQueryable <TEntity> Query <TEntity>() where TEntity : class
 {
     return(CourseworkContext.Set <TEntity>());
 }