TestDatabase.cshtml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. @{
  2. ViewData["Title"] = "Database Test";
  3. }
  4. <div class="container mt-4">
  5. <h2>Database Connection Test</h2>
  6. <div class="alert @(ViewBag.Error != null ? "alert-danger" : "alert-success")">
  7. <h4>@ViewBag.ConnectionStatus</h4>
  8. @if (ViewBag.Error != null)
  9. {
  10. <p><strong>Error:</strong> @ViewBag.Error</p>
  11. }
  12. @if (ViewBag.RecipeCount != null)
  13. {
  14. <p><strong>Recipes in database:</strong> @ViewBag.RecipeCount</p>
  15. }
  16. @if (ViewBag.TableError != null)
  17. {
  18. <p><strong>Table Error:</strong> @ViewBag.TableError</p>
  19. }
  20. </div>
  21. @if (ViewBag.Tables != null)
  22. {
  23. <div class="card">
  24. <div class="card-header">
  25. <h5>Tables in Database 'recept'</h5>
  26. </div>
  27. <div class="card-body">
  28. @if (((List<string>)ViewBag.Tables).Any())
  29. {
  30. <ul class="list-group">
  31. @foreach (var table in (List<string>)ViewBag.Tables)
  32. {
  33. <li class="list-group-item">
  34. @table
  35. @if (table.ToLower().Contains("recepie"))
  36. {
  37. <span class="badge bg-success ms-2">Recipe Related</span>
  38. }
  39. </li>
  40. }
  41. </ul>
  42. }
  43. else
  44. {
  45. <p class="text-muted">No tables found in the database.</p>
  46. }
  47. </div>
  48. </div>
  49. }
  50. @if (ViewBag.RecepieColumns != null)
  51. {
  52. <div class="card mt-3">
  53. <div class="card-header">
  54. <h5>Structure of 'recepie' table</h5>
  55. </div>
  56. <div class="card-body">
  57. <div class="table-responsive">
  58. <table class="table table-striped">
  59. <thead>
  60. <tr>
  61. <th>Column Name</th>
  62. <th>Data Type</th>
  63. <th>Nullable</th>
  64. <th>Key</th>
  65. </tr>
  66. </thead>
  67. <tbody>
  68. @foreach (var column in (List<dynamic>)ViewBag.RecepieColumns)
  69. {
  70. <tr>
  71. <td><strong>@column.Name</strong></td>
  72. <td>@column.Type</td>
  73. <td>@column.Nullable</td>
  74. <td>@column.Key</td>
  75. </tr>
  76. }
  77. </tbody>
  78. </table>
  79. </div>
  80. </div>
  81. </div>
  82. }
  83. @if (ViewBag.SampleData != null && ViewBag.ColumnNames != null)
  84. {
  85. <div class="card mt-3">
  86. <div class="card-header">
  87. <h5>Sample Data from 'recepie' table</h5>
  88. </div>
  89. <div class="card-body">
  90. <div class="table-responsive">
  91. <table class="table table-striped table-sm">
  92. <thead>
  93. <tr>
  94. @foreach (var columnName in (List<string>)ViewBag.ColumnNames)
  95. {
  96. <th>@columnName</th>
  97. }
  98. </tr>
  99. </thead>
  100. <tbody>
  101. @foreach (var row in (List<Dictionary<string, object>>)ViewBag.SampleData)
  102. {
  103. <tr>
  104. @foreach (var columnName in (List<string>)ViewBag.ColumnNames)
  105. {
  106. <td>
  107. @{
  108. var value = row[columnName]?.ToString() ?? "NULL";
  109. if (value.Length > 50)
  110. {
  111. value = value.Substring(0, 47) + "...";
  112. }
  113. }
  114. @value
  115. </td>
  116. }
  117. </tr>
  118. }
  119. </tbody>
  120. </table>
  121. </div>
  122. </div>
  123. </div>
  124. }
  125. <div class="mt-3">
  126. <a href="@Url.Action("Index")" class="btn btn-primary">Back to Recipes</a>
  127. </div>
  128. </div>