コード例 #1
0
        private void addDataTypes(long unitId, List <string> datatypeNames, UnitManager unitManager, DataTypeManager dataTypeManger)
        {
            if (unitId <= 0 || datatypeNames == null || datatypeNames.Count <= 0)
            {
                return;
            }
            var unitRepo     = unitManager.GetUnitOfWork().GetReadOnlyRepository <Unit>();
            var dataTypeRepo = dataTypeManger.GetUnitOfWork().GetReadOnlyRepository <DataType>();

            Unit unit = unitRepo.Get(unitId);

            // add bpp-dataTypes to the unit
            if (unit == null)
            {
                return;
            }
            DataType dt = new DataType();

            foreach (string type in datatypeNames)
            {
                dt = dataTypeRepo.Get().Where(d => d.Name.ToLower().Equals(type.ToLower())).FirstOrDefault();
                if (dt != null && !(unit.AssociatedDataTypes.Contains(dt)))
                {
                    unit.AssociatedDataTypes.Add(dt);
                }
            }
            unitManager.Update(unit);
        }
コード例 #2
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);
        }
コード例 #3
0
        private Unit updataAssociatedDataType(Unit unit, long[] newDataTypeIds)
        {
            if (unit != null)
            {
                DataTypeManager dataTypeManger = null;
                try
                {
                    dataTypeManger = new DataTypeManager();
                    List <DataType> newDataTypes = newDataTypeIds == null ? new List <DataType>() : dataTypeManger.GetUnitOfWork().GetReadOnlyRepository <DataType>().Query().Where(p => newDataTypeIds.Contains(p.Id)).ToList();

                    unit.AssociatedDataTypes = newDataTypes;

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