Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add field history modals to web app and mobile app (#1473)
Leendert de Borst6005b53a0fec
diff --git a/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor b/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razorindex 083a438c9..306fa6d49 100644--- a/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor+++ b/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor@@ -1,6 +1,7 @@@using AliasVault.Client.Main.Utilities@using AliasClientDb.Models@using Microsoft.Extensions.Localization+@inject ItemService ItemService@* FieldBlock component - renders a single field based on its type *@@switch (Field.FieldType)@@ -8,9 +9,10 @@case FieldType.Password:case FieldType.Hidden:<div class="col-span-6">+ @RenderLabelWithHistory()<CopyPastePasswordFormRowId="@GetFieldId()"- Label="@GetLabel()"+ Label=""Value="@(Field.Value ?? string.Empty)" /></div>break;@@ -18,7 +20,7 @@<div class="col-span-6">@if (!HideLabel){- <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">@GetLabel()</label>+ @RenderLabelWithHistory()}<div class="p-3 bg-gray-50 dark:bg-gray-700 rounded-lg text-gray-900 dark:text-white whitespace-pre-wrap text-sm">@RenderTextWithLinks(Field.Value ?? string.Empty)@@ -27,7 +29,7 @@break;case FieldType.URL:<div class="col-span-6">- <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">@GetLabel()</label>+ @RenderLabelWithHistory()@if (!string.IsNullOrEmpty(Field.Value)){@if (Field.Value.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || Field.Value.StartsWith("https://", StringComparison.OrdinalIgnoreCase))@@ -45,23 +47,36 @@break;case FieldType.Date:<div class="@(FullWidth ? "col-span-6" : "col-span-6 sm:col-span-3")">+ @RenderLabelWithHistory()<CopyPasteFormRowId="@GetFieldId()"- Label="@GetLabel()"+ Label=""Value="@(Field.Value ?? string.Empty)" /></div>break;default:@* Text, Email, Phone, Number - use standard copy/paste row *@<div class="@(FullWidth ? "col-span-6" : "col-span-6 sm:col-span-3")">+ @RenderLabelWithHistory()<CopyPasteFormRowId="@GetFieldId()"- Label="@GetLabel()"+ Label=""Value="@(Field.Value ?? string.Empty)" /></div>break;}+@* Field History Modal *@+@if (ShowHistoryModal)+{+ <FieldHistoryModal+ ItemId="@ItemId"+ FieldKey="@Field.FieldKey"+ FieldLabel="@GetLabel()"+ IsHidden="@(Field.FieldType == FieldType.Password || Field.FieldType == FieldType.Hidden)"+ OnClose="CloseHistoryModal" />+}+@code {[Inject]private IStringLocalizerFactory LocalizerFactory { get; set; } = default!;@@ -74,6 +89,12 @@[Parameter]public required DisplayField Field { get; set; }+ /// <summary>+ /// Gets or sets the item ID (required for history lookup).+ /// </summary>+ [Parameter]+ public Guid ItemId { get; set; }+/// <summary>/// Gets or sets whether the field should span full width./// </summary>@@ -86,6 +107,82 @@[Parameter]public bool HideLabel { get; set; }+ private bool ShowHistoryModal { get; set; }+ private int HistoryCount { get; set; }++ /// <inheritdoc />+ protected override async Task OnParametersSetAsync()+ {+ await base.OnParametersSetAsync();++ // Check history count if field has history enabled and item ID is provided+ if (Field.EnableHistory && ItemId != Guid.Empty && !string.IsNullOrEmpty(Field.FieldKey))+ {+ HistoryCount = await ItemService.GetFieldHistoryCountAsync(ItemId, Field.FieldKey);+ }+ else+ {+ HistoryCount = 0;+ }+ }++ /// <summary>+ /// Renders the label with optional history icon.+ /// </summary>+ private RenderFragment RenderLabelWithHistory() => builder =>+ {+ builder.OpenElement(0, "label");+ builder.AddAttribute(1, "for", GetFieldId());+ builder.AddAttribute(2, "class", "block mb-2 text-sm font-medium text-gray-900 dark:text-white");++ // Label text+ builder.AddContent(3, GetLabel());++ // History icon (only if history is enabled and there's history data)+ if (Field.EnableHistory && HistoryCount > 0)+ {+ builder.OpenElement(4, "button");+ builder.AddAttribute(5, "type", "button");+ builder.AddAttribute(6, "class", "ml-2 inline-flex items-center text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 focus:outline-none");+ builder.AddAttribute(7, "title", Localizer["ViewHistory"]);+ builder.AddAttribute(8, "onclick", EventCallback.Factory.Create(this, OpenHistoryModal));++ // Clock/history icon SVG+ builder.OpenElement(9, "svg");+ builder.AddAttribute(10, "class", "h-4 w-4");+ builder.AddAttribute(11, "fill", "none");+ builder.AddAttribute(12, "viewBox", "0 0 24 24");+ builder.AddAttribute(13, "stroke-width", "1.5");+ builder.AddAttribute(14, "stroke", "currentColor");+ builder.OpenElement(15, "path");+ builder.AddAttribute(16, "stroke-linecap", "round");+ builder.AddAttribute(17, "stroke-linejoin", "round");+ builder.AddAttribute(18, "d", "M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z");+ builder.CloseElement(); // path+ builder.CloseElement(); // svg++ builder.CloseElement(); // button+ }++ builder.CloseElement(); // label+ };++ /// <summary>+ /// Opens the history modal.+ /// </summary>+ private void OpenHistoryModal()+ {+ ShowHistoryModal = true;+ }++ /// <summary>+ /// Closes the history modal.+ /// </summary>+ private void CloseHistoryModal()+ {+ ShowHistoryModal = false;+ }+/// <summary>/// Gets the label for the field./// </summary>diff --git a/apps/server/AliasVault.Client/Main/Components/Fields/FieldHistoryModal.razor b/apps/server/AliasVault.Client/Main/Components/Fields/FieldHistoryModal.razornew file mode 100644index 000000000..afa1e4fd7--- /dev/null+++ b/apps/server/AliasVault.Client/Main/Components/Fields/FieldHistoryModal.razor@@ -0,0 +1,175 @@+@using AliasClientDb+@using AliasVault.Client.Main.Components.Layout+@using Microsoft.Extensions.Localization+@inject ItemService ItemService+@inject IStringLocalizerFactory LocalizerFactory++<ClickOutsideHandler OnClose="Close" ContentId="fieldHistoryModal">+ <ModalWrapper OnEnter="Close">+ <div id="fieldHistoryModal" class="relative bg-white dark:bg-gray-800 w-full max-w-2xl flex flex-col rounded-lg shadow-xl max-h-[90vh] border-2 border-gray-300 dark:border-gray-600">+ <!-- Header -->+ <div class="p-4 border-b border-gray-200 dark:border-gray-700">+ <div class="flex items-center justify-between">+ <h2 class="text-xl font-bold text-gray-900 dark:text-white">+ @Localizer["HistoryTitle"] - @FieldLabel+ </h2>+ <button @onclick="Close" class="text-gray-400 hover:text-gray-500 dark:hover:text-gray-300">+ <svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>+ </svg>+ </button>+ </div>+ </div>++ <!-- Content -->+ <div class="flex-1 overflow-y-auto p-4">+ @if (IsLoading)+ {+ <div class="flex justify-center items-center py-8">+ <svg class="animate-spin h-8 w-8 text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">+ <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>+ <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>+ </svg>+ </div>+ }+ else if (HistoryRecords.Count == 0)+ {+ <p class="text-gray-500 dark:text-gray-400 text-center py-8">@Localizer["NoHistoryAvailable"]</p>+ }+ else+ {+ <div class="space-y-4">+ @foreach (var record in HistoryRecords)+ {+ <div class="border border-gray-200 dark:border-gray-700 rounded-lg p-4">+ <div class="text-sm text-gray-500 dark:text-gray-400 mb-2">+ @FormatDate(record.ChangedAt)+ </div>+ @{+ var values = ParseValueSnapshot(record.ValueSnapshot);+ }+ @foreach (var value in values)+ {+ <div class="mb-2 last:mb-0">+ @if (IsHidden)+ {+ <CopyPastePasswordFormRow+ Id="@($"history-{record.Id}-{values.IndexOf(value)}")"+ Label=""+ Value="@value" />+ }+ else+ {+ <CopyPasteFormRow+ Id="@($"history-{record.Id}-{values.IndexOf(value)}")"+ Label=""+ Value="@value" />+ }+ </div>+ }+ </div>+ }+ </div>+ }+ </div>++ <!-- Footer -->+ <div class="p-4 border-t border-gray-200 dark:border-gray-700 flex justify-end">+ <button @onclick="Close" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors">+ @Localizer["CloseButton"]+ </button>+ </div>+ </div>+ </ModalWrapper>+</ClickOutsideHandler>++@code {+ private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Fields.FieldHistoryModal", "AliasVault.Client");++ /// <summary>+ /// Gets or sets the item ID.+ /// </summary>+ [Parameter]+ public Guid ItemId { get; set; }++ /// <summary>+ /// Gets or sets the field key.+ /// </summary>+ [Parameter]+ public string FieldKey { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the field label for display.+ /// </summary>+ [Parameter]+ public string FieldLabel { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets whether the field is hidden (password/sensitive).+ /// </summary>+ [Parameter]+ public bool IsHidden { get; set; }++ /// <summary>+ /// Callback when the modal is closed.+ /// </summary>+ [Parameter]+ public EventCallback OnClose { get; set; }++ private bool IsLoading { get; set; } = true;+ private List<FieldHistory> HistoryRecords { get; set; } = new();++ /// <inheritdoc />+ protected override async Task OnInitializedAsync()+ {+ await base.OnInitializedAsync();+ await LoadHistoryAsync();+ }++ /// <summary>+ /// Load field history records.+ /// </summary>+ private async Task LoadHistoryAsync()+ {+ IsLoading = true;+ StateHasChanged();++ HistoryRecords = await ItemService.GetFieldHistoryAsync(ItemId, FieldKey);++ IsLoading = false;+ StateHasChanged();+ }++ /// <summary>+ /// Parse the value snapshot JSON to a list of values.+ /// </summary>+ private List<string> ParseValueSnapshot(string valueSnapshot)+ {+ try+ {+ var values = System.Text.Json.JsonSerializer.Deserialize<List<string>>(valueSnapshot);+ return values ?? new List<string>();+ }+ catch+ {+ // If parsing fails, return the raw value as a single item+ return new List<string> { valueSnapshot };+ }+ }++ /// <summary>+ /// Format the date for display.+ /// </summary>+ private string FormatDate(DateTime date)+ {+ return date.ToString("MMM d, yyyy h:mm tt");+ }++ /// <summary>+ /// Close the modal.+ /// </summary>+ private async Task Close()+ {+ await OnClose.InvokeAsync();+ }+}diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/View.razor b/apps/server/AliasVault.Client/Main/Pages/Items/View.razorindex a6acb726e..82d1e3e08 100644--- a/apps/server/AliasVault.Client/Main/Pages/Items/View.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Items/View.razor@@ -97,7 +97,7 @@ else<div class="grid grid-cols-6 gap-6">@foreach (var field in notesFields){- <FieldBlock Field="@field" HideLabel="true" />+ <FieldBlock Field="@field" ItemId="@Item.Id" HideLabel="true" />}</div></div>@@ -173,7 +173,7 @@ else<div class="grid grid-cols-6 gap-6">@foreach (var field in loginFields){- <FieldBlock Field="@field" />+ <FieldBlock Field="@field" ItemId="@Item.Id" />}</div></form>@@ -201,7 +201,7 @@ else}@foreach (var field in aliasFields){- <FieldBlock Field="@field" />+ <FieldBlock Field="@field" ItemId="@Item.Id" />}</div></form>@@ -218,7 +218,7 @@ else<div class="grid grid-cols-6 gap-6">@foreach (var field in cardFields){- <FieldBlock Field="@field" />+ <FieldBlock Field="@field" ItemId="@Item.Id" />}</div></form>@@ -233,7 +233,7 @@ else<div class="grid grid-cols-6 gap-6">@foreach (var field in noteTypeNotesFields){- <FieldBlock Field="@field" HideLabel="true" />+ <FieldBlock Field="@field" ItemId="@Item.Id" HideLabel="true" />}</div></div>@@ -247,7 +247,7 @@ else<div class="grid grid-cols-6 gap-6">@foreach (var field in customFields){- <FieldBlock Field="@field" FullWidth="true" />+ <FieldBlock Field="@field" ItemId="@Item.Id" FullWidth="true" />}</div></form>diff --git a/apps/server/AliasVault.Client/Resources/Components/Fields/FieldBlock.en.resx b/apps/server/AliasVault.Client/Resources/Components/Fields/FieldBlock.en.resxindex 507e759c4..fe5e42084 100644--- a/apps/server/AliasVault.Client/Resources/Components/Fields/FieldBlock.en.resx+++ b/apps/server/AliasVault.Client/Resources/Components/Fields/FieldBlock.en.resx@@ -126,4 +126,10 @@<value>Notes</value><comment>Label for notes content field</comment></data>++ <!-- History -->+ <data name="ViewHistory" xml:space="preserve">+ <value>View history</value>+ <comment>Tooltip for history icon button</comment>+ </data></root>diff --git a/apps/server/AliasVault.Client/Resources/Components/Fields/FieldHistoryModal.en.resx b/apps/server/AliasVault.Client/Resources/Components/Fields/FieldHistoryModal.en.resxnew file mode 100644index 000000000..a3a31208a--- /dev/null+++ b/apps/server/AliasVault.Client/Resources/Components/Fields/FieldHistoryModal.en.resx@@ -0,0 +1,73 @@+<?xml version="1.0" encoding="utf-8"?>+<root>+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />+ <xsd:element name="root" msdata:IsDataSet="true">+ <xsd:complexType>+ <xsd:choice maxOccurs="unbounded">+ <xsd:element name="metadata">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" />+ </xsd:sequence>+ <xsd:attribute name="name" use="required" type="xsd:string" />+ <xsd:attribute name="type" type="xsd:string" />+ <xsd:attribute name="mimetype" type="xsd:string" />+ <xsd:attribute ref="xml:space" />+ </xsd:complexType>+ </xsd:element>+ <xsd:element name="assembly">+ <xsd:complexType>+ <xsd:attribute name="alias" type="xsd:string" />+ <xsd:attribute name="name" type="xsd:string" />+ </xsd:complexType>+ </xsd:element>+ <xsd:element name="data">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />+ </xsd:sequence>+ <xsd:attribute name="name" use="required" type="xsd:string" />+ <xsd:attribute name="type" type="xsd:string" />+ <xsd:attribute name="mimetype" type="xsd:string" />+ <xsd:attribute ref="xml:space" />+ </xsd:complexType>+ </xsd:element>+ <xsd:element name="resheader">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />+ </xsd:sequence>+ <xsd:attribute name="name" use="required" type="xsd:string" />+ </xsd:complexType>+ </xsd:element>+ </xsd:choice>+ </xsd:complexType>+ </xsd:element>+ </xsd:schema>+ <resheader name="resmimetype">+ <value>text/microsoft-resx</value>+ </resheader>+ <resheader name="version">+ <value>2.0</value>+ </resheader>+ <resheader name="reader">+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>+ </resheader>+ <resheader name="writer">+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>+ </resheader>+ <data name="HistoryTitle" xml:space="preserve">+ <value>History</value>+ <comment>Title for the field history modal</comment>+ </data>+ <data name="NoHistoryAvailable" xml:space="preserve">+ <value>No history available</value>+ <comment>Message shown when no history records exist</comment>+ </data>+ <data name="CloseButton" xml:space="preserve">+ <value>Close</value>+ <comment>Close button text</comment>+ </data>+</root>diff --git a/apps/server/AliasVault.Client/Services/ItemService.cs b/apps/server/AliasVault.Client/Services/ItemService.csindex c5ac31d2b..4ec4b6fd1 100644--- a/apps/server/AliasVault.Client/Services/ItemService.cs+++ b/apps/server/AliasVault.Client/Services/ItemService.cs@@ -294,6 +294,9 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, ConfClearInapplicableData(context, existingItem, item.ItemType, updateDateTime);}+ // Track history for fields with EnableHistory=true before updating+ await TrackFieldHistoryAsync(context, existingItem, item, updateDateTime);+// Update field valuesUpdateFieldValues(context, existingItem, item, updateDateTime);@@ -681,6 +684,38 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Confreturn false;}+ /// <summary>+ /// Get field history for a specific item and field.+ /// </summary>+ /// <param name="itemId">The item ID.</param>+ /// <param name="fieldKey">The field key.</param>+ /// <returns>List of field history records.</returns>+ public async Task<List<FieldHistory>> GetFieldHistoryAsync(Guid itemId, string fieldKey)+ {+ var context = await dbService.GetDbContextAsync();++ return await context.FieldHistories+ .Where(fh => fh.ItemId == itemId && fh.FieldKey == fieldKey && !fh.IsDeleted)+ .OrderByDescending(fh => fh.ChangedAt)+ .Take(10)+ .ToListAsync();+ }++ /// <summary>+ /// Get field history count for a specific item and field.+ /// </summary>+ /// <param name="itemId">The item ID.</param>+ /// <param name="fieldKey">The field key.</param>+ /// <returns>Number of history records.</returns>+ public async Task<int> GetFieldHistoryCountAsync(Guid itemId, string fieldKey)+ {+ var context = await dbService.GetDbContextAsync();++ return await context.FieldHistories+ .Where(fh => fh.ItemId == itemId && fh.FieldKey == fieldKey && !fh.IsDeleted)+ .CountAsync();+ }+/// <summary>/// Gets a field value from an item by field key./// </summary>@@ -1250,4 +1285,107 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf// Return the mapped language, or fall back to "en" if no match foundreturn mappedLanguage ?? "en";}++ /// <summary>+ /// Track field history for fields with EnableHistory=true.+ /// Compares old values with new values and creates history records.+ /// </summary>+ /// <param name="context">The database context.</param>+ /// <param name="existingItem">The existing item in the database.</param>+ /// <param name="newItem">The new item with updated field values.</param>+ /// <param name="updateDateTime">The timestamp for updates.</param>+ /// <returns>Task.</returns>+#pragma warning disable SA1204 // Static members should appear before non-static members+ private static async Task TrackFieldHistoryAsync(AliasClientDbContext context, Item existingItem, Item newItem, DateTime updateDateTime)+#pragma warning restore SA1204+ {+ // Maximum number of history records to keep per field+ const int MaxFieldHistoryRecords = 10;++ // Get the existing tracked field values from the existingItem (loaded with Include)+ var existingFields = existingItem.FieldValues.Where(fv => !fv.IsDeleted).ToList();++ // Group existing fields by key to support multi-value fields+ var existingByFieldKey = existingFields+ .Where(f => f.FieldKey != null)+ .GroupBy(f => f.FieldKey!)+ .ToDictionary(g => g.Key, g => g.OrderBy(f => f.Weight).Select(f => f.Value ?? string.Empty).ToList());++ // Group new fields by key to handle multi-value fields+ var newFieldsByKey = newItem.FieldValues+ .Where(fv => !fv.IsDeleted && fv.FieldKey != null)+ .GroupBy(f => f.FieldKey!)+ .ToDictionary(g => g.Key, g => g.OrderBy(f => f.Weight).Select(f => f.Value ?? string.Empty).ToList());++ foreach (var (fieldKey, newValues) in newFieldsByKey)+ {+ // Check if history tracking is enabled for this field+ var fieldDef = SystemFieldRegistry.GetSystemField(fieldKey);+ if (fieldDef == null || !fieldDef.EnableHistory)+ {+ continue;+ }++ var oldValues = existingByFieldKey.TryGetValue(fieldKey, out var values) ? values : new List<string>();++ // Check if values have changed+ var valuesChanged = oldValues.Count != newValues.Count ||+ !oldValues.SequenceEqual(newValues);++ // Only create history if values changed AND there were old values+ if (valuesChanged && oldValues.Count > 0)+ {+ // Create a JSON snapshot of old values+ var valueSnapshot = System.Text.Json.JsonSerializer.Serialize(oldValues);++ // Create new history record+ var historyRecord = new FieldHistory+ {+ Id = Guid.NewGuid(),+ ItemId = existingItem.Id,+ FieldKey = fieldKey,+ FieldDefinitionId = null,+ ValueSnapshot = valueSnapshot,+ ChangedAt = updateDateTime,+ CreatedAt = updateDateTime,+ UpdatedAt = updateDateTime,+ IsDeleted = false,+ };+ context.FieldHistories.Add(historyRecord);++ // Prune old history records to keep only the most recent+ await PruneFieldHistoryAsync(context, existingItem.Id, fieldKey, MaxFieldHistoryRecords, updateDateTime);+ }+ }+ }++ /// <summary>+ /// Prune old field history records.+ /// Keeps only the most recent MaxFieldHistoryRecords records.+ /// </summary>+ /// <param name="context">The database context.</param>+ /// <param name="itemId">The item ID.</param>+ /// <param name="fieldKey">The field key.</param>+ /// <param name="maxRecords">Maximum number of records to keep.</param>+ /// <param name="updateDateTime">The timestamp for updates.</param>+ /// <returns>Task.</returns>+ private static async Task PruneFieldHistoryAsync(AliasClientDbContext context, Guid itemId, string fieldKey, int maxRecords, DateTime updateDateTime)+ {+ // Get all history records for this field, ordered by ChangedAt descending+ var historyRecords = await context.FieldHistories+ .Where(fh => fh.ItemId == itemId && fh.FieldKey == fieldKey && !fh.IsDeleted)+ .OrderByDescending(fh => fh.ChangedAt)+ .ToListAsync();++ // If we have more than maxRecords, soft-delete the old ones+ if (historyRecords.Count > maxRecords)+ {+ var recordsToDelete = historyRecords.Skip(maxRecords);+ foreach (var record in recordsToDelete)+ {+ record.IsDeleted = true;+ record.UpdatedAt = updateDateTime;+ }+ }+ }}