Beispiel #1
0
        public async Task SeedAsync()
        {
            _context.Database.EnsureCreated();

            User user = await _userManager.FindByNameAsync("admin");

            if (user == null)
            {
                user = new User()
                {
                    CompanyID = "admin@CRM",
                    UserName  = "******"
                };

                var result = await _userManager.CreateAsync(user, "P@ssw0rd");

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Could not create user in Seeding");
                }
            }

            //if (!_userManager.Users.Any())
            //{
            //    User user = new User()
            //    {
            //        CompanyID = "admin@CRM",
            //        UserName = "******"
            //    };

            //    var result =  _userManager.CreateAsync(user, "P@ssw0rd").Result;
            //    if (result != IdentityResult.Success)
            //    {
            //        throw new InvalidOperationException("Could not create a new user in seeder");
            //    }
            //}

            if (!_context.Cities.Any())
            {
                _context.Cities.Add(new City
                {
                    Name = "Tel Aviv"
                });
                _context.Cities.Add(new City
                {
                    Name = "Petach Tiqwa"
                });
                _context.Cities.Add(new City
                {
                    Name = "Jerusalem"
                });

                _context.PrimaryBusinessFields.Add(new PrimaryBusinessField
                {
                    Name = "Hi-Tech",
                    SecondaryBusinessFields = new List <SecondaryBusinessField>()
                    {
                        new SecondaryBusinessField()
                        {
                            Name = "Software"
                        },
                        new SecondaryBusinessField()
                        {
                            Name = "QA"
                        },
                        new SecondaryBusinessField()
                        {
                            Name = "Communication"
                        },
                        new SecondaryBusinessField()
                        {
                            Name = "DevOps"
                        }
                    }
                });
            }

            _context.SaveChanges();
        }
Beispiel #2
0
 public bool SaveAll()
 {
     return(_context.SaveChanges() > 0);
 }