Пример #1
0
        public async Task EnsureSeedDataAsync()
        {
            if (await _userManager.FindByNameAsync("bobbytables") == null &&
                await _userManager.FindByEmailAsync("*****@*****.**") == null)
            {
                // Add the user.
                var newUser = new BallotboxUser()
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };

                await _userManager.CreateAsync(newUser, "P@ssw0rd!");
            }

            if (!_context.Polls.Any())
            {
                // Add new data
                var cokeOrPepsiPoll = new Poll()
                {
                    Name    = "Coke or Pepsi?",
                    User    = await _userManager.FindByNameAsync("bobbytables"),
                    Choices = new List <Choice>()
                    {
                        new Choice()
                        {
                            Name = "Pepsi"
                        },
                        new Choice()
                        {
                            Name = "Coke"
                        },
                        new Choice()
                        {
                            Name = "Neither"
                        }
                    }
                };

                _context.Polls.Add(cokeOrPepsiPoll);
                _context.Choices.AddRange(cokeOrPepsiPoll.Choices);

                _context.SaveChanges();
            }
        }
Пример #2
0
 public bool SaveAll()
 {
     return(_context.SaveChanges() > 0);
 }