Example #1
0
        private object ConvertEntity(object soruceObject, string sourceOjbectName, string targetObjectName)
        {
            IObjectSpace obojectSpace = new ODataObjectSpace();
            var          targetType   = obojectSpace.ResolveType(targetObjectName);
            var          targetObject = Activator.CreateInstance(targetType);

            obojectSpace.SetEntityId(targetObjectName, targetObject, Guid.NewGuid());
            var mappingList = GetMappingList(sourceOjbectName, targetObjectName);

            foreach (var mappingItem in mappingList)
            {
                SetProperValue(soruceObject, mappingItem.SourceAttributeName, targetObject, mappingItem.TargetAttributeName);
            }
            string convertPath = "/ConvertObject/" + targetObjectName;

            if (AddInTree.ExistsTreeNode(convertPath))
            {
                var descriptor = AddInTree.BuildItems <IObjectConvert>(convertPath, null);
                if (descriptor != null && descriptor.Count() > 0)
                {
                    descriptor.First().ConvertObject(soruceObject, targetObject);
                }
            }
            SetFieldValue(targetObject, "CreatedOn", DateTime.Now);
            SetFieldValue(targetObject, "CreatedById", AuthorizationManager.CurrentUserId);
            SetFieldValue(targetObject, "OwnerId", AuthorizationManager.CurrentUserId);
            SetFieldValue(targetObject, "ModifiedOn", DateTime.Now);
            SetFieldValue(targetObject, "ModifiedById", AuthorizationManager.CurrentUserId);
            return(targetObject);
        }