try to save to db

pull/1/head
Sascha 2023-02-23 23:38:25 +07:00
parent 84dbcbb1d1
commit ab5ab399b0
6 changed files with 104 additions and 65 deletions

@ -1,41 +1,30 @@
{ {
// Use IntelliSense to learn about possible attributes. // Verwendet IntelliSense zum Ermitteln möglicher Attribute.
// Hover to view descriptions of existing attributes. // Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": ".NET Core Launch (console)", "name": ".NET Core Launch (web)",
"type": "coreclr", "type": "coreclr",
"request": "launch",
"WARNING01": "*********************************************************************************",
"WARNING02": "The C# extension was unable to automatically decode projects in the current",
"WARNING03": "workspace to create a runnable launch.json file. A template launch.json file has",
"WARNING04": "been created as a placeholder.",
"WARNING05": "",
"WARNING06": "If OmniSharp is currently unable to load your project, you can attempt to resolve",
"WARNING07": "this by restoring any missing project dependencies (example: run 'dotnet restore')",
"WARNING08": "and by fixing any reported errors from building the projects in your workspace.",
"WARNING09": "If this allows OmniSharp to now load your project then --",
"WARNING10": " * Delete this file",
"WARNING11": " * Open the Visual Studio Code command palette (View->Command Palette)",
"WARNING12": " * run the command: '.NET: Generate Assets for Build and Debug'.",
"WARNING13": "",
"WARNING14": "If your project requires a more complex launch configuration, you may wish to delete",
"WARNING15": "this configuration and pick a different template using the 'Add Configuration...'",
"WARNING16": "button at the bottom of this file.",
"WARNING17": "*********************************************************************************",
"preLaunchTask": "build", "preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll", "request": "launch",
"program": "${workspaceFolder}/bin/Debug/net7.0/Gremlin_BlazorServer",
"args": [], "args": [],
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"console": "internalConsole", "stopAtEntry": false,
"stopAtEntry": false "requireExactSource": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
}, },
{ "env": {
"name": ".NET Core Attach", "ASPNETCORE_ENVIRONMENT": "Development",
"type": "coreclr", "ASPNETCORE_URLS": "https://localhost:5000"
"request": "attach" },
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
} }
] ]
} }

24
.vscode/tasks.json vendored

@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}

@ -10,24 +10,24 @@ public class Account : IMetadata
//foreign keys: //foreign keys:
public IList<Contact>? Contacts { get; set; } public IList<Contact>? Contacts { get; set; }
public uint ParentAccountId { get; set; } public uint ParentAccountId { get; set; } = 0;
public AccountType? AccountType { get; set; } public AccountType? AccountType { get; set; }
public SubMarket? SubMarket { get; set; } public SubMarket? SubMarket { get; set; }
public IList<CustomDescription>? CustomDescriptions { get; set; } public IList<CustomDescription>? CustomDescriptions { get; set; }
//class properties: //class properties:
[Required] public string? AccountName { get; set; } [Required] public string? AccountName { get; set; }
public string? Notes { get; set; } public string Notes { get; set; } = string.Empty;
[Required] public string? Street { get; set; } [Required] public string? Street { get; set; }
[Required] public uint Zip { get; set; } [Required] public uint Zip { get; set; }
[Required] public string? City { get; set; } [Required] public string? City { get; set; }
public string? FloorOrBuilding { get; set; } public string FloorOrBuilding { get; set; } = string.Empty;
public float Longitude { get; set; } public float Longitude { get; set; }
public float Latitude { get; set; } public float Latitude { get; set; }
public string? PhoneNumber { get; set; } public string PhoneNumber { get; set; } = string.Empty;
public string? FaxNumber { get; set; } public string FaxNumber { get; set; } = string.Empty;
public string? Webpage { get; set; } public string Webpage { get; set; } = string.Empty;
public string? EMail { get; set; } public string EMail { get; set; } = string.Empty;
//Agilent-specific Properties: //Agilent-specific Properties:
public uint SapAccountNumber { get; set; } public uint SapAccountNumber { get; set; }
@ -40,7 +40,7 @@ public class Account : IMetadata
public DateTime DataValidUntil { get; set; } = DateTime.MaxValue; public DateTime DataValidUntil { get; set; } = DateTime.MaxValue;
public string DataModificationByUser { get; set; } = "Gremlin_BlazorServer"; public string DataModificationByUser { get; set; } = "Gremlin_BlazorServer";
public uint DataVersionNumber { get; set; } public uint DataVersionNumber { get; set; }
public string? DataVersionComment { get; set; } public string? DataVersionComment { get; set; } = string.Empty;
public string DataStatus { get; set; } = "Active"; public string DataStatus { get; set; } = "Active";
//IBase //IBase

