/// <summary>
        /// Populates the auto-populated columns of the entity and returns a list of attributes that were created / updated
        /// </summary>
        private static void PopulateAutoPopulatedAttributes <T>(LocalCrmDatabaseOrganizationService service, T entity, bool isCreate) where T : Entity
        {
            var properties = PropertiesCache.For <T>();
            var info       = service.Info;
            var name       = GetFullName(info,
                                         entity.GetAttributeValue <string>(SystemUser.Fields.FirstName),
                                         entity.GetAttributeValue <string>(SystemUser.Fields.MiddleName),
                                         entity.GetAttributeValue <string>(SystemUser.Fields.LastName));

            // TODO: Need to add logic to see if an update to the Full Name is being Performed
            ConditionallyAddValue(entity, properties, SystemUser.Fields.FullName, name, !string.IsNullOrWhiteSpace(name));

            AutoPopulateContactFields(entity, properties);
            AutoPopulateOpportunityFields(service, entity, isCreate);

            if (isCreate)
            {
                SetAttributeId(entity);
                SetStatusToActiveForCreate(entity);
                SetOwnerForCreate(service, entity, properties);
                ConditionallyAddValue(entity, properties, Email.Fields.CreatedBy, info.User, info.User.GetIdOrDefault() != Guid.Empty);
                ConditionallyAddValue(entity, properties, Email.Fields.CreatedOnBehalfBy, info.UserOnBehalfOf, info.UserOnBehalfOf.GetIdOrDefault() != Guid.Empty);
                ConditionallyAddValue(entity, properties, Email.Fields.CreatedOn, entity.Contains(Email.Fields.OverriddenCreatedOn) ? entity[Email.Fields.OverriddenCreatedOn] : DateTime.UtcNow);
                ConditionallyAddValue(entity, properties, Email.Fields.OwningBusinessUnit, info.BusinessUnit, !entity.Contains(Email.Fields.OwningBusinessUnit) && info.BusinessUnit.GetIdOrDefault() != Guid.Empty);
            }
            else if (entity.Contains(Email.Fields.OwnerId))
            {
                UpdateOwningFieldsBasedOnOwner(service, entity, properties);
            }

            PopulateModifiedAttributes(service.Info, entity, properties);
        }
Exemple #2
0
        private static void UpdateActivityPointer <T>(LocalCrmDatabaseOrganizationService service, T entity) where T : Entity
        {
            if (entity.LogicalName == ActivityPointer.EntityLogicalName || !PropertiesCache.For <T>().IsActivityType)
            {
                return; // Type is already an activity pointer, no need to re-update
            }

            service.Update(GetActivityPointerForActivityEntity(entity));
        }
Exemple #3
0
        private static void CreateActivityParties <T>(LocalCrmDatabaseOrganizationService service, T entity) where T : Entity
        {
            if (entity.LogicalName == ActivityParty.EntityLogicalName ||
                entity.LogicalName == ActivityPointer.EntityLogicalName ||
                !PropertiesCache.For <T>().IsActivityType)
            {
                return;
            }

            CreateActivityPartiesFromPartyLists(service, entity);
            CreateActivityPartiesFromSingleFields(service, entity);
        }
Exemple #4
0
        /// <summary>
        /// Creates the activity pointer if the Entity is an Activity Type
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="service">The service.</param>
        /// <param name="entity">The entity.</param>
        private static void CreateActivityPointer <T>(LocalCrmDatabaseOrganizationService service, T entity) where T : Entity
        {
            if (EntityHelper.GetEntityLogicalName <T>() == ActivityPointer.EntityLogicalName)
            {
                return; // Type is already an activity pointer, no need to recreated
            }

            if (!PropertiesCache.For <T>().IsActivityType)
            {
                return; // Type is not an activity type
            }

            // Copy over matching values and create
            service.Create(GetActivityPointerForActivityEntity(entity));
        }
Exemple #5
0
        private static Entity GetActivityPointerForActivityEntity <T>(T entity) where T : Entity
        {
            var pointerFields = typeof(ActivityPointer.Fields).GetFields();
            var pointer       = new Entity(ActivityPointer.EntityLogicalName)
            {
                Id = entity.Id
            };

            foreach (var att in pointerFields.Where(p => PropertiesCache.For <T>().ContainsProperty(p.Name))
                     .Select(field => field.GetRawConstantValue().ToString()).Where(entity.Contains))
            {
                pointer[att] = entity[att];
            }

            return(pointer);
        }
Exemple #6
0
        private static void DeleteActivityPointer <T>(LocalCrmDatabaseOrganizationService service, Guid id) where T : Entity
        {
            if (EntityHelper.GetEntityLogicalName <T>() == ActivityPointer.EntityLogicalName || !PropertiesCache.For <T>().IsActivityType)
            {
                return; // Type is already an activity pointer, no need to redelete, or type is not an activity type
            }

            service.Delete(ActivityPointer.EntityLogicalName, id);
        }