Exemple #1
0
        /// <summary>
        /// Registers a deleted object to the repository context.
        /// </summary>
        /// <typeparam name="TEntity">The type of the aggregate root.</typeparam>
        /// <param name="obj">The object to be registered.</param>
        public virtual void RegisterRemoved <TEntity>(TEntity obj)
            where TEntity : IEntity
        {
            var objId = EntityAttributeUtil.GetId(obj);

            if (objId.Equals(string.Empty))
            {
                throw new ArgumentException("The UniqueIdentifier of the object is empty.", nameof(obj));
            }

            if (_localNewCollection.Value.ContainsKey(objId))
            {
                if (_localNewCollection.Value.Remove(objId))
                {
                    return;
                }
            }

            bool removedFromModified = _localModifiedCollection.Value.Remove(objId);
            bool addedToDeleted      = false;

            if (!_localDeletedCollection.Value.ContainsKey(objId))
            {
                _localDeletedCollection.Value.Add(objId, obj);
                addedToDeleted = true;
            }

            _localCommitted.Value = !(removedFromModified || addedToDeleted);
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="obj"></param>
        /// <param name="repositoryItemType"></param>
        /// <param name="operateName"></param>
        public void RegisterCustomOperate <TEntity>(TEntity obj, Type repositoryItemType, string operateName) where TEntity : IEntity
        {
            var objId = EntityAttributeUtil.GetId(obj);

            if (string.IsNullOrEmpty(objId))
            {
                throw new ArgumentException("The UniqueIdentifier of the object is empty.", nameof(obj));
            }
            if (_localDeletedCollection.Value.ContainsKey(objId))
            {
                throw new InvalidOperationException("The object cannot be registered as a modified object since it was marked as deleted.");
            }
            if (!_localCustomOperateCollection.Value.ContainsKey(objId) && !_localNewCollection.Value.ContainsKey(objId))
            {
                _localCustomOperateCollection.Value.Add(objId, new CustomOperate <IEntity>(obj, repositoryItemType, operateName));
            }
            _localCommitted.Value = false;
        }
Exemple #3
0
        /// <summary>
        /// Registers a new object to the repository context.
        /// </summary>
        /// <typeparam name="TEntity">The type of the aggregate root.</typeparam>
        /// <param name="obj">The object to be registered.</param>
        public virtual void RegisterAdded <TEntity>(TEntity obj)
            where TEntity : IEntity
        {
            var objId = EntityAttributeUtil.GetId(obj);

            if (string.IsNullOrEmpty(objId))
            {
                throw new ArgumentException("The UniqueIdentifier of the object is empty.", nameof(obj));
            }

            if (_localModifiedCollection.Value.ContainsKey(objId))
            {
                throw new InvalidOperationException(
                          "The object cannot be registered as a new object since it was marked as modified.");
            }

            if (_localNewCollection.Value.ContainsKey(objId))
            {
                throw new InvalidOperationException("The object has already been registered as a new object.");
            }

            _localNewCollection.Value.Add(objId, obj);
            _localCommitted.Value = false;
        }