Exemplo n.º 1
0
        private void GetHierarchyRecords(RecordHierarchy parentHierarchy, IEnumerable <dynamic> records, IList <EntityHierarchy> subHierarchies, string foreignKey = null, string foreignKeyValue = null)
        {
            foreach (var hierarchy in subHierarchies)
            {
                var prefix = hierarchy.Alias.Trim("[]".ToCharArray()) + "_";

                foreach (var record in records)
                {
                    var recordDict = (IDictionary <string, object>)record;
                    var rowData    = ExpandoToDataRow(recordDict, hierarchy.Entity, prefix);

                    if (!rowData.KeyValue.IsNullOrEmpty())
                    {
                        var subRecord = new RecordHierarchy
                        {
                            Entity                = hierarchy.Entity,
                            KeyValue              = rowData.KeyValue,
                            DisplayName           = GetDisplayName(hierarchy.Entity, rowData),
                            SubRecordsHierarchies = new List <RecordHierarchy>()
                        };

                        if (parentHierarchy.SubRecordsHierarchies.FirstOrDefault(x => x.KeyValue == subRecord.KeyValue) == null &&
                            (foreignKey.IsNullOrEmpty() || recordDict[foreignKey].ToStringSafe() == foreignKeyValue))
                        {
                            parentHierarchy.SubRecordsHierarchies.Add(subRecord);

                            GetHierarchyRecords(subRecord, records, hierarchy.SubHierarchies, prefix + hierarchy.Entity.Key.ColumnName, rowData.KeyValue);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private IList <string> GetDeleteRelatedEntityDeleteSql(DbCommand cmd, RecordHierarchy record)
        {
            // {0} - Foreign table
            // {1} - Primary key
            // {2} - Key value
            const string deleteFormat = "DELETE FROM {0} WHERE {1};";

            var paramIndex = cmd.Parameters.Count;

            cmd.AddParams(record.KeyValue.ToArray());
            var whereParts = new List <string>();

            foreach (var key in record.Entity.Key)
            {
                whereParts.Add("{0} = @{1}".Fill(key.ColumnName, paramIndex++));
            }
            var wherePart = string.Join(" AND ", whereParts);

            var sql = deleteFormat.Fill(
                record.Entity.TableName,
                wherePart);

            var sqls = new List <string>()
            {
                sql
            };

            foreach (var subRecord in record.SubRecordsHierarchies)
            {
                sqls.AddRange(GetDeleteRelatedEntityDeleteSql(cmd, subRecord));
            }

            return(sqls);
        }
Exemplo n.º 3
0
        private string GetSetToNullUpdateSql(DbCommand cmd, Entity entity, RecordHierarchy subRecord)
        {
            // {0} - Foreign table
            // {1} - Foreign key
            // {2} - Primary key
            // {3} - Key value
            const string updateFormat = "UPDATE {0} SET {1} = @{2} WHERE {3};";
            //UPDATE Products SET CategoryID = null WHERE ProductID = 7

            var foreignTable = subRecord.Entity.TableName;
            var foreignKey   = subRecord.Entity.Properties.FirstOrDefault(x => x.ForeignEntity == entity).ColumnName;
            var nullIndex    = cmd.Parameters.Count;
            var paramIndex   = nullIndex + 1;

            cmd.AddParam(null);
            cmd.AddParams(subRecord.KeyValue.ToArray());

            var whereParts = new List <string>();

            foreach (var key in subRecord.Entity.Key)
            {
                whereParts.Add("{0} = @{1}".Fill(key.ColumnName, paramIndex++));
            }
            var wherePart = string.Join(" AND ", whereParts);

            var updateSql = updateFormat.Fill(
                foreignTable,
                foreignKey,
                nullIndex,
                wherePart);

            return(updateSql);
        }
Exemplo n.º 4
0
        private string GetSetToNullUpdateSql(DbCommand cmd, Entity entity, RecordHierarchy subRecord)
        {
            // {0} - Foreign table
            // {1} - Foreign key
            // {2} - Primary key
            // {3} - Key value
            const string updateFormat = "UPDATE {0} SET {1} = @{2} WHERE {3} = @{4};";
            //UPDATE Products SET CategoryID = null WHERE ProductID = 7

            var foreignTable = subRecord.Entity.TableName;
            var foreignKey   = subRecord.Entity.Properties.FirstOrDefault(x => x.ForeignEntity == entity).ColumnName;
            var primaryKey   = subRecord.Entity.Key.ColumnName;
            var paramIndex   = cmd.Parameters.Count;

            cmd.AddParam(null);
            cmd.AddParam(subRecord.KeyValue);

            var updateSql = updateFormat.Fill(
                foreignTable,
                foreignKey,
                paramIndex++,
                primaryKey,
                paramIndex);

            return(updateSql);
        }
Exemplo n.º 5
0
        private IList <string> GetDeleteRelatedEntityDeleteSql(DbCommand cmd, RecordHierarchy record)
        {
            // {0} - Foreign table
            // {1} - Primary key
            // {2} - Key value
            const string deleteFormat = "DELETE FROM {0} WHERE {1} = @{2};";

            var paramIndex = cmd.Parameters.Count;

            cmd.AddParam(record.KeyValue);

            var sql = deleteFormat.Fill(
                record.Entity.TableName,
                record.Entity.Key.ColumnName,
                paramIndex);

            var sqls = new List <string>()
            {
                sql
            };

            foreach (var subRecord in record.SubRecordsHierarchies)
            {
                sqls.AddRange(GetDeleteRelatedEntityDeleteSql(cmd, subRecord));
            }

            return(sqls);
        }
Exemplo n.º 6
0
        private string GetSetToNullUpdateSql(Entity entity, RecordHierarchy subRecord)
        {
            // {0} - Foreign table
            // {1} - Foreign key
            // {2} - Primary key
            // {3} - Key value
            var updateFormat = "UPDATE {0} SET {1} = NULL WHERE {2} = {3};";
            //UPDATE Products SET CategoryID = null WHERE ProductID = 7

            var foreignTable = subRecord.Entity.TableName;
            var foreignKey   = subRecord.Entity.Properties.FirstOrDefault(x => x.ForeignEntity == entity).ColumnName;
            var primaryKey   = subRecord.Entity.Key.ColumnName;
            var keyValue     = DecorateSqlValue(subRecord.KeyValue, subRecord.Entity.Key);

            var updateSql = string.Format(updateFormat, foreignTable, foreignKey, primaryKey, keyValue);

            return(updateSql);
        }
Exemplo n.º 7
0
        private RecordHierarchy GetHierarchyRecords(IEnumerable <dynamic> records, EntityHierarchy hierarchy)
        {
            var baseRecord = records.FirstOrDefault();
            var prefix     = hierarchy.Alias.Trim("[]".ToCharArray()) + "_";
            var rowData    = ExpandoToDataRow(baseRecord, hierarchy.Entity, prefix);

            var recordHierarchy = new RecordHierarchy
            {
                Entity                = hierarchy.Entity,
                KeyValue              = rowData.KeyValue,
                DisplayName           = GetDisplayName(hierarchy.Entity, rowData),
                SubRecordsHierarchies = new List <RecordHierarchy>()
            };

            GetHierarchyRecords(recordHierarchy, records, hierarchy.SubHierarchies);

            return(recordHierarchy);
        }
Exemplo n.º 8
0
        private IList <string> GetDeleteRelatedEntityDeleteSql(RecordHierarchy record)
        {
            var sqls = new List <string>();

            // {0} - Foreign table
            // {1} - Primary key
            // {2} - Key value
            var deleteFormat = "DELETE FROM {0} WHERE {1} = {2};";

            sqls.Add(string.Format(deleteFormat, record.Entity.TableName, record.Entity.Key.ColumnName, DecorateSqlValue(record.KeyValue, record.Entity.Key)));

            foreach (var subRecord in record.SubRecordsHierarchies)
            {
                sqls.AddRange(GetDeleteRelatedEntityDeleteSql(subRecord));
            }

            return(sqls);
        }
Exemplo n.º 9
0
        private void GetHierarchyRecords(
            RecordHierarchy parentHierarchy, 
            IList<dynamic> records, 
            IEnumerable<EntityHierarchy> subHierarchies, 
            string foreignKey = null, 
            string foreignKeyValue = null)
        {
            foreach (var hierarchy in subHierarchies)
            {
                var prefix = hierarchy.Alias.Trim("[]".ToCharArray()) + "_";

                foreach (var record in records)
                {
                    var recordDict = (IDictionary<string, object>)record;
                    var rowData = new DataRow(recordDict, hierarchy.Entity, prefix);

                    if (!rowData.KeyValue.IsNullOrEmpty())
                    {
                        var subRecord = new RecordHierarchy
                        {
                            Entity = hierarchy.Entity,
                            KeyValue = rowData.KeyValue,
                            DisplayName = hierarchy.Entity.ToString(rowData),
                            SubRecordsHierarchies = new List<RecordHierarchy>()
                        };

                        if (parentHierarchy.SubRecordsHierarchies.FirstOrDefault(x => x.KeyValue == subRecord.KeyValue) == null &&
                            (foreignKey.IsNullOrEmpty() || recordDict[foreignKey].ToStringSafe() == foreignKeyValue))
                        {
                            parentHierarchy.SubRecordsHierarchies.Add(subRecord);

                            GetHierarchyRecords(
                                subRecord, 
                                records, 
                                hierarchy.SubHierarchies, 
                                prefix + hierarchy.Entity.Key.ColumnName, 
                                rowData.KeyValue);
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        private RecordHierarchy GetHierarchyRecords(
            IList<IDictionary<string, object>> records,
            EntityHierarchy hierarchy)
        {
            var baseRecord = records.FirstOrDefault();
            var prefix = hierarchy.Alias.Undecorate() + "_";
            var record = hierarchy.Entity.CreateRecord(baseRecord, prefix);

            var recordHierarchy = new RecordHierarchy
            {
                Entity = hierarchy.Entity,
                JoinedKeysValues = record.JoinedKeysValues,
                DisplayName = record.ToString(),
                SubRecordsHierarchies = new List<RecordHierarchy>()
            };

            GetHierarchyRecords(recordHierarchy, records, hierarchy.SubHierarchies);

            return recordHierarchy;
        }
Exemplo n.º 11
0
        private RecordHierarchy GetHierarchyRecords(
            IList <IDictionary <string, object> > records,
            EntityHierarchy hierarchy)
        {
            var baseRecord = records.FirstOrDefault();
            var prefix     = hierarchy.Alias.Undecorate() + "_";
            var record     = hierarchy.Entity.CreateRecord(baseRecord, prefix);

            var recordHierarchy = new RecordHierarchy
            {
                Entity                = hierarchy.Entity,
                JoinedKeysValues      = record.JoinedKeysValues,
                DisplayName           = record.ToString(),
                SubRecordsHierarchies = new List <RecordHierarchy>()
            };

            GetHierarchyRecords(recordHierarchy, records, hierarchy.SubHierarchies);

            return(recordHierarchy);
        }
        private RecordHierarchy GetHierarchyRecords(
            IList<IDictionary<string, object>> records,
            EntityHierarchy hierarchy)
        {
            var baseRecord = records.FirstOrDefault();
            var prefix = hierarchy.Alias.Undecorate() + "_";
            var rowData = new DataRow(baseRecord, hierarchy.Entity, prefix);

            var recordHierarchy = new RecordHierarchy
            {
                Entity = hierarchy.Entity,
                KeyValue = rowData.KeyValue,
                DisplayName = hierarchy.Entity.ToString(rowData),
                SubRecordsHierarchies = new List<RecordHierarchy>()
            };

            GetHierarchyRecords(recordHierarchy, records, hierarchy.SubHierarchies);

            return recordHierarchy;
        }
Exemplo n.º 13
0
        private RecordHierarchy GetHierarchyRecords(
            IList<dynamic> records,
            EntityHierarchy hierarchy)
        {
            var baseRecord = records.FirstOrDefault();
            var prefix = hierarchy.Alias.Trim("[]".ToCharArray()) + "_";
            var rowData = new DataRow(baseRecord, hierarchy.Entity, prefix);

            var recordHierarchy = new RecordHierarchy
            {
                Entity = hierarchy.Entity,
                KeyValue = rowData.KeyValue,
                DisplayName = hierarchy.Entity.ToString(rowData),
                SubRecordsHierarchies = new List<RecordHierarchy>()
            };

            GetHierarchyRecords(recordHierarchy, records, hierarchy.SubHierarchies);

            return recordHierarchy;
        }
Exemplo n.º 14
0
        private RecordHierarchy GetHierarchyRecords(
            IList <IDictionary <string, object> > records,
            EntityHierarchy hierarchy)
        {
            var baseRecord = records.FirstOrDefault();
            var prefix     = hierarchy.Alias.Undecorate() + "_";
            var rowData    = new DataRow(baseRecord, hierarchy.Entity, prefix);

            var recordHierarchy = new RecordHierarchy
            {
                Entity                = hierarchy.Entity,
                KeyValue              = rowData.KeyValue,
                DisplayName           = hierarchy.Entity.ToString(rowData),
                SubRecordsHierarchies = new List <RecordHierarchy>()
            };

            GetHierarchyRecords(recordHierarchy, records, hierarchy.SubHierarchies);

            return(recordHierarchy);
        }
Exemplo n.º 15
0
        private void GetHierarchyRecords(
            RecordHierarchy parentHierarchy,
            IList <IDictionary <string, object> > records,
            IEnumerable <EntityHierarchy> subHierarchies,
            IList <string> foreignKey      = null,
            IList <string> foreignKeyValue = null)
        {
            foreach (var hierarchy in subHierarchies)
            {
                var prefix = hierarchy.Alias.Undecorate() + "_";

                foreach (var record in records)
                {
                    var rowData = new DataRow(record, hierarchy.Entity, prefix);

                    if (!rowData.KeyValue.IsNullOrEmpty())
                    {
                        var subRecord = new RecordHierarchy
                        {
                            Entity                = hierarchy.Entity,
                            KeyValue              = rowData.KeyValue,
                            DisplayName           = hierarchy.Entity.ToString(rowData),
                            SubRecordsHierarchies = new List <RecordHierarchy>()
                        };

                        if (parentHierarchy.SubRecordsHierarchies.FirstOrDefault(x => x.JoinedKeyValue == subRecord.JoinedKeyValue) == null &&
                            Matching(record, foreignKey, foreignKeyValue))
                        {
                            parentHierarchy.SubRecordsHierarchies.Add(subRecord);

                            GetHierarchyRecords(
                                subRecord,
                                records,
                                hierarchy.SubHierarchies,
                                hierarchy.Entity.Key.Select(x => prefix + x.ColumnName.Undecorate()).ToList(),
                                rowData.KeyValue);
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        private void GetHierarchyRecords(
            RecordHierarchy parentHierarchy,
            IList <IDictionary <string, object> > records,
            IEnumerable <EntityHierarchy> subHierarchies,
            IList <string> foreignKey      = null,
            IList <string> foreignKeyValue = null)
        {
            foreach (var hierarchy in subHierarchies)
            {
                var prefix = hierarchy.Alias.Undecorate() + "_";

                foreach (var record in records)
                {
                    var entityRecord = hierarchy.Entity.CreateRecord(record, prefix);

                    if (entityRecord.Keys.Any(x => x.AsString.HasValue()))
                    {
                        var subRecord = new RecordHierarchy
                        {
                            Entity                = hierarchy.Entity,
                            JoinedKeysValues      = entityRecord.JoinedKeysValues,
                            DisplayName           = entityRecord.ToString(),
                            SubRecordsHierarchies = new List <RecordHierarchy>()
                        };

                        if (parentHierarchy.SubRecordsHierarchies.FirstOrDefault(x => x.JoinedKeysValues == subRecord.JoinedKeysValues) == null &&
                            Matching(record, foreignKey, foreignKeyValue))
                        {
                            parentHierarchy.SubRecordsHierarchies.Add(subRecord);

                            GetHierarchyRecords(
                                subRecord,
                                records,
                                hierarchy.SubHierarchies,
                                hierarchy.Entity.Keys.Select(x => prefix + x.Column.Undecorate()).ToList(),
                                entityRecord.Keys.Select(x => x.AsString).ToList());
                        }
                    }
                }
            }
        }
        private void GetHierarchyRecords(
            RecordHierarchy parentHierarchy,
            IList<IDictionary<string, object>> records,
            IEnumerable<EntityHierarchy> subHierarchies,
            IList<string> foreignKey = null,
            IList<string> foreignKeyValue = null)
        {
            foreach (var hierarchy in subHierarchies)
            {
                var prefix = hierarchy.Alias.Undecorate() + "_";

                foreach (var record in records)
                {
                    var rowData = new DataRow(record, hierarchy.Entity, prefix);

                    if (!rowData.KeyValue.IsNullOrEmpty())
                    {
                        var subRecord = new RecordHierarchy
                        {
                            Entity = hierarchy.Entity,
                            KeyValue = rowData.KeyValue,
                            DisplayName = hierarchy.Entity.ToString(rowData),
                            SubRecordsHierarchies = new List<RecordHierarchy>()
                        };

                        if (parentHierarchy.SubRecordsHierarchies.FirstOrDefault(x => x.JoinedKeyValue == subRecord.JoinedKeyValue) == null &&
                            Matching(record, foreignKey, foreignKeyValue))
                        {
                            parentHierarchy.SubRecordsHierarchies.Add(subRecord);

                            GetHierarchyRecords(
                                subRecord,
                                records,
                                hierarchy.SubHierarchies,
                                hierarchy.Entity.Key.Select(x => prefix + x.ColumnName.Undecorate()).ToList(),
                                rowData.KeyValue);
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
        private void GetHierarchyRecords(
            RecordHierarchy parentHierarchy,
            IList<IDictionary<string, object>> records,
            IEnumerable<EntityHierarchy> subHierarchies,
            IList<string> foreignKey = null,
            IList<string> foreignKeyValue = null)
        {
            foreach (var hierarchy in subHierarchies)
            {
                var prefix = hierarchy.Alias.Undecorate() + "_";

                foreach (var record in records)
                {
                    var entityRecord = hierarchy.Entity.CreateRecord(record, prefix);

                    if (entityRecord.Keys.Any(x => x.AsString.HasValue()))
                    {
                        var subRecord = new RecordHierarchy
                        {
                            Entity = hierarchy.Entity,
                            JoinedKeysValues = entityRecord.JoinedKeysValues,
                            DisplayName = entityRecord.ToString(),
                            SubRecordsHierarchies = new List<RecordHierarchy>()
                        };

                        if (parentHierarchy.SubRecordsHierarchies.FirstOrDefault(x => x.JoinedKeysValues == subRecord.JoinedKeysValues) == null &&
                            Matching(record, foreignKey, foreignKeyValue))
                        {
                            parentHierarchy.SubRecordsHierarchies.Add(subRecord);

                            GetHierarchyRecords(
                                subRecord,
                                records,
                                hierarchy.SubHierarchies,
                                hierarchy.Entity.Keys.Select(x => prefix + x.Column.Undecorate()).ToList(),
                                entityRecord.Keys.Select(x=>x.AsString).ToList());
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
        public HelperResult DisplayRecordHierarchy(RecordHierarchy record)
        {
#line default
#line hidden
            return(new HelperResult(__razor_helper_writer => {
#line 58 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"



#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "    <li>\r\n");

                WriteLiteralTo(__razor_helper_writer, "        ");


#line 60 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                WriteTo(__razor_helper_writer, record.Entity.Name);


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, ": ");


#line 60 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                WriteTo(__razor_helper_writer, Html.ActionLink(record.DisplayName, "Edit", new { entityName = record.Entity.Name, key = record.KeyValue }));


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "\r\n");


#line 61 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"


#line default
#line hidden

#line 61 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                if (record.SubRecordsHierarchies.Any())
                {
#line default
#line hidden
                    WriteLiteralTo(__razor_helper_writer, "            <ul>\r\n");


#line 64 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"


#line default
#line hidden

#line 64 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                    foreach (var subRecord in record.SubRecordsHierarchies)
                    {
#line default
#line hidden
                        WriteLiteralTo(__razor_helper_writer, "                    ");


#line 66 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                        WriteTo(__razor_helper_writer, DisplayRecordHierarchy(subRecord));


#line default
#line hidden
                        WriteLiteralTo(__razor_helper_writer, "\r\n");


#line 67 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                    }


#line default
#line hidden
                    WriteLiteralTo(__razor_helper_writer, "            </ul>\r\n");


#line 69 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                }


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "    </li>\r\n");


#line 71 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"


#line default
#line hidden
            }));

#line 71 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
        }
Exemplo n.º 20
0
        private IList<string> GetDeleteRelatedEntityDeleteSql(DbCommand cmd, RecordHierarchy record)
        {
            // {0} - Foreign table
            // {1} - Primary key
            // {2} - Key value
            const string deleteFormat = "DELETE FROM {0} WHERE {1};";

            var paramIndex = cmd.Parameters.Count;
            cmd.AddParams(record.KeyValue.ToArray());
            var whereParts = new List<string>();
            foreach (var key in record.Entity.Key)
            {
                whereParts.Add("{0} = @{1}".Fill(key.ColumnName, paramIndex++));
            }
            var wherePart = string.Join(" AND ", whereParts);

            var sql = deleteFormat.Fill(
                record.Entity.TableName,
                wherePart);

            var sqls = new List<string>() { sql };
            foreach (var subRecord in record.SubRecordsHierarchies)
            {
                sqls.AddRange(GetDeleteRelatedEntityDeleteSql(cmd, subRecord));
            }

            return sqls;
        }
Exemplo n.º 21
0
        private string GetSetToNullUpdateSql(DbCommand cmd, Entity entity, RecordHierarchy subRecord)
        {
            // {0} - Foreign table
            // {1} - Foreign key
            // {2} - Primary key
            // {3} - Key value
            const string updateFormat = "UPDATE {0} SET {1} = @{2} WHERE {3};";
            //UPDATE Products SET CategoryID = null WHERE ProductID = 7

            var foreignTable = subRecord.Entity.TableName;
            var foreignKey = subRecord.Entity.Properties.FirstOrDefault(x => x.ForeignEntity == entity).ColumnName;
            var nullIndex = cmd.Parameters.Count;
            var paramIndex = nullIndex + 1;
            cmd.AddParam(null);
            cmd.AddParams(subRecord.KeyValue.ToArray());

            var whereParts = new List<string>();
            foreach (var key in subRecord.Entity.Key)
            {
                whereParts.Add("{0} = @{1}".Fill(key.ColumnName, paramIndex++));
            }
            var wherePart = string.Join(" AND ", whereParts);

            var updateSql = updateFormat.Fill(
                foreignTable,
                foreignKey,
                nullIndex,
                wherePart);

            return updateSql;
        }
Exemplo n.º 22
0
        private IList<string> GetDeleteRelatedEntityDeleteSql(DbCommand cmd, RecordHierarchy record)
        {
            // {0} - Foreign table
            // {1} - Primary key
            // {2} - Key value
            const string deleteFormat = "DELETE FROM {0} WHERE {1} = @{2};";

            var paramIndex = cmd.Parameters.Count;
            cmd.AddParam(record.KeyValue);

            var sql = deleteFormat.Fill(
                record.Entity.TableName,
                record.Entity.Key.ColumnName,
                paramIndex);

            var sqls = new List<string>() { sql };
            foreach (var subRecord in record.SubRecordsHierarchies)
            {
                sqls.AddRange(GetDeleteRelatedEntityDeleteSql(cmd, subRecord));
            }

            return sqls;
        }
Exemplo n.º 23
0
        private string GetSetToNullUpdateSql(DbCommand cmd, Entity entity, RecordHierarchy subRecord)
        {
            // {0} - Foreign table
            // {1} - Foreign key
            // {2} - Primary key
            // {3} - Key value
            const string updateFormat = "UPDATE {0} SET {1} = @{2} WHERE {3} = @{4};";
            //UPDATE Products SET CategoryID = null WHERE ProductID = 7

            var foreignTable = subRecord.Entity.TableName;
            var foreignKey = subRecord.Entity.Properties.FirstOrDefault(x => x.ForeignEntity == entity).ColumnName;
            var primaryKey = subRecord.Entity.Key.ColumnName;
            var paramIndex = cmd.Parameters.Count;
            cmd.AddParam(null);
            cmd.AddParam(subRecord.KeyValue);

            var updateSql = updateFormat.Fill(
                foreignTable,
                foreignKey,
                paramIndex++,
                primaryKey,
                paramIndex);

            return updateSql;
        }
Exemplo n.º 24
0
        public System.Web.WebPages.HelperResult DisplayRecordHierarchy(RecordHierarchy record)
        {
#line default
#line hidden
            return(new System.Web.WebPages.HelperResult(__razor_helper_writer => {
#line 72 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"



#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "    <li>\r\n");

                WriteLiteralTo(__razor_helper_writer, "        ");


#line 74 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                WriteTo(__razor_helper_writer, record.Entity.Name);


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, ": ");


#line 74 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                WriteTo(__razor_helper_writer, Html.ActionLink(record.DisplayName.GetValueOrDefault("--empty--"), "Edit", new { entityName = record.Entity.Name, key = record.JoinedKeysValues }));


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "\r\n");


#line 75 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"


#line default
#line hidden

#line 75 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                if (record.SubRecordsHierarchies.Any())
                {
#line default
#line hidden
                    WriteLiteralTo(__razor_helper_writer, "            <ul>\r\n");


#line 78 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"


#line default
#line hidden

#line 78 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                    foreach (var subRecord in record.SubRecordsHierarchies)
                    {
#line default
#line hidden
                        WriteLiteralTo(__razor_helper_writer, "                    ");


#line 80 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                        WriteTo(__razor_helper_writer, DisplayRecordHierarchy(subRecord));


#line default
#line hidden
                        WriteLiteralTo(__razor_helper_writer, "\r\n");


#line 81 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                    }


#line default
#line hidden
                    WriteLiteralTo(__razor_helper_writer, "            </ul>\r\n");


#line 83 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
                }


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "    </li>\r\n");


#line 85 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"


#line default
#line hidden
            }));

#line 85 "..\..\Areas\IlaroAdmin\Views\Entity\Delete.cshtml"
        }