public List <Thread> SearchForUsersAndThreads(String searchString) { // ASSUMPTION: search string could be a username OR a threadname // therefore, the search will be conducted here since the User domain model has a Thread // search user list // add the user's thread if the username matches the searchString List <Thread> threadSearchResult = new List <Thread>(); List <StandardUser> userList = GetUsers(); foreach (StandardUser u in userList) { if (u.Name == searchString) { threadSearchResult.Add(u.OwnedThread); } } // then // search thread list // add the thread to search results if the thread matches the searchString List <Thread> threads = new RealThreadRepo(context).GetThreads(); foreach (Thread t in threads) { if (t.Name == searchString) { threadSearchResult.Add(t); } } return(threadSearchResult); }
public static void Seed(IApplicationBuilder app) { AppDbContext context = app.ApplicationServices.GetRequiredService <AppDbContext>(); context.Database.EnsureCreated(); if (!context.StandardUsers.Any()) { RealUserRepo userRepo = new RealUserRepo(context); RealThreadRepo threadRepo = new RealThreadRepo(context); // Add users const string username = "******"; const string password = "******"; const string gender = "female"; DateTime dateJoinedD = DateTime.Now; StandardUser newUser = new StandardUser() // user1 { Name = username, Password = password, ConfirmPassword = password, Gender = gender, DateJoined = dateJoinedD }; const string bio = "hello there friends"; const string name = "testThread1"; string creatorName = newUser.Name; string category = ThreadCategories.GetCategory(0); Thread thread1 = new Thread() { Name = name, CreatorName = creatorName, Bio = bio, Category = category }; threadRepo.AddThreadtoRepo(thread1); newUser.OwnedThread = thread1; userRepo.AddUsertoRepo(newUser); // ----------------------------------------> const string username2 = "Robert"; const string password2 = "5678"; const string gender2 = "male"; DateTime dateJoinedD2 = DateTime.Now; StandardUser newUser2 = new StandardUser() // user2 { Name = username2, Password = password2, ConfirmPassword = password2, Gender = gender2, DateJoined = dateJoinedD2 }; const string bio2 = "hello there friends"; const string name2 = "testThread2"; string creatorName2 = newUser2.Name; string category2 = ThreadCategories.GetCategory(1); Thread thread2 = new Thread() { Name = name2, CreatorName = creatorName2, Bio = bio2, Category = category2 }; threadRepo.AddThreadtoRepo(thread2); newUser2.OwnedThread = thread2; userRepo.AddUsertoRepo(newUser2); // ----------------------------------------> const string username3 = "Jim"; const string password3 = "1011"; const string gender3 = "male"; DateTime dateJoinedD3 = DateTime.Now; StandardUser newUser3 = new StandardUser() // user2 { Name = username3, Password = password3, ConfirmPassword = password3, Gender = gender3, DateJoined = dateJoinedD3 }; const string bio3 = "hello there friends"; const string name3 = "testThread3"; string creatorName3 = newUser3.Name; string category3 = ThreadCategories.GetCategory(2); Thread thread3 = new Thread() { Name = name3, CreatorName = creatorName3, Bio = bio3, Category = category3 }; threadRepo.AddThreadtoRepo(thread3); newUser3.OwnedThread = thread3; userRepo.AddUsertoRepo(newUser3); // ----------------------------------------> } }