Esempio n. 1
0
        public void Set(object fromKey, IEnumerable toKeys)
        {
            var oldToKeys = GetToKeys(fromKey);

            RelationEditor.Set(fromKey, toKeys);
            var logContext = new LogContext()
            {
                FromKey       = fromKey,
                RelationName  = RelationName,
                AddedToKeys   = toKeys.Cast <object>().Where(toKey => !DalcRelationEditor.Contains(toKey, oldToKeys)).ToArray(),
                RemovedToKeys = oldToKeys.Cast <object>().Where(oldToKey => !DalcRelationEditor.Contains(oldToKey, toKeys)).ToArray()
            };

            WriteLog.Execute(logContext);
        }
Esempio n. 2
0
        public void Set(object fromKey, IEnumerable toKeys)
        {
            // load
            var relationTbl = DalcManager.LoadAll(new Query(RelationSourceName, ComposeFromCondition(fromKey)));

            var data = ExtraKeys == null ? new Dictionary <string, object>() : new Dictionary <string, object>(ExtraKeys);

            data[FromFieldName] = fromKey;

            int pos = 1;

            foreach (var toKey in toKeys)
            {
                DataRow relationRow = relationTbl.Rows.Cast <DataRow>().Where(r => DalcRelationEditor.AreEqual(toKey, r[ToFieldName])).FirstOrDefault();
                if (relationRow == null)
                {
                    relationRow = relationTbl.NewRow();
                    relationRow[FromFieldName] = fromKey;
                    relationRow[ToFieldName]   = toKey;
                    if (ExtraKeys != null)
                    {
                        foreach (var extraKeyEntry in ExtraKeys)
                        {
                            relationRow[extraKeyEntry.Key] = extraKeyEntry.Value;
                        }
                    }
                    relationTbl.Rows.Add(relationRow);
                }

                if (PositionFieldName != null)
                {
                    relationRow[PositionFieldName] = pos++;
                }
            }

            // delete missed relations
            foreach (DataRow r in relationTbl.Rows)
            {
                if (!DalcRelationEditor.Contains(r[ToFieldName], toKeys))
                {
                    r.Delete();
                }
            }

            DalcManager.Update(relationTbl);
        }