@ -121,12 +121,9 @@
{ {
Console.WriteLine(exception.Message); Console.WriteLine(exception.Message);
} }
finally
{
Console.WriteLine("Account import successfull"); Console.WriteLine("Account import successfull");
isImportingAccounts = false; isImportingAccounts = false;
StateHasChanged(); StateHasChanged();
}
return; return;
} }

@ -37,15 +37,38 @@ public class GenericController {
return gremlinDb.Set<TResult>().AsEnumerable().Last(); return gremlinDb.Set<TResult>().AsEnumerable().Last();
} }
public bool Insert<T>(T entity) where T : class, IMetadata { public bool Insert<T>(T entity) where T : class, IMetadata
{
try
{
gremlinDb.Set<T>().Add(entity); gremlinDb.Set<T>().Add(entity);
if (typeof(T) == typeof(Account))
{
Account account = entity as Account;
System.Console.WriteLine($"Added {account.SapAccountNumber}:{account.AccountName} to database, try to save...");
}
return gremlinDb.SaveChanges() > 0; return gremlinDb.SaveChanges() > 0;
} }
catch (Exception exception)
{
Console.WriteLine(exception.InnerException);
return false;
}
}
public bool Insert<T>(List<T> entities) where T : class, IMetadata public bool Insert<T>(List<T> entities) where T : class, IMetadata
{
try
{ {
gremlinDb.Set<T>().AddRange(entities); gremlinDb.Set<T>().AddRange(entities);
return gremlinDb.SaveChanges() > 0; return gremlinDb.SaveChanges() > 0;
} }
catch (Exception exception)
{
Console.WriteLine(exception.InnerException);
return false;
}
}
public bool IsExisting<T>(Predicate<T> search) where T : class, IMetadata public bool IsExisting<T>(Predicate<T> search) where T : class, IMetadata
{ {

@ -12,7 +12,13 @@ namespace Gremlin_BlazorServer.Services
if (typeof(T) == typeof(Account)) if (typeof(T) == typeof(Account))
{ {
List<Account>listOfAccounts = await Task.Run(() => ParseListToAccounts(splitLines)); List<Account>listOfAccounts = await Task.Run(() => ParseListToAccounts(splitLines));
return genericController.Insert(listOfAccounts); // return genericController.Insert(listOfAccounts);
foreach (Account account in listOfAccounts)
{
Console.Write($"Try to add {account.SapAccountNumber}:{account.AccountName} to database?");
string readLine = Console.ReadLine();
if (readLine == "y") genericController.Insert(account);
}
} }
return false; return false;
@ -28,7 +34,6 @@ namespace Gremlin_BlazorServer.Services
select clipboardLine.Split(';') select clipboardLine.Split(';')
).ToList(); ).ToList();
return fileList; return fileList;
} }
@ -52,19 +57,20 @@ namespace Gremlin_BlazorServer.Services
Street = line[2], Street = line[2],
City = line[3], City = line[3],
Zip = zip, Zip = zip,
//TODO: AccountTypeCode
AccountType = genericController.Get<AccountType>(aT => aT.AccountTypeCode == line[6]), AccountType = genericController.Get<AccountType>(aT => aT.AccountTypeCode == line[6]),
//TODO: SubMarketCode SubMarket = genericController.Get<SubMarket>(sM => sM.SubMarketCode == line[7]),
SubMarket = genericController.Get<SubMarket>(sM => sM.SubMarketCode == line[7]) ParentAccountId = 0,
DataModificationByUser = "Gremlin Generic Importer"
}; };
if (AccountExists(account)) if (AccountExists(account))
{ {
//TODO: Check for changes //TODO: Check for changes
// Console.WriteLine($"Account {account.SapAccountNumber}:{account.AccountName} already exists...");
} }
else else
{ {
Console.WriteLine($"Found new account {account.AccountName}"); // Console.WriteLine($"Found new account {account.SapAccountNumber}:{account.AccountName}!");
listOfAccounts.Add(account); listOfAccounts.Add(account);
} }
} }