protected override void GenerateEntity()
        {
            var project = new Project { Name = Random.GetString(5, 45)};

            var employeeCount = Random.GetInt(2, 20);
            var employeesForProject = new HashSet<int>();

            while (employeesForProject.Count < employeeCount)
            {
                employeesForProject.Add(this.employees[Random.GetInt(0, this.employees.Count - 1)]);
            }

            foreach (var employee in employeesForProject)
            {
                var startDate = Random.GeneraDateTime();
                var endDate = Random.GeneraDateTime();

                if (startDate > endDate)
                {
                    var switchDates = startDate;
                    startDate = endDate;
                    endDate = switchDates;
                }

                project.EmployeesProjects.Add(new EmployeesProject{ EmployeeId = employee, ProjectId = project.Id, EndingDate = endDate, StartingDate = startDate});
            }

            this.databaseContext.Projects.Add(project);
        }
        public override void Generate()
        {
            this.Logger.LogMessage("Adding projects");
            for (int i = 0; i < this.Count; i++)
            {
                DateTime startDate = RandomDay();
                DateTime endDate = startDate.AddDays(this.Random.GetRandomNumber(1, 200));

                var project = new Project
                {
                    Name = this.Random.GetRandomStringWithRandomLength(5, 50),
                    StartDate = startDate,
                    EndDate = endDate
                };

                this.Database.Projects.Add(project);

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

            this.Logger.LogMessage(" Projects added!\n");
        }
 public void GenerateData(CompanyEntities data, IRandomGenerator random, int count)
 {
     for (int i = 0; i < count; i++)
     {
         var project = new Project { Name = random.GetRandomString(random.GetRandomNumber(5, 50)) };
         data.Projects.Add(project);
     }
 }
Exemplo n.º 4
0
        public override void Generate()
        {
            Console.WriteLine("Generating Projects");
            var employeesIds = this.Db.Employees.Select(d => d.ID).ToList();

            for (int i = 0; i < this.Count; i++)
            {
                var newProject = new Project
                {
                    Name = this.Random.GetString(5, 50),
                };
                if (employeesIds.Count > 1)
                {
                    var uniqueEmployeesIds = new HashSet<int>();
                    var employeesInProject = this.Random.GetInt(2, Math.Min(employeesIds.Count - 1, 20));
                    while (uniqueEmployeesIds.Count != employeesInProject)
                    {
                        uniqueEmployeesIds.Add(employeesIds[this.Random.GetInt(0, employeesIds.Count - 1)]);
                    }
                    foreach (var uniqueEmployeeId in uniqueEmployeesIds)
                    {
                        var startingDate = DateTime.Now.AddDays(this.Random.GetInt(-5, 10));
                        var endingDate = startingDate.AddDays(this.Random.GetInt(1, 5));
                        var newEmployeesProject = new EmployeesProject
                        {
                            Employee = this.Db.Employees.Find(uniqueEmployeeId),
                            Project = newProject,
                            StartingDate = startingDate,
                            EndingDate = endingDate
                        };
                        newProject.EmployeesProjects.Add(newEmployeesProject);
                    }
                }
                this.Db.Projects.Add(newProject);
                if (i % 100 == 0)
                {
                    Console.Write(".");
                    Db.SaveChanges();
                }
            }

            Console.WriteLine("\nGenerating Projects Done!");
        }
Exemplo n.º 5
0
        public override void Generate()
        {
            var employeesIds = this.Database.Employees.Select(a => a.Id).ToList();

            Console.WriteLine("Adding Projects:");
            for (int i = 0; i < this.Count; i++)
            {
                var newProject = new Project
                {
                    Name = this.Random.GetRandomStringWithRandomLength(5, 50),
                    EmployeeId = employeesIds[this.Random.GetRandomNumber(0, employeesIds.Count - 1 )]
                };

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

                this.Database.Projects.Add(newProject);
            }
            Console.WriteLine();
            Console.WriteLine("Projects added!");
        }
Exemplo n.º 6
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;
        }