コード例 #1
0
        private static void InitializeFuelTypes(FuelDbContext context)
        {
            if (context.FuelTypes.Any())
            {
                return;
            }

            var entities = new List <FuelType>()
            {
                new FuelType {
                    Name = "АИ-80"
                },
                new FuelType {
                    Name = "АИ-92"
                },
                new FuelType {
                    Name = "АИ-95"
                },
                new FuelType {
                    Name = "АИ-98"
                },
                new FuelType {
                    Name = "Дизель"
                },
                new FuelType {
                    Name = "Газ"
                }
            };

            context.FuelTypes.AddRange(entities);
            context.SaveChanges();
        }
コード例 #2
0
        private static void InitializeAdminUsers(UserManager <ApplicationUser> userManager, FuelDbContext context)
        {
            if (context.AdminUsers.Any())
            {
                return;
            }

            const string email     = "*****@*****.**";
            const string password  = "******";
            var          adminUser = new SystemAdmin
            {
                Email         = email,
                UserName      = email,
                SecurityStamp = Guid.NewGuid().ToString()
            };

            Task <IdentityResult> adminDelegate() => userManager.CreateAsync(adminUser, password);

            var adminTask = Task.Factory.StartNew(adminDelegate).Unwrap();

            adminTask.Wait();

            if (adminTask.Result.Succeeded)
            {
                Task adminCanLoginDelegate() => userManager.AddClaimAsync(adminUser, new System.Security.Claims.Claim("CanLogin", "1"));

                var adminClaimTask = Task.Factory.StartNew(adminCanLoginDelegate).Unwrap();
                adminClaimTask.Wait();
            }
        }
コード例 #3
0
        public static void InitializePredefinedData(UserManager <ApplicationUser> userManager, FuelDbContext context)
        {
            InitializeAdminUsers(userManager, context);

            InitializeFuelTypes(context);
        }