Example #1
0
        private Entity AppendEntity(Guid entityGuid)
        {
            var entity = new Entity(_appId, entityGuid, ContentType.StaticName, new Dictionary <string, object>());

            ImportEntities.Add(entity);
            return(entity);
        }
Example #2
0
        /// <summary>
        /// Import an Entity with all values
        /// </summary>
        private Entity CreateMergedForSaving(Entity update, AppDataPackage appDataPackage, SaveOptions saveOptions)
        {
            #region try to get AttributeSet or otherwise cancel & log error

            var dbAttrSet = appDataPackage.ContentTypes.Values
                            .FirstOrDefault(ct => String.Equals(ct.StaticName, update.Type.StaticName, StringComparison.InvariantCultureIgnoreCase));

            if (dbAttrSet == null) // AttributeSet not Found
            {
                Storage.Log.Add(new LogItem(EventLogEntryType.Error, "ContentType not found for " + update.Type.StaticName));
                return(null);
            }

            #endregion

            // Find existing Enties - meaning both draft and non-draft
            List <IEntity> existingEntities = null;
            if (update.EntityGuid != Guid.Empty)
            {
                existingEntities = appDataPackage.List.Where(e => e.EntityGuid == update.EntityGuid).ToList();
            }

            #region Simplest case - nothing existing to update: return entity

            if (existingEntities == null || !existingEntities.Any())
            {
                return(update);
            }

            #endregion

            Storage.Log.Add(new LogItem(EventLogEntryType.Information, $"FYI: Entity {update.EntityId} already exists for guid {update.EntityGuid}"));

            // now update (main) entity id from existing - since it already exists
            var original = existingEntities.First();
            update.ChangeIdForSaving(original.EntityId);
            return(EntitySaver.CreateMergedForSaving(original, update, saveOptions) as Entity);
        }