예제 #1
0
        public void Delete <TDataObject>(int id)
            where TDataObject : class, IIntKeyedDataObject, new()
        {
            using (var scope = DBScope("Removing " + typeof(TDataObject).Name + ". ID = " + id))
            {
                Removed <TDataObject>(id);
                RunInTransaction(scope.Connection, (cn, transaction) =>
                {
                    using (var cmd = cn.CreateCommand())
                    {
                        cmd.Transaction = transaction;
                        var sc          = new SqlSerializationContext((SqlCommand)cmd);
                        DataObjectSqlSerializer <TDataObject> .AppendSoftDeleteSql(sc, id);
                        sc.Finish();
                        cmd.LexExecuteNonQuery();

                        if (DataObjectInfo <TDataObject> .IsSecured)
                        {
                            var updOp = new UpdateOperation <TblPermissions>(
                                new CompareCondition <int>
                                (
                                    new PropertyCondition <int>(ObjectTypeHelper.GetObjectType(typeof(TDataObject)).GetSecurityAtr().Name + "Ref"),
                                    new ValueCondition <int>(id),
                                    COMPARE_KIND.EQUAL
                                ),
                                new PropertyAssignement <int>(DataObject.Schema.SysState, new ValueCondition <int>(1)));
                            Update(updOp, cn, transaction);
                        }
                    }
                });
            }
        }
예제 #2
0
        public void Delete <TDataObject>(IList <int> ids)
            where TDataObject : class, IIntKeyedDataObject, new()
        {
            if (ids.Count > 0)
            {
                using (var scope = DBScope("Removing multiple " + typeof(TDataObject).Name + ". Count = " + ids.Count))
                {
                    foreach (var i in ids)
                    {
                        Logger.WriteLine("ID = " + i);
                        Cache.Remove(FormatCacheKey <TDataObject>(i));
                    }

                    RunInTransaction(scope.Connection, (cn, transaction) =>
                    {
                        using (var cmd = cn.CreateCommand())
                        {
                            cmd.Transaction = transaction;
                            var sc          = new SqlSerializationContext((SqlCommand)cmd);
                            DataObjectSqlSerializer <TDataObject> .
                            AppendSoftDeleteSql(sc, ids);
                            sc.Finish();
                            cmd.LexExecuteNonQuery();
                        }

                        if (DataObjectInfo <TDataObject> .IsSecured)
                        {
                            var idCond = new ValueCondition <int>(0);

                            var updOp = new UpdateOperation <TblPermissions>(
                                new CompareCondition <int>
                                (
                                    new PropertyCondition <int>(ObjectTypeHelper.GetObjectType(typeof(TDataObject)).GetSecurityAtr().Name + "Ref"),
                                    idCond,
                                    COMPARE_KIND.EQUAL
                                ),
                                new PropertyAssignement <int>(DataObject.Schema.SysState, new ValueCondition <int>(1)));
                            foreach (var id in ids)
                            {
                                idCond.Value = id;
                                Update(updOp, cn, transaction);
                            }
                        }
                    });
                }
            }
        }