Ejemplo n.º 1
0
        public void DeleteTagFromEntity(EntityType entityType, int entityID, String tagName)
        {
            using (var db = GetDb())
            {
                var tagID = db.ExecuteScalar<int>(Query("crm_tag").Select("id")
                                     .Where(Exp.Eq("lower(title)", tagName.ToLower()) & Exp.Eq("entity_type", (int)entityType)));

                if (tagID == 0) return;

                var sqlQuery = new SqlDelete("crm_entity_tag")
                    .Where(Exp.Eq("entity_type", (int)entityType) & Exp.Eq("tag_id", tagID));

                if (entityID > 0)
                    sqlQuery.Where(Exp.Eq("entity_id", entityID));

                db.ExecuteNonQuery(sqlQuery);

                if (entityID == 0)
                    db.ExecuteNonQuery(Delete("crm_tag")
                        .Where(Exp.Eq("id", tagID) & Exp.Eq("entity_type", (int)entityType)));
            }
        }
Ejemplo n.º 2
0
        protected void RemoveRelative(int[] contactID, EntityType entityType, int[] entityID, DbManager db)
        {

            if ((contactID == null || contactID.Length == 0) && (entityID == null || entityID.Length == 0))
                throw new ArgumentException();

            var sqlQuery = new SqlDelete("crm_entity_contact");

            if (contactID != null && contactID.Length > 0)
                sqlQuery.Where(Exp.In("contact_id", contactID));

            if (entityID != null && entityID.Length > 0)
                sqlQuery.Where(Exp.In("entity_id", entityID) & Exp.Eq("entity_type", (int)entityType));

            db.ExecuteNonQuery(sqlQuery);
        }
Ejemplo n.º 3
0
        public void RemoveProvider(string obj, string provider = null, string hashId = null)
        {
            CacheEntry.Reset(obj);

            var sql = new SqlDelete(LinkTable).Where("id", obj);

            if (!string.IsNullOrEmpty(provider)) sql.Where("provider", provider);
            if (!string.IsNullOrEmpty(hashId)) sql.Where("uid", hashId);

            using (var db = new DbManager(_dbid))
            {
                db.ExecuteScalar<int>(sql);
            }
        }
Ejemplo n.º 4
0
        protected void SetRelative(int[] contactID, EntityType entityType, int entityID)
        {
            using (var db = GetDb())
            using (var tx = db.BeginTransaction())
            {

                var sqlDelete = new SqlDelete("crm_entity_contact");

                if (entityID == 0)
                    throw new ArgumentException();

                sqlDelete.Where(Exp.Eq("entity_type", entityType) & Exp.Eq("entity_id", entityID));

                db.ExecuteNonQuery(sqlDelete);

                if (!(contactID == null || contactID.Length == 0))
                    foreach (var id in contactID)
                        SetRelative(id, entityType, entityID, db);

                tx.Commit();
            }
        }