Exemplo n.º 1
0
        internal static void RandomPrivateBoardMessages(this LendADogDemoDb context, int numberOfFriends, int messagesPerFriend)
        {
            List <DogOwner> dogOwners = context.DogOwners.ToList();

            using (TransactionScope scope = new TransactionScope())
            {
                using (context = new LendADogDemoDb())
                {
                    int a = 0;
                    foreach (DogOwner sender in dogOwners)
                    {
                        a++;
                        var randomFriends = context.DogOwners
                                            .SqlQuery("SELECT TOP(@numberOfRecords) * FROM AspNetUsers WHERE NOT Id = @Id ORDER BY NEWID();"
                                                      , new SqlParameter("Id", sender.Id)
                                                      , new SqlParameter("numberOfRecords", numberOfFriends)).ToList();

                        foreach (DogOwner receiver in randomFriends)
                        {
                            for (int i = 0; i < messagesPerFriend; i++)
                            {
                                PrivateMessageBoard sendMsg = new PrivateMessageBoard()
                                {
                                    SendFromID     = sender.Id,
                                    RrecivedFromID = receiver.Id,
                                    CreateDate     = GetRandomDate(),
                                    Message        = "Hi " + receiver.FirstName
                                };
                                context.PrivateMessages.Add(sendMsg);

                                PrivateMessageBoard RecMmsg = new PrivateMessageBoard()
                                {
                                    SendFromID     = receiver.Id,
                                    RrecivedFromID = sender.Id,
                                    CreateDate     = GetRandomDate(),
                                    Message        = "Hi " + sender.FirstName
                                };
                                context.PrivateMessages.Add(RecMmsg);
                            }
                        }
                        if (a % 10 == 0)
                        {
                            context.SaveChanges();
                            context.Dispose();
                            context = new LendADogDemoDb();
                        }
                    }
                    context.SaveChanges();
                }
                scope.Complete();
            }
        }
Exemplo n.º 2
0
        internal static void RandomMainBoardMessages(this LendADogDemoDb context, int messagesPerNumberOfDogs)
        {
            #region Helpers

            List <DogOwner> allOwners = context.DogOwners.Include(d => d.Dogs).ToList();

            string[] numbersToLetters = { "two", "tre", "four", "five", "six", "seven", "eight", "nine" };

            #endregion

            using (TransactionScope scope = new TransactionScope())
            {
                using (context = new LendADogDemoDb())
                {
                    int a = 0;
                    foreach (DogOwner sender in allOwners)
                    {
                        if (sender.Dogs != null)
                        {
                            var randomDogs = context.Dogs
                                             .SqlQuery("SELECT TOP(@numberOfRecords) * FROM Dog ORDER BY NEWID();"
                                                       , new SqlParameter("numberOfRecords", messagesPerNumberOfDogs)).ToList();

                            foreach (Dog dog in randomDogs)
                            {
                                MainMessageBoard msg = new MainMessageBoard()
                                {
                                    DogOwnerID     = sender.Id,
                                    RequestMessage = "Need Someone to Take Care of My Dog(" + dog.DogName + ") for " + numbersToLetters[random.Next(numbersToLetters.Length)] + " days",
                                    CreateDate     = GetRandomDate(),
                                    Answered       = random.NextDouble() > 0.5,
                                    DogID          = dog.DogID,
                                };
                                context.MainMessages.Add(msg);
                            }
                        }
                        if (a % 10 == 0)
                        {
                            context.SaveChanges();
                            context.Dispose();
                            context = new LendADogDemoDb();
                        }
                    }
                    context.SaveChanges();
                }
                scope.Complete();
            }
        }
