Beispiel #1
0
        public static void createRandomAccounts(int idGreaterThan)
        {
            List <account> accs = new List <account>();


            using (creaturesEntities db = new creaturesEntities())
            {
                accs = db.account.Where(x => x.AccountID > idGreaterThan).ToList();

                foreach (account acc in accs)
                {
                    int x = rnd.Next(0, 3);

                    for (int i = 0; i < x; i++)
                    {
                        trainer t = new trainer()
                        {
                            AccountId   = acc.AccountID,
                            TrainerName = randomGamertag()
                        };

                        while (true)
                        {
                            if (db.trainer.Where(d => d.TrainerName == t.TrainerName).Count() > 0)
                            {
                                t.TrainerName = randomGamertag();
                            }
                            else
                            {
                                break;
                            }
                        }

                        acc.trainer.Add(t);
                    }
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(acc.trainer + e.ToString());

                        throw;
                    }
                }
            }
        }