BExIS.Dlm.Services.DataStructure.UnitManager.DeleteConversionMethod C# (CSharp) Method

DeleteConversionMethod() public method

public DeleteConversionMethod ( IEnumerable entities ) : bool
entities IEnumerable
return bool
        public bool DeleteConversionMethod(IEnumerable<ConversionMethod> entities)
        {
            Contract.Requires(entities != null);
            Contract.Requires(Contract.ForAll(entities, (ConversionMethod e) => e != null));
            Contract.Requires(Contract.ForAll(entities, (ConversionMethod e) => e.Id >= 0));

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<ConversionMethod> repoCM = uow.GetRepository<ConversionMethod>();

                foreach (var entity in entities)
                {
                    var latest = repoCM.Reload(entity); ;

                    // remove all associations
                    latest.Source = null;
                    latest.Target = null;

                    //delete the entity
                    repoCM.Delete(latest);
                }
                // commit changes
                uow.Commit();
            }
            return (true);
        }

Same methods

UnitManager::DeleteConversionMethod ( ConversionMethod entity ) : bool

Usage Example

コード例 #1
0
ファイル: TestController.cs プロジェクト: BEXIS2/Core
        private void Add2UnitsAnd1ConversionUsingAPI()
        {
            UnitManager um = new UnitManager();
            Unit km = um.Create("Kilometer", "Km", "This is the Kilometer", null, MeasurementSystem.Metric);// null dimension should be replaced
            Unit m = um.Create("Meter", "M", "This is the Meter", null, MeasurementSystem.Metric);// null dimension should be replaced
            Unit cm = um.Create("Centimeter", "Cm", "This is the CentiMeter which is equal to 0.01 Meter", null, MeasurementSystem.Metric);
            ConversionMethod cm1 = um.CreateConversionMethod("s*100", "Converts meter to centi meter", m, cm);
            ConversionMethod cm2 = um.CreateConversionMethod("s*1000", "Converts kilometer to meter", km, m);
            ConversionMethod cm3 = um.CreateConversionMethod("s/1000", "Converts meter to kilometer", m, km);
            ConversionMethod cm4 = um.CreateConversionMethod("s/100", "Converts centimeter to meter", cm, m);

            km.Description += "Updated";
            cm1.Description += "Updated";
            km.ConversionsIamTheSource.Clear(); //??
            um.Update(km);
            um.UpdateConversionMethod(cm1);

            // Works fine: 24.07.12, Javad
            //DataTypeManager dtManager = new DataTypeManager();
            //DataType deci = dtManager.Create("Decimal", "A decimal data type", TypeCode.Int16);
            //um.AddAssociatedDataType(m, deci);
            //um.RemoveAssociatedDataType(m, deci);

            um.DeleteConversionMethod(cm1);
            um.DeleteConversionMethod(new List<ConversionMethod>() { cm2, cm3 });

            um.Delete(cm);
            um.Delete(new List<Unit>() { km, m });
        }