public static int CreateTestObjects() { #region REGIONS CCountry Country = new CCountry(DatabaseContext) { FullDescription = "Россия", ShortDescription = "Россия", Name = "Россия", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = CEmbeddedObjectsConsts.CONST_FOLDER_REGIONS_KEY, Status = EnMetaobjectStatus.EEnabled, System = false }; var R = Country.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CState State = new CState(DatabaseContext) { FullDescription = "Пермский край", ShortDescription = "Пермский край", Name = "Пермский край", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = Country.Key, Status = EnMetaobjectStatus.EEnabled, System = false }; R = State.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CCity City = new CCity(DatabaseContext) { FullDescription = "Пермь", ShortDescription = "Пермь", Name = "Пермь", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = State.Key, Status = EnMetaobjectStatus.EEnabled, System = false, Coordinates = "" }; R = City.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; #endregion #region ORGANIZATIONS COrganizationNetwork OrganizationNetwork = new COrganizationNetwork(DatabaseContext) { FullDescription = "Сеть организаций", ShortDescription = "Сеть организаций", Name = "Сеть организаций", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = CEmbeddedObjectsConsts.CONST_FOLDER_MENUS_KEY, Status = EnMetaobjectStatus.EEnabled, System = false, Email = "Email", Url = "" }; R = OrganizationNetwork.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; COrganization Organization = new COrganization(DatabaseContext) { FullDescription = "Организация", ShortDescription = "Организация", Name = "Организация", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = CEmbeddedObjectsConsts.CONST_FOLDER_MENUS_KEY, Status = EnMetaobjectStatus.EEnabled, System = false }; R = Organization.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; cMenu.Metaobjects.Linq.CMetaobjectLink Link = new Metaobjects.Linq.CMetaobjectLink() { LinkedObjectKey = Organization.Key, LinkType = EnMetaobjectLinkType.ESimple, LinkValue = 1, SourceObjectKey = City.Key }; R = Link.LinkInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; #endregion #region SERVICES CMenuService Service1 = new CMenuService(DatabaseContext) { FullDescription = "Товар 1", ShortDescription = "Товар 1", Name = "Товар 1", Composition = "Состав", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = CEmbeddedObjectsConsts.CONST_FOLDER_SERVICES_KEY, Status = EnMetaobjectStatus.EEnabled, System = false }; R = Service1.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CMenuService Service2 = new CMenuService(DatabaseContext) { FullDescription = "Товар 2", ShortDescription = "Товар 2", Name = "Товар 2", Composition = "Состав", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = CEmbeddedObjectsConsts.CONST_FOLDER_SERVICES_KEY, Status = EnMetaobjectStatus.EEnabled, System = false }; R = Service2.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CMenuServiceAmount Amount1 = new CMenuServiceAmount(DatabaseContext) { FullDescription = "Порция 1.1", ShortDescription = "ТПорция 1.1", Name = "Порция 1.1", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = Service1.Key, Status = EnMetaobjectStatus.EEnabled, System = false, Price = 100, Amount = 200, Units = "мг", TimeAmount = new TimeSpan(0, 10, 0) }; R = Amount1.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CMenuServiceAmount Amount2 = new CMenuServiceAmount(DatabaseContext) { FullDescription = "Порция 2.1", ShortDescription = "ТПорция 2.1", Name = "Порция 2.1", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = Service2.Key, Status = EnMetaobjectStatus.EEnabled, System = false, Price = 200, Amount = 300, Units = "г", TimeAmount = new TimeSpan(0, 20, 0) }; R = Amount2.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; #endregion #region MENU CMenu Menu = new CMenu(DatabaseContext) { FullDescription = "Меню", ShortDescription = "Меню", Name = "Меню", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = Organization.Key, Status = EnMetaobjectStatus.EEnabled, System = false, Primary = true }; R = Menu.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CCategory Category = new CCategory() { FullDescription = "Категория", ShortDescription = "Категория", Name = "Категория", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = Menu.Key, Status = EnMetaobjectStatus.EEnabled, System = false }; R = Category.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CMetaobjectShortcut Shortcut = new CMetaobjectShortcut(DatabaseContext) { FullDescription = "Ссылка на порцию 1.1", ShortDescription = "Ссылка на порцию 1.1", Name = "Ссылка на порцию 1.1", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = Category.Key, Status = EnMetaobjectStatus.EEnabled, System = false, SourceObjectKey = Amount1.Key }; R = Shortcut.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CMetaobjectShortcut Shortcut2 = new CMetaobjectShortcut(DatabaseContext) { FullDescription = "Ссылка на порцию 1.2", ShortDescription = "Ссылка на порцию 1.2", Name = "Ссылка на порцию 1.2", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = Category.Key, Status = EnMetaobjectStatus.EEnabled, System = false, SourceObjectKey = Amount2.Key }; R = Shortcut2.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; #endregion #region TABLES COrganizationTable Table = new COrganizationTable(DatabaseContext) { FullDescription = "Стол", ShortDescription = "Стол", Name = "Стол", ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(Provider), ModificatonDate = DateTime.Now, Parent = CEmbeddedObjectsConsts.CONST_FOLDER_SERVICES_KEY, Status = EnMetaobjectStatus.EEnabled, System = false }; R = Table.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; Link = new Metaobjects.Linq.CMetaobjectLink() { LinkedObjectKey = Table.Key, LinkType = EnMetaobjectLinkType.ESimple, LinkValue = 1, SourceObjectKey = Organization.Key }; R = Link.LinkInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; #endregion try { DatabaseContext.SubmitChanges(); } catch (Exception Exception) { throw new Exception(Exception.Message); return CErrors.ERR_DB_INSERT_OBJECT; } return CErrors.ERR_SUC; }
public static int CreateGroupsUsers() { CSystemUserGroup AdminGroup = new CSystemUserGroup(DatabaseContext) { FullDescription = "Группа администраторов", ShortDescription = "Группа администраторов", Name = "Администраторы", ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_GROUP_ADMINISTRATORS_ID), Key = CEmbeddedSecurityConsts.CONST_USER_GROUP_ADMINISTRATORS_KEY, ModificatonDate = DateTime.Now, Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY, Status = EnMetaobjectStatus.EEnabled, System = true }; var R = AdminGroup.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CSystemUserGroup ModeratorsGroup = new CSystemUserGroup(DatabaseContext) { FullDescription = "Группа модераторов", ShortDescription = "Группа модераторов", Name = "Модераторы", ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_ID), Key = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY, ModificatonDate = DateTime.Now, Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY, Status = EnMetaobjectStatus.EEnabled, System = true }; R = AdminGroup.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CSystemUserGroup UsersGroup = new CSystemUserGroup(DatabaseContext) { FullDescription = "Группа пользователей", ShortDescription = "Группа пользователей", Name = "Пользователи", ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_GROUP_USERS_ID), Key = CEmbeddedSecurityConsts.CONST_USER_GROUP_USERS_KEY, ModificatonDate = DateTime.Now, Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY, Status = EnMetaobjectStatus.EEnabled, System = true }; R = AdminGroup.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; CSystemUser AdminUser = new CSystemUser(DatabaseContext) { ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_ADMINISTRATOR_ID), Key = CEmbeddedSecurityConsts.CONST_USER_ADMINISTRATOR_KEY, ShortDescription = "Главный администратор системы", Email = "*****@*****.**", EnterpriseType = -1, FirstName = "Administrator", SecondName = "", Surname = "", Login = "******", Name = "Администратор", MobilePhone = "89028087122", HomePhone = "", WorkPhone = "", Passhash = CSecurityHelper.sGeneratePasshash("Administrator", "q"), ModificatonDate = DateTime.Now, Parent = CEmbeddedSecurityConsts.CONST_USER_GROUP_ADMINISTRATORS_KEY, Status = EnMetaobjectStatus.EEnabled, System = true }; R = AdminUser.ObjectInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; cMenu.Metaobjects.Linq.CMetaobjectLink Link = new Metaobjects.Linq.CMetaobjectLink() { LinkedObjectKey = AdminUser.Key, LinkType = EnMetaobjectLinkType.ESecurity, LinkValue = 1, SourceObjectKey = AdminGroup.Key }; R = Link.LinkInsert(DatabaseContext); if (R != CErrors.ERR_SUC) return R; try { DatabaseContext.SubmitChanges(); } catch (Exception Exception) { throw new Exception(Exception.Message); return CErrors.ERR_DB_INSERT_OBJECT; } return CErrors.ERR_SUC; }