Beispiel #1
0
        private static void Update <T>(LocalCrmDatabaseOrganizationService service, T entity, DelayedException exception) where T : Entity
        {
            AssertTypeContainsColumns <T>(entity.Attributes.Keys);
            AssertEntityReferencesExists(service, entity);
            SimulateCrmAttributeManipulations(entity);
            if (SimulateCrmUpdateActionPrevention(service, entity, exception))
            {
                return;
            }

            // Get the Entity From the database
            var databaseValue = SchemaGetOrCreate <T>(service.Info).FirstOrDefault(e => e.Id == entity.Id);

            if (databaseValue == null)
            {
                exception.Exception = CrmExceptions.GetEntityDoesNotExistException(entity);
                return;
            }

            // Update all of the attributes from the entity passed in, to the database entity
            foreach (var attribute in entity.Attributes)
            {
                databaseValue[attribute.Key] = attribute.Value;
            }

            // Set all Autopopulated values
            service.PopulateAutoPopulatedAttributes(databaseValue, false);

            SchemaGetOrCreate <T>(service.Info).Update(databaseValue);

            UpdateActivityPointer(service, databaseValue);
        }
Beispiel #2
0
        private static Guid Create <T>(LocalCrmDatabaseOrganizationService service, T entity, DelayedException exception) where T : Entity
        {
            // Clone entity so no changes will affect actual entity
            entity = entity.Serialize().DeserializeEntity <T>();

            AssertTypeContainsColumns <T>(entity.Attributes.Keys);
            AssertEntityReferencesExists(service, entity);
            SimulateCrmAttributeManipulations(entity);
            if (SimulateCrmCreateActionPrevention(entity, exception))
            {
                return(Guid.Empty);
            }
            var table = SchemaGetOrCreate <T>(service.Info);

            service.PopulateAutoPopulatedAttributes(entity, true);

            // Clear non Attribute Related Values
            entity.FormattedValues.Clear();
            entity.KeyAttributes.Clear();
            //var relatedEntities = entity.RelatedEntities.ToList();
            entity.RelatedEntities.Clear();

            if (entity.Id == Guid.Empty)
            {
                entity.Id = Guid.NewGuid();
            }

            table.Insert(entity);

            CreateActivityPointer(service, entity);

            return(entity.Id);
        }
        public static Guid Create <T>(LocalCrmDatabaseOrganizationService service, T entity) where T : Entity
        {
            // Clone entity so no changes will affect actual entity
            entity = entity.Serialize().DeserializeEntity <T>();

            AssertTypeContainsColumns <T>(entity.Attributes.Keys);
            AssertEntityReferencesExists(service, entity);
            ConvertEntityArrayToEntityCollection(entity);
            var table = SchemaGetOrCreate <T>(service.Info);

            service.PopulateAutoPopulatedAttributes(entity, true);

            if (entity.Id == Guid.Empty)
            {
                entity.Id = Guid.NewGuid();
            }

            table.Insert(entity);

            CreateActivityPointer(service, entity);

            return(entity.Id);
        }