private void CreateRelation(string primaryClassName, string relatedClassName) { MetaClass relatedMetaClass = DataContext.Current.GetMetaClass(relatedClassName); MetaClass primaryMetaClass = DataContext.Current.GetMetaClass(primaryClassName); if (relatedMetaClass.Fields[MetaClassManager.GetPrimaryKeyName(primaryClassName)] != null) { return; } using (MetaClassManagerEditScope managerEditScope = DataContext.Current.MetaModel.BeginEdit()) { var metaField = relatedMetaClass.CreateReference(primaryMetaClass, primaryClassName, primaryClassName, true); metaField.AccessLevel = AccessLevel.Customization; metaField.Attributes.Add(Constants.Attributes.DisplayBlock, Constants.SectionName); metaField.Attributes.Add(Constants.Attributes.DisplayText, relatedClassName); metaField.Attributes.Add(Constants.Attributes.DisplayOrder, Constants.DefaultDisplayOrder); XmlBuilder.ClearCache(); managerEditScope.SaveChanges(); } }
protected override void ExecuteInternal(IProgressMessenger progressMessenger) { using (var scope = DataContext.Current.MetaModel.BeginEdit(MetaClassManagerEditScope.SystemOwner, Mediachase.BusinessFoundation.Data.Meta.Management.AccessLevel.System)) { var manager = DataContext.Current.MetaModel; var changeTrackingManifest = ChangeTrackingManager.CreateModuleManifest(); var recentReferenceManifest = RecentReferenceManager.CreateModuleManifest(); var contactMetaClass = manager.MetaClasses[ContactEntity.ClassName]; var demoUserMenu = MetaEnum.Create("DemoUserMenu", "Show in Demo User Menu", false); MetaEnum.AddItem(demoUserMenu, 1, "Never", 1); MetaEnum.AddItem(demoUserMenu, 2, "Always", 2); MetaEnum.AddItem(demoUserMenu, 3, "Commerce Only", 3); using (var builder = new MetaFieldBuilder(contactMetaClass)) { builder.CreateEnumField("ShowInDemoUserMenu", "{Customer:DemoUserMenu}", "DemoUserMenu", true, "1", false); builder.CreateText("DemoUserTitle", "{Customer:DemoUserTitle}", true, 100, false); builder.CreateText("DemoUserDescription", "{Customer:DemoUserDescription}", true, 500, false); builder.SaveChanges(); } AddMetaFieldToForms(contactMetaClass, contactMetaClass.Fields["ShowInDemoUserMenu"]); AddMetaFieldToForms(contactMetaClass, contactMetaClass.Fields["DemoUserTitle"]); AddMetaFieldToForms(contactMetaClass, contactMetaClass.Fields["DemoUserDescription"]); var giftCardClass = manager.CreateMetaClass("GiftCard", "{Customer:GiftCard}", "{Customer:GiftCard}", "cls_GiftCard", PrimaryKeyIdValueType.Guid); ModuleManager.Activate(giftCardClass, changeTrackingManifest); using (var builder = new MetaFieldBuilder(giftCardClass)) { builder.CreateText("GiftCardName", "{Customer:GiftCardName}", false, 100, false); builder.CreateCurrency("InitialAmount", "{Customer:InitialAmount}", true, 0, true); builder.CreateCurrency("RemainBalance", "{Customer:RemainBalance}", true, 0, true); builder.CreateText("RedemptionCode", "{Customer:RedemptionCode}", true, 100, false); builder.CreateCheckBoxBoolean("IsActive", "{Customer:IsActive}", true, true, "{Customer:IsActive}"); giftCardClass.Fields[MetaClassManager.GetPrimaryKeyName(giftCardClass.Name)].FriendlyName = "{GlobalMetaInfo:PrimaryKeyId}"; var contactReference = builder.CreateReference("Contact", "{Customer:CreditCard_mf_Contact}", true, "Contact", false); contactReference.Attributes.Add(McDataTypeAttribute.ReferenceDisplayBlock, "InfoBlock"); contactReference.Attributes.Add(McDataTypeAttribute.ReferenceDisplayText, "{Customer:GiftCard}"); contactReference.Attributes.Add(McDataTypeAttribute.ReferenceDisplayOrder, "10000"); builder.SaveChanges(); } giftCardClass.AddPermissions(); AddMetaFieldToForms(giftCardClass, giftCardClass.Fields["GiftCardName"]); AddMetaFieldToForms(giftCardClass, giftCardClass.Fields["InitialAmount"]); AddMetaFieldToForms(giftCardClass, giftCardClass.Fields["RemainBalance"]); AddMetaFieldToForms(giftCardClass, giftCardClass.Fields["RedemptionCode"]); AddMetaFieldToForms(giftCardClass, giftCardClass.Fields["IsActive"]); AddMetaFieldToForms(giftCardClass, giftCardClass.Fields["ContactId"]); scope.SaveChanges(); } var contactProfile = @"<ListViewProfile xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <Id>{54a649a9-302f-48bd-b657-11ca3604fda9}</Id> <Name>{Customer:AllContacts}</Name> <IsSystem>true</IsSystem> <IsPublic>true</IsPublic> <FieldSetName>Contacts</FieldSetName> <FieldSet> <string>FullName</string> <string>Email</string> <string>LastOrder</string> <string>NumberOfOrders</string> <string>NumberOfReviews</string> <string>Points</string> <string>ShowInDemoUserMenu</string> <string>DemoUserTitle</string> </FieldSet> <GroupByFieldName /> <Filters /> <Sorting /> <ColumnsUI> <Column field=""FullName"" width=""150"" /> <Column field=""Email"" width=""150"" /> <Column field=""LastOrder"" width=""150"" /> <Column field=""NumberOfOrders"" width=""150"" /> <Column field=""NumberOfReviews"" width=""150"" /> <Column field=""Points"" width=""150"" /> <Column field=""ShowInDemoUserMenu"" width=""150"" /> <Column field=""DemoUserTitle"" width=""150"" /> </ColumnsUI> </ListViewProfile>"; var contactviewProfile = (ListViewProfile)_listViewProfileXmlSerializer.Deserialize(new StringReader(contactProfile)); ListViewProfile.SaveSystemProfile("Contact", "EntityList", Guid.NewGuid(), contactviewProfile); using (var stream = new FileStream(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"App_Data\Customers.xml"), FileMode.Open)) { ProcessCustomers(stream); ProcessOrganizations(stream); } }