public void SetupDb() { using (var context = new SocialBackendContext(options)) { User userA = new User() { username = usernames[0], emailAddress = emails[0], password = hashedPasswords[0], authToken = authTokens[0] }; users.Add(userA); User userB = new User() { username = usernames[1], emailAddress = emails[1], password = hashedPasswords[1], authToken = authTokens[1] }; users.Add(userB); context.User.Add(userA); context.User.Add(userB); context.SaveChanges(); Todo todoA = new Todo() { task = tasks[0], dueDate = dueDates[0], complete = completes[0], user = context.User.Where(u => u.username == users[0].username).AsNoTracking().FirstOrDefault() }; todos.Add(todoA); Todo todoB = new Todo() { task = tasks[1], dueDate = dueDates[1], complete = completes[1], user = context.User.Where(u => u.username == users[1].username).AsNoTracking().FirstOrDefault() }; todos.Add(todoB); context.Todo.Add(todoA); context.Todo.Add(todoB); context.SaveChanges(); } }
public void SetupDb() { using (var context = new SocialBackendContext(options)) { User userA = new User() { username = usernames[0], emailAddress = emails[0], password = hashedPasswords[0], authToken = authTokens[0] }; users.Add(userA); User userB = new User() { username = usernames[1], emailAddress = emails[1], password = hashedPasswords[1], authToken = authTokens[1] }; users.Add(userB); context.User.Add(userA); context.User.Add(userB); context.SaveChanges(); } }
public void ClearDb() { using (var context = new SocialBackendContext(options)) { context.User.RemoveRange(context.User); context.SaveChanges(); }; i = 999; }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new SocialBackendContext( serviceProvider.GetRequiredService <DbContextOptions <SocialBackendContext> >())) { if (context.User.Count() == 0) { context.User.AddRange( new User { username = "******", password = "******", emailAddress = "*****@*****.**", authToken = Guid.NewGuid().ToString(), online = false }); } context.SaveChanges(); if (context.Todo.Count() == 0) { context.Todo.AddRange( new Todo { task = "Finish coding todo API", dueDate = DateTime.Now.AddDays(1), complete = false, user = context.User.FirstOrDefault() }, new Todo { task = "Finish social work app", dueDate = DateTime.Now.AddDays(2), complete = false, user = context.User.FirstOrDefault() }); } context.SaveChanges(); } }