示例#1
0
        private async Task SeedDatabase(AppDbcontext context, UserManager <ApplicationUser> userManager)
        {
            if (!await context.Users.AnyAsync())
            {
                var user = new ApplicationUser {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };
                var result = await userManager.CreateAsync(user, "Guest1!");

                if (!result.Succeeded)
                {
                    throw new ApplicationException("Could not created default user");
                }

                context.KnuxPhrases.Add(new KnuxPhrase {
                    Owner     = user,
                    KnuxValue = "punk cats"
                });

                context.KnuxPhrases.Add(new KnuxPhrase {
                    KnuxValue = "funk bats"
                });

                context.SaveChanges();
            }
        }
示例#2
0
        // // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        // public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        // {
        //     if (env.IsDevelopment())
        //     {
        //         app.UseDeveloperExceptionPage();
        //     }
        //     else
        //     {
        //         app.UseHsts();
        //     }

        //     app.UseHttpsRedirection();
        //    // app.UseMvc();
        //    app.UseJsonApi();
        // }


        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              AppDbcontext context,
                              UserManager <ApplicationUser> userManager
                              )
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));

            var logger = loggerFactory.CreateLogger <Startup>();

            logger.LogInformation($"Starting application in {env.EnvironmentName} environment");

            app.UseAuthentication();

            if (env.IsDevelopment())
            {
                app.UseCors(builder => {
                    builder.WithOrigins("http://localhost:4200")
                    //only use the following for dev, do not use for production
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials();
                });
            }

            app.UseJsonApi();

            SeedDatabase(context, userManager).Wait();
        }
 public KnuxPhraseRepository(
     AppDbcontext context,
     ILoggerFactory loggerFactory,
     IJsonApiContext jsonApiContext,
     IAuthenticationService authenticationService)
     : base(loggerFactory, jsonApiContext)
 {
     _context = context;
     _logger  = loggerFactory.CreateLogger <KnuxPhraseRepository>();
     _authenticationService = authenticationService;
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, AppDbcontext ctx, RoleManager <IdentityRole> roleManager, UserManager <ApplicationUser> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();
            app.UseAuthorization();
            app.UseAuthentication();

            Seeder.Seeder.Seeding(ctx, roleManager, userManager).Wait();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
        public static async Task Seeding(AppDbcontext ctx, RoleManager <IdentityRole> roleManager, UserManager <ApplicationUser> userManager)
        {
            // chosse role
            ctx.Database.EnsureCreated();
            if (!roleManager.Roles.Any())
            {
                var listofRoles = new List <IdentityRole>()
                {
                    new IdentityRole("User")
                };

                foreach (var role in listofRoles)
                {
                    await roleManager.CreateAsync(role);
                }
            }
            // populate user

            if (!userManager.Users.Any())
            {
                var listofUsers = new List <ApplicationUser>()
                {
                    // new user
                    new ApplicationUser {
                        UserName = "******", Email = "*****@*****.**", LastName = "Mike", FirstName = "Mike", Photo = "~/images/avarta.jpg"
                    },
                    new ApplicationUser {
                        UserName = "******", Email = "*****@*****.**", LastName = "Frank", FirstName = "Frank", Photo = "~/images/avarta.jpg"
                    }
                };

                // assign password
                foreach (var user in listofUsers)
                {
                    var result = await userManager.CreateAsync(user, "P@$$word1");

                    if (result.Succeeded)
                    {
                        await userManager.AddToRoleAsync(user, "User");
                    }
                }
            }
        }
 public BlogViewComponent(AppDbcontext db)
 {
     _db = db;
 }
 public HomeController(AppDbcontext db)
 {
     _db = db;
 }
 public NoticeBoardViewComponent(AppDbcontext db)
 {
     _db = db;
 }
 public EventController(AppDbcontext db)
 {
     _db = db;
 }
 public NoticeProfessionController(AppDbcontext db)
 {
     _db = db;
 }
示例#11
0
 public ContractRepository(AppDbcontext context)
 {
     this.context = context;
 }
 public WelcomeToEduhomeController(AppDbcontext db, IWebHostEnvironment env)
 {
     _db  = db;
     _env = env;
 }
 public NewManagmentController(AppDbcontext db, IWebHostEnvironment env)
 {
     _db  = db;
     _env = env;
 }
示例#14
0
 public TeacherController(AppDbcontext db)
 {
     _db = db;
 }
 public CarrierRepository(AppDbcontext context)
 {
     this.context = context;
 }
 public AdvisorRepository(AppDbcontext context)
 {
     this.context = context;
 }
 public CourseViewComponent(AppDbcontext db)
 {
     _db = db;
 }
示例#18
0
 public ActivityRepository(AppDbcontext context)
 {
     _context = context;
 }
示例#19
0
 public UnitOfWork(AppDbcontext context)
 {
     _context = context;
 }
示例#20
0
 public LoginRepository(AppDbcontext context) : base(context)
 {
 }
示例#21
0
 public TestimonialController(AppDbcontext db, IWebHostEnvironment env)
 {
     _db  = db;
     _env = env;
 }
 public CourseController(AppDbcontext db)
 {
     _db = db;
 }
示例#23
0
 public ContactController(AppDbcontext db)
 {
     _db = db;
 }
 public HeaderTwoViewComponent(AppDbcontext db, UserManager <User> userManager)
 {
     _db          = db;
     _userManager = userManager;
 }
 public OpcionComidaRepository(AppDbcontext context) : base(context)
 {
 }
示例#26
0
 public TakeVideoController(AppDbcontext db)
 {
     _db = db;
 }
示例#27
0
 public TeacherViewComponent(AppDbcontext db)
 {
     _db = db;
 }
 public AjaxController(AppDbcontext db)
 {
     _db = db;
 }
 public BlogController(AppDbcontext db, IWebHostEnvironment env)
 {
     _db  = db;
     _env = env;
 }
 public AboutController(AppDbcontext db)
 {
     _db = db;
 }