public override void UpdateDatabaseAfterUpdateSchema() { base.UpdateDatabaseAfterUpdateSchema(); var watch = new System.Diagnostics.Stopwatch(); watch.Start(); //Create departments. Department devDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'R&D'")); if (devDepartment == null) { devDepartment = ObjectSpace.CreateObject <Department>(); devDepartment.Title = "R&D"; devDepartment.Office = "1"; devDepartment.Save(); } Department supDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'Technical Support'")); if (supDepartment == null) { supDepartment = ObjectSpace.CreateObject <Department>(); supDepartment.Title = "Technical Support"; supDepartment.Office = "2"; supDepartment.Save(); } Department mngDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'Management'")); if (mngDepartment == null) { mngDepartment = ObjectSpace.CreateObject <Department>(); mngDepartment.Title = "Management"; mngDepartment.Office = "3"; mngDepartment.Save(); } //Create employees. //Admin is a god that can do everything. Employee administrator = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Admin'")); if (administrator == null) { administrator = ObjectSpace.CreateObject <Employee>(); administrator.UserName = "******"; administrator.FirstName = "Admin"; administrator.LastName = "Admin"; administrator.Department = mngDepartment; administrator.IsActive = true; administrator.SetPassword(string.Empty); administrator.Roles.Add(GetAdministratorRole()); administrator.Save(); } //Sam is a manager and he can do everything with his own department Employee managerSam = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Sam'")); if (managerSam == null) { managerSam = ObjectSpace.CreateObject <Employee>(); managerSam.UserName = "******"; managerSam.FirstName = "Sam"; managerSam.LastName = "Jackson"; managerSam.IsActive = true; managerSam.SetPassword(string.Empty); managerSam.Department = devDepartment; managerSam.Roles.Add(GetManagerRole()); managerSam.Save(); } //John is an ordinary user within the Sam's department. Employee userJohn = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'John'")); if (userJohn == null) { userJohn = ObjectSpace.CreateObject <Employee>(); userJohn.UserName = "******"; userJohn.FirstName = "John"; userJohn.LastName = "Doe"; userJohn.IsActive = true; userJohn.SetPassword(string.Empty); userJohn.Department = devDepartment; userJohn.Roles.Add(GetUserRole()); userJohn.Save(); } //Mary is a manager of another department. Employee managerMary = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Mary'")); if (managerMary == null) { managerMary = ObjectSpace.CreateObject <Employee>(); managerMary.UserName = "******"; managerMary.FirstName = "Mary"; managerMary.LastName = "Tellinson"; managerMary.IsActive = true; managerMary.SetPassword(string.Empty); managerMary.Department = supDepartment; managerMary.Roles.Add(GetManagerRole()); managerMary.Save(); } //Brian is a manager of another department. Employee subAdminBrian = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Brian'")); if (subAdminBrian == null) { subAdminBrian = ObjectSpace.CreateObject <Employee>(); subAdminBrian.UserName = "******"; subAdminBrian.FirstName = "Brian"; subAdminBrian.LastName = "Tellinson"; subAdminBrian.IsActive = true; subAdminBrian.SetPassword(string.Empty); subAdminBrian.Department = supDepartment; subAdminBrian.Roles.Add(GetDepartmentAdminRole()); subAdminBrian.Save(); } //Joe is an ordinary user within the Mary's department. Employee userJoe = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Joe'")); if (userJoe == null) { userJoe = ObjectSpace.CreateObject <Employee>(); userJoe.UserName = "******"; userJoe.FirstName = "Joe"; userJoe.LastName = "Pitt"; userJoe.IsActive = true; userJoe.SetPassword(string.Empty); userJoe.Department = supDepartment; userJoe.Roles.Add(GetUserRole()); userJoe.Save(); } //Silvia is an accountant user within the Mary's department. can Edit Invoices. Employee userSilvia = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Silvia'")); if (userSilvia == null) { userSilvia = ObjectSpace.CreateObject <Employee>(); userSilvia.UserName = "******"; userSilvia.FirstName = "Silvia"; userSilvia.LastName = "Lolobrigida"; userSilvia.IsActive = true; userSilvia.SetPassword(string.Empty); userSilvia.Department = supDepartment; userSilvia.Roles.Add(GetAccountantRole()); userSilvia.Save(); } Employee userJason = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Joe'")); if (userJoe == null) { userJoe = ObjectSpace.CreateObject <Employee>(); userJoe.UserName = "******"; userJoe.FirstName = "Joe"; userJoe.LastName = "Connor"; userJoe.IsActive = true; userJoe.SetPassword(string.Empty); userJoe.Department = supDepartment; userJoe.Roles.Add(GetUserRole()); userJoe.Save(); } //Create tasks for employees. if (ObjectSpace.FindObject <EmployeeTask>(CriteriaOperator.Parse("Subject == 'Do homework'")) == null) { EmployeeTask task = ObjectSpace.CreateObject <EmployeeTask>(); task.Subject = "Do homework"; task.AssignedTo = managerSam; task.DueDate = DateTime.Now; task.Status = TaskStatus.NotStarted; task.Description = "This is a task for Sam"; task.Save(); } for (int i = 0; i < 99; i++) { if (ObjectSpace.FindObject <EmployeeTask>(CriteriaOperator.Parse($"Subject == 'Prepare {i} coffee for everyone'")) == null) { EmployeeTask task = ObjectSpace.CreateObject <EmployeeTask>(); task.Subject = $"Prepare {i} coffee for everyone"; task.AssignedTo = userJohn; task.DueDate = DateTime.Now; task.Status = TaskStatus.InProgress; task.Description = "This is a task for John"; task.Save(); } if (ObjectSpace.FindObject <EmployeeTask>(CriteriaOperator.Parse($"Subject == 'Read {i} latest news'")) == null) { EmployeeTask task = ObjectSpace.CreateObject <EmployeeTask>(); task.Subject = $"Read {i} latest news"; task.AssignedTo = managerMary; task.DueDate = DateTime.Now; task.Status = TaskStatus.Completed; task.Description = "This is a task for Mary"; task.Save(); } if (ObjectSpace.FindObject <EmployeeTask>(CriteriaOperator.Parse($"Subject == 'Book {i} tickets'")) == null) { EmployeeTask task = ObjectSpace.CreateObject <EmployeeTask>(); task.Subject = $"Book {i} tickets"; task.AssignedTo = userJoe; task.DueDate = DateTime.Now; task.Status = TaskStatus.Deferred; task.Description = "This is a task for Joe"; task.Save(); } } ObjectSpace.CommitChanges(); //DataGeneratorHelper.GenerateCountries(ObjectSpace); //DataGeneratorHelper.GenerateCustomers(ObjectSpace, 100); //ObjectSpace.CommitChanges(); //DataGeneratorHelper.GenerateInvoices(ObjectSpace, 1000); //ObjectSpace.CommitChanges(); watch.Stop(); Console.WriteLine($"db2 Execution Time: {watch.ElapsedMilliseconds} ms"); //string name = "MyName"; //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name)); //if(theObject == null) { // theObject = ObjectSpace.CreateObject<DomainObject1>(); // theObject.Name = name; //} //ObjectSpace.CommitChanges(); //Uncomment this line to persist created object(s). }
public override void UpdateDatabaseAfterUpdateSchema() { base.UpdateDatabaseAfterUpdateSchema(); //Create departments. Department devDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'R&D'")); if (devDepartment == null) { devDepartment = ObjectSpace.CreateObject <Department>(); devDepartment.Title = "R&D"; devDepartment.Office = "1"; devDepartment.Save(); } Department supDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'Technical Support'")); if (supDepartment == null) { supDepartment = ObjectSpace.CreateObject <Department>(); supDepartment.Title = "Technical Support"; supDepartment.Office = "2"; supDepartment.Save(); } Department mngDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'Management'")); if (mngDepartment == null) { mngDepartment = ObjectSpace.CreateObject <Department>(); mngDepartment.Title = "Management"; mngDepartment.Office = "3"; mngDepartment.Save(); } //Create employees. //Admin is a god that can do everything. Employee administrator = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Admin'")); if (administrator == null) { administrator = ObjectSpace.CreateObject <Employee>(); administrator.UserName = "******"; administrator.FirstName = "Admin"; administrator.LastName = "Admin"; administrator.Department = mngDepartment; administrator.IsActive = true; administrator.SetPassword(""); administrator.Roles.Add(GetAdministratorRole()); administrator.Save(); } //Sam is a manager and he can do everything with his own department Employee managerSam = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Sam'")); if (managerSam == null) { managerSam = ObjectSpace.CreateObject <Employee>(); managerSam.UserName = "******"; managerSam.FirstName = "Sam"; managerSam.LastName = "Jackson"; managerSam.IsActive = true; managerSam.SetPassword(""); managerSam.Department = devDepartment; managerSam.Roles.Add(GetManagerRole()); managerSam.Save(); } //John is an ordinary user within the Sam's department. Employee userJohn = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'John'")); if (userJohn == null) { userJohn = ObjectSpace.CreateObject <Employee>(); userJohn.UserName = "******"; userJohn.FirstName = "John"; userJohn.LastName = "Doe"; userJohn.IsActive = true; userJohn.SetPassword(""); userJohn.Department = devDepartment; userJohn.Roles.Add(GetUserRole()); userJohn.Save(); } //Mary is a manager of another department. Employee managerMary = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Mary'")); if (managerMary == null) { managerMary = ObjectSpace.CreateObject <Employee>(); managerMary.UserName = "******"; managerMary.FirstName = "Mary"; managerMary.LastName = "Tellinson"; managerMary.IsActive = true; managerMary.SetPassword(""); managerMary.Department = supDepartment; managerMary.Roles.Add(GetManagerRole()); managerMary.Save(); } //Joe is an ordinary user within the Mary's department. Employee userJoe = ObjectSpace.FindObject <Employee>(CriteriaOperator.Parse("UserName == 'Joe'")); if (userJoe == null) { userJoe = ObjectSpace.CreateObject <Employee>(); userJoe.UserName = "******"; userJoe.FirstName = "Joe"; userJoe.LastName = "Pitt"; userJoe.IsActive = true; userJoe.SetPassword(""); userJoe.Department = supDepartment; userJoe.Roles.Add(GetUserRole()); userJoe.Save(); } //Create tasks for employees. if (ObjectSpace.FindObject <EmployeeTask>(CriteriaOperator.Parse("Subject == 'Do homework'")) == null) { EmployeeTask task = ObjectSpace.CreateObject <EmployeeTask>(); task.Subject = "Do homework"; task.AssignedTo = managerSam; task.DueDate = DateTime.Now; task.Status = TaskStatus.NotStarted; task.Description = "This is a task for Sam"; task.Save(); } if (ObjectSpace.FindObject <EmployeeTask>(CriteriaOperator.Parse("Subject == 'Prepare coffee for everyone'")) == null) { EmployeeTask task = ObjectSpace.CreateObject <EmployeeTask>(); task.Subject = "Prepare coffee for everyone"; task.AssignedTo = userJohn; task.DueDate = DateTime.Now; task.Status = TaskStatus.InProgress; task.Description = "This is a task for John"; task.Save(); } if (ObjectSpace.FindObject <EmployeeTask>(CriteriaOperator.Parse("Subject == 'Read latest news'")) == null) { EmployeeTask task = ObjectSpace.CreateObject <EmployeeTask>(); task.Subject = "Read latest news"; task.AssignedTo = managerMary; task.DueDate = DateTime.Now; task.Status = TaskStatus.Completed; task.Description = "This is a task for Mary"; task.Save(); } if (ObjectSpace.FindObject <EmployeeTask>(CriteriaOperator.Parse("Subject == 'Book tickets'")) == null) { EmployeeTask task = ObjectSpace.CreateObject <EmployeeTask>(); task.Subject = "Book tickets"; task.AssignedTo = userJoe; task.DueDate = DateTime.Now; task.Status = TaskStatus.Deferred; task.Description = "This is a task for Joe"; task.Save(); } ObjectSpace.CommitChanges(); }