Beispiel #1
0
        /// <summary>
        /// Adds the specified item to the data store, but makes an attempt to
        /// ensure that it has an identity first.  If <paramref name="identity"/> is
        /// <c>null</c> and the item is an implementation of <see cref="IEntity"/> then
        /// <see cref="IGeneratesIdentity.UpdateWithIdentity(CSF.Entities.IEntity)"/>
        /// is used first to generate an identity for the item.
        /// </summary>
        /// <param name="item">The data item to add.</param>
        /// <param name="identity">Optional, the item's identity.</param>
        /// <returns>The identity value which the item has, after it was added.</returns>
        /// <typeparam name="T">The item type.</typeparam>
        public object Add <T>(T item, object identity = null) where T : class
        {
            if (identity != null)
            {
                return(wrapped.Add <T>(item, identity));
            }

            if (item is IEntity entity)
            {
                identityGenerator.UpdateWithIdentity(entity);
                return(wrapped.Add <T>((T)entity, entity.IdentityValue));
            }

            return(wrapped.Add <T>(item, identity));
        }
Beispiel #2
0
        /// <summary>
        /// Add the specified entity.
        /// </summary>
        /// <param name="entity">Entity.</param>
        public void Add(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            persister.Add(entity, entity.GetIdentity()?.Value);
        }
        private void PersistContentEntity(Content contentEntity)
        {
            Log.Begin($"{nameof(PersistContentEntity)}.{contentEntity}");

            _contentEntityPersister.Add(contentEntity);
            _contentEntityPersister.Save();

            Log.End($"{nameof(PersistContentEntity)}.{contentEntity}");
        }
        /// <summary>
        /// Add the specified entity.
        /// </summary>
        /// <param name="entity">Entity.</param>
        /// <typeparam name="TEntity">The entity type.</typeparam>
        public void Add <TEntity>(TEntity entity) where TEntity : class, IEntity
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            persister.Add(entity, entity.GetIdentity()?.Value);
        }
Beispiel #5
0
        /// <summary>
        /// Add the specified entity.
        /// </summary>
        /// <param name="entity">Entity.</param>
        /// <typeparam name="TEntity">The entity type.</typeparam>
        public IIdentity <TEntity> Add <TEntity>(TEntity entity) where TEntity : class, IEntity
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var    identity = entity.GetIdentity();
            object idValue;

            if (identity != null)
            {
                idValue = persister.Add(entity, identity.Value);
                return(ReferenceEquals(idValue, null)? null : (IIdentity <TEntity>)idFactory.Create(typeof(TEntity), idValue));
            }

            idValue = persister.Add(entity);
            return(ReferenceEquals(idValue, null) ? null : (IIdentity <TEntity>)idFactory.Create(typeof(TEntity), idValue));
        }
Beispiel #6
0
        public DatabaseInfoDto CreateNewDatabase(string databaseName)
        {
            if (string.IsNullOrEmpty(databaseName))
            {
                throw new Exception("Please give correct name to the new created database");
            }
            var newEntity = _databaseInfoHandler.BuildNewDatabase(databaseName);

            _persister.Add(newEntity);
            _persister.Save();

            return(new DatabaseInfoDtoConverter().ToDto(newEntity));
        }