Exemplo n.º 3
0
        internal static void RandomRequestMessages(this LendADogDemoDb context, int numberOfRecords)
        {
            List <DogOwner> allOwners = context.DogOwners.ToList();

            using (TransactionScope scope = new TransactionScope())
            {
                using (context = new LendADogDemoDb())
                {
                    int a = 0;
                    foreach (DogOwner sender in allOwners)
                    {
                        a++;
                        var randomOwners = context.DogOwners
                                           .SqlQuery("SELECT TOP(@numberOfRecords) * FROM AspNetUsers WHERE NOT Id = @Id ORDER BY NEWID();"
                                                     , new SqlParameter("Id", sender.Id)
                                                     , new SqlParameter("numberOfRecords", numberOfRecords)).ToList();

                        foreach (DogOwner receiver in randomOwners)
                        {
                            RequestMessage msg = new RequestMessage()
                            {
                                SendFromID = sender.Id,
                                ReciverID  = receiver.Id,
                                Message    = "Dear " + receiver.FullName + " i like to be part of LendADog community.",
                                CreateDate = GetRandomDate()
                            };
                            context.RequestMessages.Add(msg);
                        }
                        if (a % 10 == 0)
                        {
                            context.SaveChanges();
                            context.Dispose();
                            context = new LendADogDemoDb();
                        }
                    }
                    context.SaveChanges();
                }
                scope.Complete();
            }
        }
Exemplo n.º 4
0
        internal static void RandomDogsPerDogOwner(this LendADogDemoDb context, int dogsPerOwner, int photosPerDog)
        {
            #region Helpers
            List <DogOwner> dogOwners = context.DogOwners.ToList();

            var currentDirName = @"C:\Users\karco\Desktop\DogPhotos";

            var aveablePhotos = Directory.GetFiles(currentDirName);

            byte[][] ImagesBytes = new byte[aveablePhotos.Length][];

            for (int i = 0; i < aveablePhotos.Length; i++)
            {
                using (Image img = Image.FromFile(aveablePhotos[i]))
                {
                    var imgBiteNew = img.ResizeImageConvertInBytes(360, 270);
                    ImagesBytes[i] = imgBiteNew;
                }
            }

            string[] dogNames = new string[]
            {
                "Rufus", "Ella", "Luke", "Dixie", "Kona", "Nala", "Penelope", "Jasmine", "Lola",
                "Cisco", "Maddie", "Princess", "Blue", "Payton", "Scooter", "Marley", "Buddy",
                "Gizmo", "Brutus", "Moose", "Tiger", "Teddy", "Rex", "Cocoa", "Lacey", "Coco",
                "Rocky", "Hank", "Rosie", "Chance", "Bubba", "Benji", "Ace", "Zara", "Scout",
                "Gigi", "Tucker", "Baxter", "Gunner", "Bruno"
            };

            string[] firstWord = new string[]
            {
                "active", "adorable", "adventurous", "amazing", "bright", "charming", "cheerful",
                "clever", "delightful", "energetic", "intelligent", "interesting", "loving",
                "playful", "positive", "sensitive", "friendly"
            };

            #endregion

            using (TransactionScope scope = new TransactionScope())
            {
                using (context = new LendADogDemoDb())
                {
                    int a = 0;
                    foreach (DogOwner user in dogOwners)
                    {
                        a++;
                        for (int i = 0; i < dogsPerOwner; i++)
                        {
                            Dog newDog = new Dog()
                            {
                                DogName     = dogNames[random.Next(dogNames.Length)],
                                DogSize     = (Size)random.Next(1, 4),
                                DogOwnerID  = user.Id,
                                Description = $" is {firstWord[random.Next(firstWord.Length)]} dog. Perfect guest for your home.",
                                DogPhotos   = new List <DogPhoto>()
                            };

                            for (int b = 0; b < photosPerDog; b++)
                            {
                                DogPhoto newDogPhoto = new DogPhoto()
                                {
                                    DogID = newDog.DogID,
                                    Photo = ImagesBytes[random.Next(ImagesBytes.Length)]
                                };
                                newDog.DogPhotos.Add(newDogPhoto);
                            }

                            context.Dogs.Add(newDog);
                        }
                        if (a % 10 == 0)
                        {
                            context.SaveChanges();
                            context.Dispose();
                            context = new LendADogDemoDb();
                        }
                    }
                    context.SaveChanges();
                }
                scope.Complete();
            }
        }