public override void Generate()
        {
            var departmentIds = this.Database.Departments.Select(a => a.Id).ToList();

            Console.WriteLine("Adding Employees:");
            for (int i = 0; i < this.Count; i++)
            {
                var newEmployee = new Employee
                {
                    FirstName = this.Random.GetRandomStringWithRandomLength(5, 20),
                    LastName = this.Random.GetRandomStringWithRandomLength(5, 20),
                    Salary = this.Random.GetRandomNumber(50000, 200000),
                    DepartmentId = departmentIds[this.Random.GetRandomNumber(0, departmentIds.Count - 1)]
                };

                if (i >= 1)
                {
                    bool hasManager = this.Random.GetRandomNumber(0, 100) <= 95;
                    if (hasManager)
                    {
                        newEmployee.ManagerId = i;
                    }
                }

                if (i % 100 == 0)
                {
                    Console.Write(".");
                    this.Database.SaveChanges();
                }

                this.Database.Employees.Add(newEmployee);
            }
            Console.WriteLine();
            Console.WriteLine("Employees added!");
        }
        public void GenerateData(CompanyEntities data, IRandomGenerator random, int count)
        {
            var allAddedEmployees = new List<Employee>();
            var departmentIds = data.Departments.Select(d => d.Id).ToList();

            for (int i = 0; i < count; i++)
            {
                var employee = new Employee
                                   {
                                       FirstName = random.GetRandomString(random.GetRandomNumber(5, 20)),
                                       LastName = random.GetRandomString(random.GetRandomNumber(5, 20)),
                                       Salary = random.GetRandomNumber(50000, 200000),
                                       DepartmentId =
                                           departmentIds[random.GetRandomNumber(0, departmentIds.Count - 1)]
                                   };

                if (allAddedEmployees.Count > 0 && random.GetRandomNumber(1, 100) <= 95)
                {
                    employee.Employee1 = allAddedEmployees[random.GetRandomNumber(0, allAddedEmployees.Count - 1)];
                }

                allAddedEmployees.Add(employee);
            }

            data.Employees.AddRange(allAddedEmployees);
        }
        public override void Generate()
        {
            var departmentIDs = this.Database.Departments.Select(c => c.ID).ToList();

            this.Logger.LogMessage("Adding employees");
            for (int i = 0; i < this.Count; i++)
            {
                var employee = new Employee
                {
                    FirstName = this.Random.GetRandomStringWithRandomLength(5, 20),
                    LastName = this.Random.GetRandomStringWithRandomLength(5, 20),
                    DepartmentID = departmentIDs[this.Random.GetRandomNumber(0, departmentIDs.Count - 1)],
                    Salary = this.Random.GetRandomNumber(50000, 200000),
                };

                if (i % 100 == 0)
                {
                    this.Logger.Dot();
                    this.Database.SaveChanges();
                }

                this.Database.Employees.Add(employee);
            }

            this.Logger.LogMessage(" Employees added!\n");
        }
 private Employee GenerateEmployee(Employee manager)
 {
     return new Employee
                        {
                            FirstName = Random.GetString(5, 20),
                            LastName = Random.GetString(5,20),
                            DepartmentId = this.departments[this.Random.GetInt(0, this.departments.Count - 1)],
                            YearSalary = this.Random.GetInt(MinSalary, MaxSalary),
                            Employee1 = manager
                        };
 }
        public override void Generate()
        {
            Console.WriteLine("Generating Employees");

            var departmentsIds = this.Db.Departments.Select(d => d.ID).ToList();

            for (int i = 0; i < this.Count; i++)
            {
                var currentEmployeesIds = this.Db.Employees.Select(d => d.ID).ToList();
                var newEmployee = new Employee
                {
                    FirstName = this.Random.GetString(5, 20),
                    LastName = this.Random.GetString(5, 20),
                    YearSalary = this.Random.GetInt(50000, 200000),
                    DepartmentID = departmentsIds[this.Random.GetInt(0, departmentsIds.Count - 1)],
                };

                if (currentEmployeesIds.Count > 0)
                {
                    int? selectedManagerID = this.Random.GetChance(95) ? currentEmployeesIds[this.Random.GetInt(0, currentEmployeesIds.Count - 1)] : default(int?);
                    if (selectedManagerID == null)
                    {
                        newEmployee.ManagerID = selectedManagerID;
                    }
                    else
                    {
                        var forbiddenIDs = CheckManagers((int)selectedManagerID);
                        while (forbiddenIDs.Contains((int)selectedManagerID))
                        {
                            selectedManagerID = this.Random.GetChance(95) ? currentEmployeesIds[this.Random.GetInt(0, currentEmployeesIds.Count - 1)] : default(int?);
                            forbiddenIDs = CheckManagers((int)selectedManagerID);
                        }
                        newEmployee.ManagerID = selectedManagerID;
                    }
                }

                this.Db.Employees.Add(newEmployee);
                Db.SaveChanges();
                if (i % 100 == 0)
                {
                    Console.Write(".");
                }
            }

            Console.WriteLine("\nGenerating Employees Done!");
        }
        public void GenerateData(CompanyEntities data, IRandomGenerator random, int count)
        {
            var allEmployees = new List<Employee>();

            for (var i = 0; i < count; i++)
            {
                var employee = new Employee
                {
                    DepartmentId = random.GetRandomNumber(1, data.Departments.Count()),
                    Firstname = random.GetRandomString(random.GetRandomNumber(5, 20)),
                    Lastname = random.GetRandomString(random.GetRandomNumber(5, 20)),
                    Salary = random.GetRandomNumber(50000, 200000)
                };

                if (allEmployees.Any() && random.GetRandomNumber(1, 100) <= 95)
                {
                    employee.Employee1 = allEmployees[random.GetRandomNumber(0, data.Employees.Count() - 1)];
                }

                allEmployees.Add(employee);
            }

            data.Employees.AddRange(allEmployees);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            var random = RandomDataGenerator.Instance;
            var db = new CompanyEntities();
            db.Configuration.AutoDetectChangesEnabled = false;

            Console.WriteLine("\nAdding departments");

            for (int i = 0; i < 100; i++)
            {
                var department = new Department
                {
                    Name = random.GetRandomStringWithRandomLength(10,50)
                };

                db.Departments.Add(department);

                if (i%100 == 0)
                {
                    Console.Write(".");
                    db.SaveChanges();
                }
            }
            db.SaveChanges();
            Console.WriteLine("\nDepartents added");

            Console.WriteLine("\nAdding employees");

            var departmentIds = db.Departments.Select(d => d.Id).ToList();
            for (int i = 0; i < 5000; i++)
            {
              var employee = new Employee
                {
                    FirstName = random.GetRandomStringWithRandomLength(5,20),
                    LastName = random.GetRandomStringWithRandomLength(5,20),
                    DepartmentId = departmentIds[random.GetRandomNumber(0, departmentIds.Count - 1)],
                    YearSalary = random.GetRandomNumber(50000,200000),
                    ManagerId = (i > 250) ? i - 1 :(int?)null // 4750 employees will have a manager (95%) :)
                                                                  // it is very stupid i know but I left it for last and forgot it
                };

              db.Employees.Add(employee);

              if (i % 100 == 0)
              {
                  Console.Write(".");
                  db.SaveChanges();
              }
            }
            db.SaveChanges();
            Console.WriteLine("\nEmployees added");

            Console.WriteLine("\nAdding Projects"); //For some reason it does not want to work
            var employeeIds = db.Employees.Select(e => e.Id).ToList();
            for (int i = 0; i < 1000; i++)
            {
                var project = new Project
                {
                    Name = "Project" + i.ToString(),
                };

                var count = random.GetRandomNumber(5, 20);

                for (int j = 0; j < count; j++)
                {
                    var projectEmployee = new ProjectsEmployee
                    {
                        EmployeeId = employeeIds[i+j],
                        ProjectId = i+1,
                        StartDate = new DateTime(random.GetRandomNumber(1980, 2005), random.GetRandomNumber(1, 12), random.GetRandomNumber(1, 28)),
                        EndDate = new DateTime(random.GetRandomNumber(2005, 2020), random.GetRandomNumber(1, 12), random.GetRandomNumber(1, 28))

                    };

                    project.ProjectsEmployees.Add(projectEmployee);
                }

                db.Projects.Add(project);

                if (i % 100 == 0)
                {
                    Console.Write(".");
                    db.SaveChanges();
                }
            }
            db.SaveChanges();
            Console.WriteLine("\nProjects added");

            Console.WriteLine("\nAdding Reports");
            var employeeIds2 = db.Employees.Select(d => d.Id).ToList();
            for (int i = 0; i < 5000; i++)
            {
                var empId = employeeIds2[i];

                for (int j = 0; j < 50; j++) // every empolyee gets 50 reports
                {
                    var report = new Report
                    {
                        EmployeeId = empId,
                        TimeOfReport = new DateTime(random.GetRandomNumber(1980, 2014), random.GetRandomNumber(1, 12), random.GetRandomNumber(1, 28))
                    };
                    db.Reports.Add(report);
                }
                Console.Write(".");
                db.SaveChanges();

            }
            db.SaveChanges();
            Console.WriteLine("\nReports added");

            db.Configuration.AutoDetectChangesEnabled = true;
        }