Beispiel #1
0
        /// <summary>
        /// Insert the specified <paramref name="items"/> to the mapping store with <paramref name="state"/>
        /// </summary>
        /// <param name="state">
        ///     The MAPPING STORE connection and transaction state
        /// </param>
        /// <param name="items">
        ///     The items.
        /// </param>
        /// <param name="parentArtefact">
        ///     The primary key of the parent artefact.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{Long}"/>.
        /// </returns>
        public ItemStatusCollection Insert(DbTransactionState state, IEnumerable <IComponent> items, long parentArtefact)
        {
            var components = items as IComponent[] ?? items.ToArray();

            if (components.Length == 0)
            {
                return(new ItemStatusCollection());
            }

            var cache        = new StructureCache();
            var returnValues = new ItemStatusCollection();

            var dsd = components[0].MaintainableParent as IDataStructureObject;

            if (dsd == null)
            {
                throw new ArgumentException(Resources.ExceptionCannotDetermineParent, "items");
            }

            foreach (var component in components)
            {
                returnValues.Add(new ItemStatus(component.Id, Insert(state, component, cache, parentArtefact)));
            }

            return(returnValues);
        }
Beispiel #2
0
        /// <summary>
        /// Insert the specified <paramref name="items"/> to the mapping store with <paramref name="state"/>
        /// </summary>
        /// <param name="state">
        ///     The MAPPING STORE connection and transaction state
        /// </param>
        /// <param name="items">
        ///     The items.
        /// </param>
        /// <param name="parentArtefact">
        ///     The primary key of the parent artefact.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{Long}"/>.
        /// </returns>
        public ItemStatusCollection Insert(DbTransactionState state, IEnumerable <IGroup> items, long parentArtefact)
        {
            var storedProcedure = _insertDsdGroup;
            var annotations     = new List <Tuple <long, IGroup> >();
            var groupIds        = new ItemStatusCollection();

            using (DbCommand command = storedProcedure.CreateCommand(state))
            {
                DbParameter dsdParameter = storedProcedure.CreateDsdIdParameter(command);

                DbParameter idParameter = storedProcedure.CreateIdParameter(command);

                DbParameter outputParameter = storedProcedure.CreateOutputParameter(command);

                foreach (var group in items)
                {
                    idParameter.Value  = group.Id;
                    dsdParameter.Value = parentArtefact;

                    command.ExecuteNonQuery();

                    var id = (long)outputParameter.Value;
                    groupIds.Add(new ItemStatus(group.Id, id));
                    if (group.Annotations.Count > 0)
                    {
                        annotations.Add(new Tuple <long, IGroup>(id, group));
                    }
                }
            }

            foreach (var annotation in annotations)
            {
                IAnnotableObject annotableObject = annotation.Item2;
                _annotationInsertEngine.Insert(state, annotation.Item1, _insertGroupAnnotation, annotableObject.Annotations);
            }

            return(groupIds);
        }