Exemple #1
0
        private List <DataType> updataAssociatedDataType(Unit unit, long[] newDataTypeIds, UnitManager unitManager)
        {
            if (unit != null)
            {
                DataTypeManager dataTypeManger = null;
                try
                {
                    dataTypeManger = new DataTypeManager();

                    List <DataType> existingDataTypes  = unit.AssociatedDataTypes.ToList();
                    List <DataType> newDataTypes       = newDataTypeIds == null ? new List <DataType>() : dataTypeManger.GetUnitOfWork().GetReadOnlyRepository <DataType>().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);
                    }


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

                    return(unit.AssociatedDataTypes.ToList());
                }
                finally
                {
                    dataTypeManger.Dispose();
                }
            }
            return(null);
        }