Update of db possible via db refresh just before update

pull/1/head
Sascha Woitschetzki 2023-07-21 18:05:06 +07:00
parent d9a0044703
commit b825891225
6 changed files with 22 additions and 13 deletions

@ -65,6 +65,8 @@
<NumericEdit TValue="uint" Value="Convert.ToUInt32(context.CellValue)" ValueChanged="v => context.CellValue = v"/>
</EditTemplate>
</DataGridColumn>
<DataGridColumn Field="@nameof(Account.DataModificationDate)" Caption="DataModificationDate" Filterable Sortable/>
</DataGridColumns>
<ButtonRowTemplate>

@ -12,7 +12,7 @@ namespace Gremlin_BlazorServer.Pages;
public partial class Accounts {
private readonly IList<Account> accounts = new List<Account>();
private Account? selectedAccount;
public static int ImportProgress { get; set; }
private static int ImportProgress { get; set; }
[CascadingParameter] private Task<AuthenticationState>? AuthenticationStateTask { get; set; }

@ -75,7 +75,7 @@
</EditTemplate>
</DataGridColumn>
<DataGridColumn Field="@nameof(Contact.DataModificationDate)" Caption="DataModificationDate" Filterable Sortable/>
</DataGridColumns>
<ButtonRowTemplate>

@ -295,9 +295,7 @@ public partial class QuoteAdd {
return lineItems;
}
private static void OnPriceSurferFileWritten(FileWrittenEventArgs e) {
Console.WriteLine($"File: {e.File.Name} Position: {e.Position} Data: {Convert.ToBase64String(e.Data)}");
}
private static void OnPriceSurferFileWritten(FileWrittenEventArgs e) => Console.WriteLine($"File: {e.File.Name} Position: {e.Position} Data: {Convert.ToBase64String(e.Data)}");
private static void OnPriceSurferFileProgressed(FileProgressedEventArgs e) {
Console.WriteLine($"File: {e.File.Name} Progress: {e.Percentage}");

@ -126,6 +126,7 @@ public class GenericController {
}
public static async Task<int> InsertAsync<T>(T entity) where T : class, IMetadata {
await gremlinDb.Set<T>().ToListAsync(); //Get newest versions fresh from db
try {
gremlinDb.Set<T>().Add(entity);
return await gremlinDb.SaveChangesAsync();
@ -142,6 +143,7 @@ public class GenericController {
}
public static async Task<int> InsertAsync<T>(IEnumerable<T> entities) where T : class, IMetadata {
await gremlinDb.Set<T>().ToListAsync(); //Get newest versions fresh from db
try {
gremlinDb.Set<T>().AddRange(entities);
return await gremlinDb.SaveChangesAsync();
@ -167,6 +169,7 @@ public class GenericController {
}
public static async Task<int> UpdateAsync<T>(T entity) where T : class, IMetadata {
await gremlinDb.Set<T>().FirstOrDefaultAsync(t => t.Equals(entity)); //Get newest version fresh from db
try {
gremlinDb.Set<T>().Update(entity);
return await gremlinDb.SaveChangesAsync(false);
@ -182,6 +185,8 @@ public class GenericController {
}
public static async Task<int> UpdateAsync<T>(IEnumerable<T> entities) where T : class, IMetadata {
await gremlinDb.Set<T>().Where(t => t.Equals(entities)).ToListAsync(); //Get newest version fresh from db
try {
await Task.Run(() => gremlinDb.Set<T>().UpdateRange(entities));
return await gremlinDb.SaveChangesAsync();
@ -208,7 +213,8 @@ public class GenericController {
}
private static void HandleConcurrencyExceptions(DbUpdateException ex) {
foreach (EntityEntry entry in ex.Entries)
Console.WriteLine($"!!! HandleConcurrencyException: {ex.Message}");
foreach (EntityEntry entry in ex.Entries) {
switch (entry.Entity) {
case Quote or CustomDescription or Account or Contact: {
PropertyValues proposedValues = entry.CurrentValues;
@ -228,5 +234,6 @@ public class GenericController {
default:
throw new NotSupportedException("Don't know how to handle concurrency conflicts for " + entry.Metadata.Name);
}
}
}
}

@ -59,11 +59,11 @@ public class GenericImporter {
AccountTypeCode = accountTypeCode,
SubMarketCode = subMarketCode
};
Account? existingAccount = GenericController.Get<Account>(a => a.SapAccountNumber == sapAccountNumber
|| a.AccountName == readAccount.AccountName);
if (await GenericController.IsExistingAsync<Account>(a => a.SapAccountNumber == sapAccountNumber)) {
// Console.WriteLine($"Account {readAccount.AccountName} existiert bereits. Prüfe auf Updates...");
Account? existingAccount = GenericController.Get<Account>(a => a.SapAccountNumber == sapAccountNumber);
if (existingAccount is null) return null;
if (existingAccount is not null) {
if (IsEqualAccount(readAccount, existingAccount)) return null;
existingAccount.DataModificationDate = DateTime.Now;
existingAccount.DataVersionNumber++;
@ -109,14 +109,16 @@ public class GenericImporter {
DataModificationByUser = "Gremlin Generic Importer",
Gender = 0
};
Contact? existingContact = GenericController.Get<Contact>(a => a.SapContactNumber == sapContactNumber
|| (a.LastName == readContact.LastName && a.FirstName == readContact.FirstName));
if (existingContact is not null) {
if (await GenericController.IsExistingAsync<Contact>(a => a.SapContactNumber == sapContactNumber)) {
Contact? existingContact = GenericController.Get<Contact>(a => a.SapContactNumber == sapContactNumber);
if (existingContact is null) return null;
if (IsEqualContact(readContact, existingContact)) {
Console.WriteLine($"---> The contact {readContact.SapContactNumber}:{readContact.FirstName} {readContact.LastName} ist aktuell.");
return null;
}
existingContact.DataModificationDate = DateTime.Now;
existingContact.DataVersionNumber++;
existingContact.DataModificationByUser = "Updated by Gremlin Generic Importer";