private string GetDeleteQuery(string tableName, string whichColumnForWhereCondition, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }
            var queryBuilder = new DeleteQueryBuilder();

            queryBuilder.SelectFromTable(tableName);
            queryBuilder.AddWhere(whichColumnForWhereCondition, Comparison.Equals, value, 1);
            var query = queryBuilder.BuildQuery();

            return(query);
        }
Beispiel #2
0
        public bool AddRelations(Guid tenantId, string relationEntityName, string parentEntityName, Guid parentId, string childEntityName, List <Guid> childIds)
        {
            IMetadataManager _metadaManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();

            var tableName  = _metadaManager.GetTableNameByEntityname(relationEntityName);
            var primaryKey = _metadaManager.GetPrimaryKeyByEntityname(relationEntityName);

            var fields = _metadaManager.GetColumnNameByEntityName(relationEntityName, null);

            if (fields.Any())
            {
                var parentTableName = _metadaManager.GetTableNameByEntityname(parentEntityName);
                var parentField     = fields.FirstOrDefault(t => t.ReferenceTableName.Equals(parentTableName));

                var childTableName = _metadaManager.GetTableNameByEntityname(childEntityName);
                var childField     = fields.FirstOrDefault(t => t.ReferenceTableName.Equals(childTableName));

                //delete and create....
                var queryBuilder = new DeleteQueryBuilder();
                queryBuilder.SelectFromTable(tableName);
                queryBuilder.AddWhere(parentField.ColumnName, Comparison.Equals, parentId.ToString(), 1);
                var deleteQuery = queryBuilder.BuildQuery();
                //----------------------------------------------------------------------------------------
                IRelationQueryAdmin deleteAdmin = new RelationQueryAdmin();
                var res = deleteAdmin.DeleteResult(tenantId, relationEntityName, deleteQuery);

                //need to change this logic....
                foreach (var childId in childIds)
                {
                    var insertQueryBuilder = new InsertQueryBuilder();
                    var insertColumns      = GetNecessaryColumns(tenantId, parentId, fields, parentField);
                    insertColumns.Add(childField.ColumnName, childId.ToString());
                    insertQueryBuilder.InsertIntoTable(tableName, insertColumns, false);
                    var insertQuery = insertQueryBuilder.BuildQuery();
                    IRelationQueryAdmin saveAdmin = new RelationQueryAdmin();
                    saveAdmin.SaveResult(tenantId, relationEntityName, insertQuery);
                }
            }
            return(true);
        }