BExIS.Dlm.Services.DataStructure.UnitManager.RemoveAssociatedDataType C# (CSharp) Метод

RemoveAssociatedDataType() публичный Метод

public RemoveAssociatedDataType ( Unit end1, DataType end2 ) : bool
end1 BExIS.Dlm.Entities.DataStructure.Unit
end2 BExIS.Dlm.Entities.DataStructure.DataType
Результат bool
        public bool RemoveAssociatedDataType(Unit end1, DataType end2)
        {
            Contract.Requires(end1 != null && end1.Id >= 0);
            Contract.Requires(end2 != null && end2.Id >= 0);

            bool result = false;
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Unit> repo = uow.GetRepository<Unit>();
                IRepository<DataType> dtRepo = uow.GetRepository<DataType>();

                end1 = repo.Reload(end1);
                repo.LoadIfNot(end1.AssociatedDataTypes);

                end2 = dtRepo.Reload(end2);
                dtRepo.LoadIfNot(end2.ApplicableUnits);

                if (end1.AssociatedDataTypes.Contains(end2) || end2.ApplicableUnits.Contains(end1))
                {
                    end1.AssociatedDataTypes.Remove(end2);
                    end2.ApplicableUnits.Remove(end1);
                    uow.Commit();
                    result = true;
                }
            }
            return (result);
        }

Same methods

UnitManager::RemoveAssociatedDataType ( Unit end1, IEnumerable end2 ) : bool

Usage Example

Пример #1
0
        private List<DataType> updataAssociatedDataType(Unit unit, long[] newDataTypeIds)
        {
            if (unit != null)
            {
                DataTypeManager dataTypeManger = new DataTypeManager();

                UnitManager unitManager = new UnitManager();

                unit = unitManager.Repo.Get(unit.Id);
                List<DataType> existingDataTypes = unit.AssociatedDataTypes.ToList();
                List<DataType> newDataTypes = newDataTypeIds == null ? new List<DataType>() : dataTypeManger.Repo.Query().Where(p => newDataTypeIds.Contains(p.Id)).ToList();
                List<DataType> tobeAddedDataTypes = newDataTypes.Except(existingDataTypes).ToList();

                if (tobeAddedDataTypes != null && tobeAddedDataTypes.Count > 0)
                    unitManager.AddAssociatedDataType(unit, tobeAddedDataTypes);

                unit = unitManager.Repo.Get(unit.Id);
                existingDataTypes = unit.AssociatedDataTypes.ToList();
                List<DataType> toBeRemoved = existingDataTypes.Except(newDataTypes).ToList();
                if (toBeRemoved != null && toBeRemoved.Count() > 0)
                    unitManager.RemoveAssociatedDataType(unit, toBeRemoved);

                unit = unitManager.Repo.Get(unit.Id);
                return unit.AssociatedDataTypes.ToList();
            }
            return null;
        }