remove bounced contacts

pull/3/head
Sascha 2023-08-24 09:47:12 +07:00
parent 7abacc9c14
commit 5bc5064f02
3 changed files with 24 additions and 2 deletions

@ -146,6 +146,7 @@
<Paragraph> <Paragraph>
<Button Color="Color.Primary" Clicked="@OnRemoveDublicates">Remove Dublicates</Button> <Button Color="Color.Primary" Clicked="@OnRemoveDublicates">Remove Dublicates</Button>
<Button Color="Color.Secondary" Clicked="@OnRemoveBounced">Remove Bounced</Button>
</Paragraph> </Paragraph>
<Heading Size="HeadingSize.Is6">Import Contacts from CSV</Heading> <Heading Size="HeadingSize.Is6">Import Contacts from CSV</Heading>

@ -92,6 +92,17 @@ public partial class Contacts {
private static async Task OnRemoveDublicates() { private static async Task OnRemoveDublicates() {
int i = await GenericController.RemoveDublicatesAsync<Contact>(); int i = await GenericController.RemoveDublicatesAsync<Contact>();
Console.WriteLine($"Removed {i} dublicates from Contacts."); Console.WriteLine(i > 0 ? $"Removed {i} dublicates from Contacts." : "No dublicated contacts found.");
}
private static async Task OnRemoveBounced() {
IList<Contact>? bouncedContacts = await GenericController.GetAllAsync<Contact>(c => c.EMail.Contains("bounced") || c.EmailBounced);
if (bouncedContacts is not null && bouncedContacts.Count > 0) {
int i = await GenericController.RemoveAsync(bouncedContacts);
Console.WriteLine($"Removed {i} bounced contacts.");
}
else {
Console.WriteLine("Found no bounced contacts.");
}
} }
} }

@ -206,6 +206,17 @@ public class GenericController {
return 0; return 0;
} }
} }
public static async Task<int> RemoveAsync<T>(IList<T> entities) where T : class, IMetadata {
try {
await Task.Run(() => gremlinDb.Set<T>().RemoveRange(entities));
return await gremlinDb.SaveChangesAsync();
}
catch (Exception exception) {
Console.WriteLine(exception.InnerException);
return 0;
}
}
private static void HandleConcurrencyExceptions(DbUpdateException ex) { private static void HandleConcurrencyExceptions(DbUpdateException ex) {
Console.WriteLine($"!!! HandleConcurrencyException: {ex.Message}"); Console.WriteLine($"!!! HandleConcurrencyException: {ex.Message}");
@ -231,7 +242,6 @@ public class GenericController {
} }
} }
public static async Task<int> RemoveDublicatesAsync<T>() where T : class, IMetadata { public static async Task<int> RemoveDublicatesAsync<T>() where T : class, IMetadata {
try { try {
List<T> entities = gremlinDb.Set<T>().AsEnumerable().GroupBy(e => new { e.HashCode}).SelectMany(grp => grp.Skip(1)).ToList(); List<T> entities = gremlinDb.Set<T>().AsEnumerable().GroupBy(e => new { e.HashCode}).SelectMany(grp => grp.Skip(1)).ToList();