Skip to content

Commit 1dab209

Browse files
author
CIS Guru
committed
Phase 18: Database preview/import, version upgrade path, and compatibility matrix
- Add DatabasePreviewService with full import pipeline (table mapping, GUID normalization, FK ordering) - Add DatabasePreview.razor UI with preview table, conflict detection, and import confirmation - Update DatabaseSettings.razor with import trigger and status feedback - Fix GUID case mismatch bug: normalize all GUIDs to uppercase before raw SQL writes - Add version-upgrade copy block to Program.cs: copies PreviousDbFileName → new DbFileName on first launch after version bump so EF migrations apply against real data instead of blank DB - Update Compatibility-Matrix.md with versioning policy and DB filename conventions - Minor: LeaseNotificationService null guard, LeaseWorkflowService status transition fix, Index.razor property count tweak
1 parent 5dece45 commit 1dab209

9 files changed

Lines changed: 1507 additions & 347 deletions

File tree

2-Nine.Application/Models/DTOs/DatabasePreviewDTOs.cs

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ public class DatabasePreviewData
1010
public int LeaseCount { get; set; }
1111
public int InvoiceCount { get; set; }
1212
public int PaymentCount { get; set; }
13-
13+
public int MaintenanceCount { get; set; }
14+
public int RepairCount { get; set; }
15+
public int DocumentCount { get; set; }
16+
1417
public List<PropertyPreview> Properties { get; set; } = new();
1518
public List<TenantPreview> Tenants { get; set; } = new();
1619
public List<LeasePreview> Leases { get; set; } = new();
20+
public List<InvoicePreview> Invoices { get; set; } = new();
21+
public List<PaymentPreview> Payments { get; set; } = new();
22+
public List<MaintenancePreview> MaintenanceRequests { get; set; } = new();
23+
public List<RepairPreview> Repairs { get; set; } = new();
1724
}
1825

1926
/// <summary>
@@ -60,17 +67,111 @@ public class LeasePreview
6067
public string Status { get; set; } = string.Empty;
6168
}
6269

70+
/// <summary>
71+
/// DTO for invoice preview in read-only database view
72+
/// </summary>
73+
public class InvoicePreview
74+
{
75+
public Guid Id { get; set; }
76+
public string InvoiceNumber { get; set; } = string.Empty;
77+
public string PropertyAddress { get; set; } = string.Empty;
78+
public string TenantName { get; set; } = string.Empty;
79+
public DateTime DueOn { get; set; }
80+
public decimal Amount { get; set; }
81+
public string Status { get; set; } = string.Empty;
82+
}
83+
84+
/// <summary>
85+
/// DTO for payment preview in read-only database view
86+
/// </summary>
87+
public class PaymentPreview
88+
{
89+
public Guid Id { get; set; }
90+
public string PaymentNumber { get; set; } = string.Empty;
91+
public string InvoiceNumber { get; set; } = string.Empty;
92+
public DateTime PaidOn { get; set; }
93+
public decimal Amount { get; set; }
94+
public string PaymentMethod { get; set; } = string.Empty;
95+
}
96+
97+
/// <summary>
98+
/// DTO for maintenance request preview in read-only database view
99+
/// </summary>
100+
public class MaintenancePreview
101+
{
102+
public Guid Id { get; set; }
103+
public string Title { get; set; } = string.Empty;
104+
public string PropertyAddress { get; set; } = string.Empty;
105+
public string RequestType { get; set; } = string.Empty;
106+
public string Priority { get; set; } = string.Empty;
107+
public string Status { get; set; } = string.Empty;
108+
public DateTime RequestedOn { get; set; }
109+
}
110+
111+
/// <summary>
112+
/// DTO for repair preview in read-only database view
113+
/// </summary>
114+
public class RepairPreview
115+
{
116+
public Guid Id { get; set; }
117+
public string PropertyAddress { get; set; } = string.Empty;
118+
public string Description { get; set; } = string.Empty;
119+
public string RepairType { get; set; } = string.Empty;
120+
public DateTime? CompletedOn { get; set; }
121+
public decimal Cost { get; set; }
122+
}
123+
124+
/// <summary>
125+
/// Represents a non-backup database file found in the data directory (e.g. an older versioned DB)
126+
/// </summary>
127+
public class OtherDatabaseFile
128+
{
129+
public string FileName { get; set; } = string.Empty;
130+
public string FilePath { get; set; } = string.Empty;
131+
public long FileSizeBytes { get; set; }
132+
public string FileSizeFormatted => FormatBytes(FileSizeBytes);
133+
public DateTime LastModified { get; set; }
134+
135+
private static string FormatBytes(long bytes)
136+
{
137+
if (bytes < 1024) return $"{bytes} B";
138+
if (bytes < 1_048_576) return $"{bytes / 1024.0:F1} KB";
139+
return $"{bytes / 1_048_576.0:F1} MB";
140+
}
141+
}
142+
143+
/// <summary>
144+
/// Result of a data import operation from a preview database
145+
/// </summary>
146+
public class ImportResult
147+
{
148+
public bool Success { get; set; }
149+
public string Message { get; set; } = string.Empty;
150+
public int PropertiesImported { get; set; }
151+
public int TenantsImported { get; set; }
152+
public int LeasesImported { get; set; }
153+
public int InvoicesImported { get; set; }
154+
public int PaymentsImported { get; set; }
155+
public int MaintenanceRequestsImported { get; set; }
156+
public int RepairsImported { get; set; }
157+
public int DocumentsImported { get; set; }
158+
public List<string> Errors { get; set; } = new();
159+
160+
public int TotalImported => PropertiesImported + TenantsImported + LeasesImported
161+
+ InvoicesImported + PaymentsImported + MaintenanceRequestsImported + RepairsImported + DocumentsImported;
162+
}
163+
63164
/// <summary>
64165
/// Result object for database operations
65166
/// </summary>
66167
public class DatabaseOperationResult
67168
{
68169
public bool Success { get; set; }
69170
public string Message { get; set; } = string.Empty;
70-
171+
71172
public static DatabaseOperationResult SuccessResult(string message = "Operation successful")
72173
=> new() { Success = true, Message = message };
73-
174+
74175
public static DatabaseOperationResult FailureResult(string message)
75176
=> new() { Success = false, Message = message };
76177
}

0 commit comments

Comments
 (0)