Example #1
0
        public List <Thread> GetCategoryOfThreads(int categoryIndex)
        {
            string        CATEGORY = ThreadCategories.GetCategory(categoryIndex);
            List <Thread> categorySpecificThreads = new List <Thread>();

            // iterate through activeThreads list
            // add a reference to the thread in categorySEpcificThread list
            foreach (Thread t in activeThreads)
            {
                if (t.Category == CATEGORY)
                {
                    categorySpecificThreads.Add(t);
                }
            }
            return(categorySpecificThreads);
        }
Example #2
0
        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);

                // ---------------------------------------->
            }
        }