public static void Populate() { UnitOfWork uow = null; try { uow = XpoHelper.GetNewUnitOfWork(); //insert default data into Person table if (!Util.isExistXpoObject <Person>("Code", Utility.Constant.NAAN_DEFAULT_CODE)) { Person person = new Person(uow) { Code = Utility.Constant.NAAN_DEFAULT_CODE, Name = Utility.Constant.NAAN_DEFAULT_NAME, Description = "", RowStatus = -1, RowCreationTimeStamp = DateTime.Now }; person.Save(); } if (!Util.isExistXpoObject <Person>("PersonId", Guid.Parse("96947D1F-3FE3-4FF7-A759-DEBCC664FEBC"))) { Person person = new Person(uow) { PersonId = Guid.Parse("96947D1F-3FE3-4FF7-A759-DEBCC664FEBC"), Code = "MACDINH", Name = "Nhân viên mặc định", Description = "Nhân viên mặc định", RowStatus = 1, RowCreationTimeStamp = DateTime.Now }; DepartmentPerson departmentPerson = new DepartmentPerson(uow) { PersonId = person, DepartmentId = Util.getDefaultXpoObject <Department>(uow), RowStatus = Constant.ROWSTATUS_ACTIVE }; person.Save(); } uow.CommitChanges(); } catch (Exception) { throw; } finally { if (uow != null) { uow.Dispose(); } } }
public static void Populate() { Session session = null; try { session = XpoHelper.GetNewSession(); //insert default data into Organization table XPQuery <Person> personQuery = session.Query <Person>(); Person.Populate(); Person person = personQuery.Where(r => r.Code == Utility.Constant.NAAN_DEFAULT_CODE).FirstOrDefault(); if (!Util.isExistXpoObject <DepartmentPerson>("PersonId.PersonId", person.PersonId)) { XPQuery <Department> departmentQuery = session.Query <Department>(); Department.Populate(); Department department = departmentQuery.Where(r => r.Code == Utility.Constant.NAAN_DEFAULT_CODE).FirstOrDefault(); DepartmentPerson departmentPerson = new DepartmentPerson(session) { DepartmentId = department, PersonId = person, RowStatus = -1, RowCreationTimeStamp = DateTime.Now }; departmentPerson.Save(); } } catch (Exception) { throw; } finally { if (session != null) { session.Dispose(); } } }