Example #1
0
        private static async Task SeedUsersAsAdmins()
        {
            if (_context.Admins.Any())
            {
                return;
            }
            var             adminDataSection = _configuration.GetSection(GlobalVariables.AdminSectionNameOfConfigFile);
            ApplicationUser userAdmin        = new ApplicationUser {
                Email         = adminDataSection.GetValue <string>("email"),
                UserName      = adminDataSection.GetValue <string>("userName"),
                SecurityStamp = Guid.NewGuid().ToString()
            };
            await _userManager.AddPasswordAsync(userAdmin, "Admin@123");

            await _userManager.CreateAsync(userAdmin);

            await _userManager.AddToRoleAsync(userAdmin, GlobalVariables.AdminRole);

            var admin = new Admin {
                id = userAdmin.Id, fullName = adminDataSection.GetValue <string>("fullName")
            };

            _context.Admins.Add(admin);
            _context.SaveChanges();
        }
Example #2
0
        public static async Task ResetData(Atlob_dent_Context context)
        {
            var userManager   = ServiceHelper.GetUserManager();
            var customerUsers = await userManager.GetUsersInRoleAsync(GlobalVariables.CustomerRole);

            foreach (var user in  customerUsers)
            {
                await userManager.DeleteAsync(user);
            }
            context.Comments.RemoveRange(context.Comments);
            context.SaveChanges();

            /*context.Customers.RemoveRange(context.Customers);
             * context.SaveChanges();
             * context.Orders.RemoveRange(context.Orders);
             * context.SaveChanges();
             * context.Products.RemoveRange(context.Products);
             * context.SaveChanges();*/
            context.Companies.RemoveRange(context.Companies);
            context.SaveChanges();
            context.Categories.RemoveRange(context.Categories);
            context.SaveChanges();
        }
Example #3
0
        private static void SeedProducts()
        {
            var            fileJsonPath = Path.Combine(ServiceHelper.GetHostingEnv().ContentRootPath, "DataSeeds", "products.json");
            var            jsonData     = File.ReadAllText(fileJsonPath);
            List <Product> Products     =
                JsonConvert.DeserializeObject <List <Product> >(jsonData);

            if (!context.Products.Any())
            {
                context.Products.AddRange(Products);
                context.SaveChanges();
            }
        }