public void DeleteLocalizationsFor(Part part, String key)
 {
     foreach(var localization in _groups[part.ToString()].GetAllQualified().Where(qv => qv.Qualifier.Key == key).ToArray())
         DeleteValue(localization.Qualifier);
 }
 public void DeleteLocalizationsFor(Part part, String key)
 {
     using (var connection = Connect()) {
         var partId = _partTable.GetPart(part.ToString()).Id;
         foreach (var locale in _localeTable.GetAll())
             _valueTable.Delete(new InternalQualifier(partId, locale.Id, key), connection);
     }
 }
        private GroupNode GetOrCreateGroupNode(Part part)
        {
            var partString = part.ToString();
            if (_groups.ContainsKey(partString))
                return _groups[partString];

            var hierarchy = part.StackHierarchy();

            GroupNode node = null;
            foreach (var hierarchyPart in hierarchy) {
                var hierarchyPartString = hierarchyPart.ToString();
                if (_groups.ContainsKey(hierarchyPartString))
                    node = _groups[hierarchyPartString];
                else {
                    node = new GroupNode(hierarchyPart.Name, node);
                    _groups.Add(hierarchyPartString, node);
                }
            }
            return node;
        }
            public DBPart Insert(Part part, Connector connector)
            {
                var connection = connector.Connection;
                if (connection.State != ConnectionState.Open)
                    connection.Open();

                var partsToCreate = new List<Part>();
                while (part != null && GetPart(part.ToString()) == null)
                {
                    partsToCreate.Add(part);
                    part = part.Parent;
                }
                partsToCreate.Reverse();

                var command = new SqlCommand(String.Format(
                        "delete from {0} where {1} = @name and {2} = @parentId; insert into {0}({1}, {2}) values(@name, @parentId); select IDENT_CURRENT('{0}')",
                        _table, NameColumn, ParentIdColumn
                    ), connection
                );

                var lastCreatedPartId = part == null ? null : ((int?)GetPart(part.ToString()).Id);
                var lastCreatedPart = lastCreatedPartId == null ? null : _partsById[lastCreatedPartId.Value];
                foreach(var partToCreate in partsToCreate)
                {
                    command.Parameters.Clear();

                    command.Parameters.Add(new SqlParameter("name", SqlDbType.VarChar) { Value = partToCreate.Name });
                    command.Parameters.Add(new SqlParameter("parentId", SqlDbType.BigInt) { Value = (Object)lastCreatedPartId ?? DBNull.Value });

                    var newPart = new DBPart(Int32.Parse(command.ExecuteScalar().ToString()), partToCreate.Name, lastCreatedPart);
                    _partsById.Add(newPart.Id, newPart);
                    _partsByQualifier.Add(newPart.ToString().ToLower(), newPart);
                    lastCreatedPart = newPart;
                }

                return lastCreatedPart;
            }