public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scop = host.Services.CreateScope())
            {
                using (JobbyContext dbContext = scop.ServiceProvider.GetRequiredService <JobbyContext>())
                {
                    using (var userManager = scop.ServiceProvider.GetRequiredService <UserManager <User> >())
                    {
                        using (var roleManager = scop.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >())
                        {
                            try
                            {
                                Sample.Initialize(dbContext, userManager, roleManager);
                            }
                            catch (Exception ex)
                            {
                                var logger = scop.ServiceProvider.GetRequiredService <ILogger <Program> >();
                                logger.LogError(ex, "dont correct add method");
                            }
                        }
                    }
                }
            }

            host.Run();
        }
Пример #2
0
        public static void Initialize(JobbyContext context, UserManager <User> userManager, RoleManager <IdentityRole> roleManager)
        {
            if (!context.Roles.Any())
            {
                IdentityRole identityRole  = new IdentityRole("Admin");
                IdentityRole identityRole2 = new IdentityRole("User");
                roleManager.CreateAsync(identityRole).GetAwaiter().GetResult();
                roleManager.CreateAsync(identityRole2).GetAwaiter().GetResult();
            }
            if (!context.Users.Any())
            {
                User user = new User
                {
                    UserName = "******",
                    Fullname = "Panah Haciyev",
                    Image    = "user1.img",
                    Email    = "*****@*****.**"
                };
                IdentityResult identityResult = userManager.CreateAsync(user, "panah123").GetAwaiter().GetResult();

                if (identityResult.Succeeded)
                {
                    userManager.AddToRoleAsync(user, "Admin").GetAwaiter().GetResult();
                }
            }
            if (!context.Categoryies.Any())
            {
                context.Categoryies.AddRange(
                    new Categoryy
                {
                    Name = "Play Group"
                },
                    new Categoryy
                {
                    Name = "Primary"
                },
                    new Categoryy {
                    Name = "Story"
                }

                    );
                context.SaveChanges();
            }
        }
Пример #3
0
 public TeacherrsController(JobbyContext context, IHostingEnvironment env)
 {
     _context = context;
     _env     = env;
 }
 public BlogCategoriesController(JobbyContext context)
 {
     _context = context;
 }
Пример #5
0
 public ClasessController(JobbyContext _context)
 {
     context = _context;
 }
 public SingleClasController(JobbyContext _context)
 {
     context = _context;
 }
Пример #7
0
 public AgesController(JobbyContext context)
 {
     _context = context;
 }
 public BlogsController(JobbyContext context)
 {
     _context = context;
 }
 public ClassroommsController(JobbyContext context)
 {
     _context = context;
 }
 public HomeController(JobbyContext context)
 {
     _context = context;
 }
 public BlogMassonryController(JobbyContext _context, UserManager <User> userManager)
 {
     context      = _context;
     _userManager = userManager;
 }
Пример #12
0
 public TeacherssController(JobbyContext _context)
 {
     context = _context;
 }
 public AjaxController(JobbyContext _context, UserManager <User> userManager)
 {
     context      = _context;
     _userManager = userManager;
 }