move razor code to seperate razor.cs file

pull/1/head
DJh2o2 2023-03-03 00:12:47 +07:00
parent 2ecff7a5ef
commit cbf4249acf
22 changed files with 716 additions and 733 deletions

@ -13,20 +13,6 @@
</NotFound>
</Router>
</Blazorise.ThemeProvider>
<ModalProvider UseModalStructure Animated Size="ModalSize.Large" />
<ModalProvider UseModalStructure Animated Size="ModalSize.Default" />
</CascadingAuthenticationState>
@code {
private Theme theme = new Theme {
ColorOptions = new ThemeColorOptions {
//Primary = "#343A40", //"#2196f3" Grey
//Secondary = "#A65529",
Dark = "#001529", //Background
Link = "#343A40", //Black
Success = "#e0dfe1", //White
Danger = "#f44336",
// other
},
//IsGradient = true,
};
}

@ -0,0 +1,18 @@
using Blazorise;
namespace Gremlin_BlazorServer;
public partial class App {
private readonly Theme theme = new() {
ColorOptions = new ThemeColorOptions {
//Primary = "#343A40", //"#2196f3" Grey
//Secondary = "#A65529",
Dark = "#001529", //Background
Link = "#343A40", //Black
Success = "#e0dfe1", //White
Danger = "#f44336",
// other
},
//IsGradient = true,
};
}

@ -81,33 +81,3 @@
</NotAuthorized>
</AuthorizeView>
@code {
[CascadingParameter] private Task<AuthenticationState>? authenticationStateTask { get; set; }
IList<AccountType>? accountTypes;
AccountType? selectedAccountType;
protected override async Task OnInitializedAsync()
{
if (authenticationStateTask != null)
{
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true })
{
accountTypes = await genericController.GetAllAsync<AccountType>("Accounts");
}
await base.OnInitializedAsync();
}
}
private async Task OnSelectedAccountTypeChanged(AccountType _selectedAccountType) {
if (_selectedAccountType != null)
{
selectedAccountType = await genericController.GetAsync<AccountType>(aC => aC.AccountTypeCode == _selectedAccountType.AccountTypeCode, "Accounts");
}
}
}

@ -0,0 +1,30 @@
using Gremlin_BlazorServer.Data.EntityClasses;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Claims;
namespace Gremlin_BlazorServer.Pages;
public partial class AccountTypes {
[CascadingParameter]
private Task<AuthenticationState>? authenticationStateTask { get; set; }
private IList<AccountType>? accountTypes;
private AccountType? selectedAccountType;
protected override async Task OnInitializedAsync() {
if (authenticationStateTask != null) {
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
accountTypes = await genericController.GetAllAsync<AccountType>("Accounts");
}
await base.OnInitializedAsync();
}
}
private async Task OnSelectedAccountTypeChanged(AccountType _selectedAccountType) {
if (_selectedAccountType != null) {
selectedAccountType = await genericController.GetAsync<AccountType>(aC => aC.AccountTypeCode == _selectedAccountType.AccountTypeCode, "Accounts");
}
}
}

@ -148,78 +148,3 @@
</NotAuthorized>
</AuthorizeView>
@code {
[CascadingParameter]
private Task<AuthenticationState>? authenticationStateTask { get; set; }
private IList<Account>? accounts;
private Account? selectedAccount;
protected override async Task OnInitializedAsync() {
if (authenticationStateTask != null) {
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is {IsAuthenticated: true }) {
accounts = await genericController.GetAllAsync<Account>("AccountType","SubMarket");
}
await base.OnInitializedAsync();
}
}
private void OnSelectedAccountChanged(Account _selectedAccount) {
selectedAccount = _selectedAccount;
selectedAccount.Contacts = genericController.GetAll<Contact>(c => c.AccountId == selectedAccount.AccountId);
}
private async Task OnImportAccounts(FileChangedEventArgs fileChangedEventArgs) {
try
{
foreach (IFileEntry? file in fileChangedEventArgs.Files)
{
using MemoryStream stream = new();
await file.WriteToStreamAsync(stream);
stream.Seek(0, SeekOrigin.Begin);
using StreamReader reader = new(stream);
string fileContent = await reader.ReadToEndAsync();
_ = await genericImporter.ImportCsvAsync<Account>(fileContent);
}
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
StateHasChanged();
return;
}
private async Task OnRowInsertedAsync(SavedRowItem<Account, Dictionary<string, object>> account) {
Account newAccount = await ResolveAccountAsync(account.Item);
if (newAccount.AccountType == null || newAccount.SubMarket == null) return;
int count = await genericController.InsertAsync(newAccount);
Console.WriteLine($"Inserted {count} properties for new account {newAccount.AccountId}: {newAccount.AccountName}.");
}
private async Task OnRowUpdatedAsync(SavedRowItem<Account, Dictionary<string, object>> account) {
Account newAccount = await ResolveAccountAsync(account.Item);
if (newAccount.AccountType == null || newAccount.SubMarket == null) return;
int count = await genericController.UpdateAsync(account.Item);
Console.WriteLine($"Updated {count} properties in account {newAccount.AccountId}: {newAccount.AccountName}.");
}
private async Task OnRowRemovedAsync(Account account) {
int count = await genericController.RemoveAsync(account);
Console.WriteLine($"Removed {count} properties and account {account.AccountId}: {account.AccountName}.");
}
private async Task<Account> ResolveAccountAsync(Account newAccount) {
newAccount.DataModificationByUser = "Gremlin Blazor Server GUI";
newAccount.DataVersionNumber++;
newAccount.AccountType = await genericController.GetAsync<AccountType>(aT => aT.AccountTypeCode.Equals("SUP"));
newAccount.SubMarket = await genericController.GetAsync<SubMarket>(sM => sM.SubMarketCode.Equals("VEN"));
return newAccount;
}
}

@ -0,0 +1,79 @@
using Blazorise;
using Blazorise.DataGrid;
using Gremlin_BlazorServer.Data.EntityClasses;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Claims;
namespace Gremlin_BlazorServer.Pages;
public partial class Accounts {
[CascadingParameter]
private Task<AuthenticationState>? authenticationStateTask { get; set; }
private IList<Account>? accounts;
private Account? selectedAccount;
protected override async Task OnInitializedAsync() {
if (authenticationStateTask != null) {
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
accounts = await genericController.GetAllAsync<Account>("AccountType", "SubMarket");
}
await base.OnInitializedAsync();
}
}
private void OnSelectedAccountChanged(Account _selectedAccount) {
selectedAccount = _selectedAccount;
selectedAccount.Contacts = genericController.GetAll<Contact>(c => c.AccountId == selectedAccount.AccountId);
}
private async Task OnImportAccounts(FileChangedEventArgs fileChangedEventArgs) {
try {
foreach (IFileEntry? file in fileChangedEventArgs.Files) {
using MemoryStream stream = new();
await file.WriteToStreamAsync(stream);
_ = stream.Seek(0, SeekOrigin.Begin);
using StreamReader reader = new(stream);
string fileContent = await reader.ReadToEndAsync();
_ = await genericImporter.ImportCsvAsync<Account>(fileContent);
}
}
catch (Exception exception) {
Console.WriteLine(exception.Message);
}
StateHasChanged();
return;
}
private async Task OnRowInsertedAsync(SavedRowItem<Account, Dictionary<string, object>> account) {
Account newAccount = await ResolveAccountAsync(account.Item);
if (newAccount.AccountType == null || newAccount.SubMarket == null)
return;
int count = await genericController.InsertAsync(newAccount);
Console.WriteLine($"Inserted {count} properties for new account {newAccount.AccountId}: {newAccount.AccountName}.");
}
private async Task OnRowUpdatedAsync(SavedRowItem<Account, Dictionary<string, object>> account) {
Account newAccount = await ResolveAccountAsync(account.Item);
if (newAccount.AccountType == null || newAccount.SubMarket == null)
return;
int count = await genericController.UpdateAsync(account.Item);
Console.WriteLine($"Updated {count} properties in account {newAccount.AccountId}: {newAccount.AccountName}.");
}
private async Task OnRowRemovedAsync(Account account) {
int count = await genericController.RemoveAsync(account);
Console.WriteLine($"Removed {count} properties and account {account.AccountId}: {account.AccountName}.");
}
private async Task<Account> ResolveAccountAsync(Account newAccount) {
newAccount.DataModificationByUser = "Gremlin Blazor Server GUI";
newAccount.DataVersionNumber++;
newAccount.AccountType = await genericController.GetAsync<AccountType>(aT => aT.AccountTypeCode.Equals("SUP"));
newAccount.SubMarket = await genericController.GetAsync<SubMarket>(sM => sM.SubMarketCode.Equals("VEN"));
return newAccount;
}
}

@ -165,98 +165,3 @@
</AuthorizeView>
@code {
[CascadingParameter]
private Task<AuthenticationState>? authenticationStateTask { get; set; }
private IList<Contact>? contacts;
private Contact? selectedContact;
private List<Contact>? selectedContacts;
private Quote? selectedQuote;
private readonly CultureInfo cultureInfo = new("de-DE");
private int totalContacts;
protected override async Task OnInitializedAsync() {
if (authenticationStateTask != null) {
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
contacts = await genericController.GetAllAsync<Contact>();
}
}
await base.OnInitializedAsync();
}
private async Task OnSelectedContactChanged(Contact _selectedContact) {
if (_selectedContact != null)
{
selectedContact = _selectedContact;
selectedContact.Quotes = await genericController.GetAllAsync<Quote>(q => q.ContactId.Equals(selectedContact.ContactId));
}
return;
}
private async Task OnSelectedQuoteChanged(Quote _selectedQuote) {
if (_selectedQuote != null)
{
selectedQuote = _selectedQuote;
selectedQuote.LineItems = await genericController.GetAllAsync<LineItem>(lI => lI.QuoteId.Equals(selectedQuote.QuoteId));
}
return;
}
private async Task OnRowInsertedAsync(SavedRowItem<Contact, Dictionary<string, object>> contact) {
Contact newContact = await ResolveContactAsync(contact.Item);
if (newContact.Account == null) return;
int count = await genericController.InsertAsync(newContact);
Console.WriteLine($"Inserted {count} properties for new contact {newContact.ContactId}: {newContact.FirstName} {newContact.LastName}.");
}
private async Task OnRowUpdatedAsync(SavedRowItem<Contact, Dictionary<string, object>> contact) {
Contact newContact = await ResolveContactAsync(contact.Item);
if (newContact.Account == null) return;
int count = await genericController.UpdateAsync(contact.Item);
Console.WriteLine($"Updated {count} properties in contact {newContact.ContactId}: {newContact.FirstName} {newContact.LastName}.");
}
private async Task OnRowRemovedAsync(Contact contact) {
int count = await genericController.RemoveAsync(contact);
Console.WriteLine($"Removed {count} properties and contact {contact.ContactId}: {contact.FirstName} {contact.LastName}.");
}
private async Task<Contact> ResolveContactAsync(Contact newContact) {
newContact.Account = await genericController.GetAsync<Account>(a => a.AccountId.Equals(newContact.AccountId));
if (newContact.Account != null) {
newContact.NoPhoneCalls = false;
newContact.EmailBounced = false;
newContact.NoHardcopyMailing = false;
newContact.ValidatedContact = true;
newContact.DataModificationByUser = "Gremlin Blazor Server GUI";
newContact.DataVersionNumber++;
}
else {
Console.WriteLine($"No account with AccountId {newContact.AccountId} found!");
}
return newContact;
}
private async Task OnImportContacts(FileChangedEventArgs fileChangedEventArgs) {
try {
foreach (IFileEntry? file in fileChangedEventArgs.Files) {
using MemoryStream stream = new();
await file.WriteToStreamAsync(stream);
stream.Seek(0, SeekOrigin.Begin);
using StreamReader reader = new(stream);
string fileContent = await reader.ReadToEndAsync();
await genericImporter.ImportCsvAsync<Account>(fileContent);
}
}
catch (Exception exception) {
Console.WriteLine(exception.Message);
}
StateHasChanged();
return;
}
}

@ -0,0 +1,106 @@
using Blazorise;
using Blazorise.DataGrid;
using Gremlin_BlazorServer.Data.EntityClasses;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using System.Globalization;
using System.Security.Claims;
namespace Gremlin_BlazorServer.Pages;
public partial class Contacts {
[CascadingParameter]
private Task<AuthenticationState>? authenticationStateTask { get; set; }
private IList<Contact>? contacts;
private Contact? selectedContact;
private readonly List<Contact>? selectedContacts;
private Quote? selectedQuote;
private readonly CultureInfo cultureInfo = new("de-DE");
private readonly int totalContacts;
protected override async Task OnInitializedAsync() {
if (authenticationStateTask != null) {
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
contacts = await genericController.GetAllAsync<Contact>();
}
}
await base.OnInitializedAsync();
}
private async Task OnSelectedContactChanged(Contact _selectedContact) {
if (_selectedContact != null) {
selectedContact = _selectedContact;
selectedContact.Quotes = await genericController.GetAllAsync<Quote>(q => q.ContactId.Equals(selectedContact.ContactId));
}
return;
}
private async Task OnSelectedQuoteChanged(Quote _selectedQuote) {
if (_selectedQuote != null) {
selectedQuote = _selectedQuote;
selectedQuote.LineItems = await genericController.GetAllAsync<LineItem>(lI => lI.QuoteId.Equals(selectedQuote.QuoteId));
}
return;
}
private async Task OnRowInsertedAsync(SavedRowItem<Contact, Dictionary<string, object>> contact) {
Contact newContact = await ResolveContactAsync(contact.Item);
if (newContact.Account == null)
return;
int count = await genericController.InsertAsync(newContact);
Console.WriteLine($"Inserted {count} properties for new contact {newContact.ContactId}: {newContact.FirstName} {newContact.LastName}.");
}
private async Task OnRowUpdatedAsync(SavedRowItem<Contact, Dictionary<string, object>> contact) {
Contact newContact = await ResolveContactAsync(contact.Item);
if (newContact.Account == null)
return;
int count = await genericController.UpdateAsync(contact.Item);
Console.WriteLine($"Updated {count} properties in contact {newContact.ContactId}: {newContact.FirstName} {newContact.LastName}.");
}
private async Task OnRowRemovedAsync(Contact contact) {
int count = await genericController.RemoveAsync(contact);
Console.WriteLine($"Removed {count} properties and contact {contact.ContactId}: {contact.FirstName} {contact.LastName}.");
}
private async Task<Contact> ResolveContactAsync(Contact newContact) {
newContact.Account = await genericController.GetAsync<Account>(a => a.AccountId.Equals(newContact.AccountId));
if (newContact.Account != null) {
newContact.NoPhoneCalls = false;
newContact.EmailBounced = false;
newContact.NoHardcopyMailing = false;
newContact.ValidatedContact = true;
newContact.DataModificationByUser = "Gremlin Blazor Server GUI";
newContact.DataVersionNumber++;
}
else {
Console.WriteLine($"No account with AccountId {newContact.AccountId} found!");
}
return newContact;
}
private async Task OnImportContacts(FileChangedEventArgs fileChangedEventArgs) {
try {
foreach (IFileEntry? file in fileChangedEventArgs.Files) {
using MemoryStream stream = new();
await file.WriteToStreamAsync(stream);
_ = stream.Seek(0, SeekOrigin.Begin);
using StreamReader reader = new(stream);
string fileContent = await reader.ReadToEndAsync();
_ = await genericImporter.ImportCsvAsync<Account>(fileContent);
}
}
catch (Exception exception) {
Console.WriteLine(exception.Message);
}
StateHasChanged();
return;
}
}

@ -4,6 +4,26 @@
<CloseButton />
</ModalHeader>
<ModalBody>
@if (suggestedCustomDescriptions.Count > 0)
{
<DataGrid TItem="CustomDescription"
Data="@suggestedCustomDescriptions"
SelectedRow="@selectedSuggestedCustomDescription"
SelectedRowChanged="@OnSelectedSuggestedCustomDescription"
Bordered Hoverable Striped ShowPager Responsive>
<DataGridCommandColumn />
<DataGridColumn Field="@nameof(CustomDescription.ProductNumber)" Caption="ProductNumber" />
<DataGridColumn Field="@nameof(CustomDescription.OptionNumber)" Caption="OptionNumber" />
<DataGridColumn Field="@nameof(CustomDescription.Heading)" Caption="Heading" />
<DataGridColumn Field="@nameof(CustomDescription.CoverletterText)" Caption="CoverletterText" />
<DataGridColumn Field="@nameof(CustomDescription.DescriptionText)" Caption="DescriptionText" />
</DataGrid>
}
else {
<Paragraph>No suggestions available.</Paragraph>
}
<Field>
<FieldLabel>ProductNumber</FieldLabel>
<FieldBody>@customDescription.ProductNumber</FieldBody>
@ -28,12 +48,3 @@
<ModalFooter>
<Button Color="Color.Success" Clicked="OnSave">Save</Button>
</ModalFooter>
@code {
[Inject] public IModalService modalService { get; set; }
[Parameter] public CustomDescription customDescription { get; set; }
private async Task OnSave() {
await modalService.Hide();
}
}

@ -0,0 +1,25 @@
using Blazorise;
using Gremlin_BlazorServer.Data.EntityClasses;
using Microsoft.AspNetCore.Components;
namespace Gremlin_BlazorServer.Pages {
public partial class CustomDescriptionModal {
[Inject] public IModalService modalService { get; set; }
[Parameter] public CustomDescription customDescription { get; set; }
[Parameter] public List<CustomDescription> suggestedCustomDescriptions { get; set; }
private CustomDescription? selectedSuggestedCustomDescription;
private async Task OnSave() {
await modalService.Hide();
}
private void OnSelectedSuggestedCustomDescription(CustomDescription _selectedSuggestedCustomDescriptions) {
selectedSuggestedCustomDescription = _selectedSuggestedCustomDescriptions;
customDescription.Heading = selectedSuggestedCustomDescription.Heading;
customDescription.CoverletterText = selectedSuggestedCustomDescription.CoverletterText;
customDescription.DescriptionText = selectedSuggestedCustomDescription.DescriptionText;
}
}
}

@ -95,73 +95,3 @@
</NotAuthorized>
</AuthorizeView>
@code {
[CascadingParameter]
private Task<AuthenticationState>? AuthenticationStateTask { get; set; }
private IList<CustomDescription>? customDescriptions;
private CustomDescription? selectedCustomDescription;
protected override async Task OnInitializedAsync() {
if (AuthenticationStateTask != null) {
ClaimsPrincipal user = (await AuthenticationStateTask).User;
if (user.Identity is {IsAuthenticated: true }) {
customDescriptions = genericController.GetAll<CustomDescription>("Supplier");
}
await base.OnInitializedAsync();
}
}
private void OnSelectedCustomDescriptionChanged(CustomDescription _selectedCustomDescription) {
selectedCustomDescription = _selectedCustomDescription;
}
private async Task OnImportCustomDescriptions(FileChangedEventArgs fileChangedEventArgs) {
try {
foreach (IFileEntry? file in fileChangedEventArgs.Files) {
using MemoryStream stream = new();
await file.WriteToStreamAsync(stream);
stream.Seek(0, SeekOrigin.Begin);
using StreamReader reader = new(stream);
string fileContent = await reader.ReadToEndAsync();
await genericImporter.ImportCsvAsync<CustomDescription>(fileContent);
}
}
catch (Exception exception) {
Console.WriteLine(exception.Message);
}
StateHasChanged();
return;
}
private async Task OnRowInsertedAsync(SavedRowItem<CustomDescription, Dictionary<string, object>> customDescription) {
CustomDescription newCustomDescription = await ResolveCustomDescriptionAsync(customDescription.Item);
if (newCustomDescription.ProductNumber == null || newCustomDescription.OptionNumber == null) return;
int count = await genericController.InsertAsync(newCustomDescription);
Console.WriteLine($"Inserted {count} properties for new custom description {newCustomDescription.ProductNumber}#{newCustomDescription.OptionNumber}: {newCustomDescription.Heading}");
}
private async Task OnRowUpdatedAsync(SavedRowItem<CustomDescription, Dictionary<string, object>> customDescription) {
CustomDescription newCustomDescription = await ResolveCustomDescriptionAsync(customDescription.Item);
if (newCustomDescription.ProductNumber == null || newCustomDescription.OptionNumber == null) return;
int count = await genericController.UpdateAsync(customDescription.Item);
Console.WriteLine($"Updated {count} properties for custom description {newCustomDescription.ProductNumber}#{newCustomDescription.OptionNumber}: {newCustomDescription.Heading}");
}
private async Task OnRowRemovedAsync(CustomDescription customDescription) {
int count = await genericController.RemoveAsync(customDescription);
Console.WriteLine($"Removed {count} properties and custom description {customDescription.ProductNumber}#{customDescription.OptionNumber}: {customDescription.Heading}");
}
private async Task<CustomDescription> ResolveCustomDescriptionAsync(CustomDescription newCustomDescription) {
newCustomDescription.Supplier = await genericController.GetAsync<Account>(a => a.AccountId.Equals(newCustomDescription.AccountId));
newCustomDescription.DataModificationByUser = "Gremlin Blazor Server GUI";
newCustomDescription.DataVersionNumber++;
return newCustomDescription;
}
}

@ -0,0 +1,75 @@
using Blazorise;
using Blazorise.DataGrid;
using Gremlin_BlazorServer.Data.EntityClasses;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Claims;
namespace Gremlin_BlazorServer.Pages;
public partial class CustomDescriptions {
[CascadingParameter]
private Task<AuthenticationState>? AuthenticationStateTask { get; set; }
private IList<CustomDescription>? customDescriptions;
private CustomDescription? selectedCustomDescription;
protected override async Task OnInitializedAsync() {
if (AuthenticationStateTask != null) {
ClaimsPrincipal user = (await AuthenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
customDescriptions = genericController.GetAll<CustomDescription>("Supplier");
}
await base.OnInitializedAsync();
}
}
private void OnSelectedCustomDescriptionChanged(CustomDescription _selectedCustomDescription) => selectedCustomDescription = _selectedCustomDescription;
private async Task OnImportCustomDescriptions(FileChangedEventArgs fileChangedEventArgs) {
try {
foreach (IFileEntry? file in fileChangedEventArgs.Files) {
using MemoryStream stream = new();
await file.WriteToStreamAsync(stream);
_ = stream.Seek(0, SeekOrigin.Begin);
using StreamReader reader = new(stream);
string fileContent = await reader.ReadToEndAsync();
_ = await genericImporter.ImportCsvAsync<CustomDescription>(fileContent);
}
}
catch (Exception exception) {
Console.WriteLine(exception.Message);
}
StateHasChanged();
return;
}
private async Task OnRowInsertedAsync(SavedRowItem<CustomDescription, Dictionary<string, object>> customDescription) {
CustomDescription newCustomDescription = await ResolveCustomDescriptionAsync(customDescription.Item);
if (newCustomDescription.ProductNumber == null || newCustomDescription.OptionNumber == null)
return;
int count = await genericController.InsertAsync(newCustomDescription);
Console.WriteLine($"Inserted {count} properties for new custom description {newCustomDescription.ProductNumber}#{newCustomDescription.OptionNumber}: {newCustomDescription.Heading}");
}
private async Task OnRowUpdatedAsync(SavedRowItem<CustomDescription, Dictionary<string, object>> customDescription) {
CustomDescription newCustomDescription = await ResolveCustomDescriptionAsync(customDescription.Item);
if (newCustomDescription.ProductNumber == null || newCustomDescription.OptionNumber == null)
return;
int count = await genericController.UpdateAsync(customDescription.Item);
Console.WriteLine($"Updated {count} properties for custom description {newCustomDescription.ProductNumber}#{newCustomDescription.OptionNumber}: {newCustomDescription.Heading}");
}
private async Task OnRowRemovedAsync(CustomDescription customDescription) {
int count = await genericController.RemoveAsync(customDescription);
Console.WriteLine($"Removed {count} properties and custom description {customDescription.ProductNumber}#{customDescription.OptionNumber}: {customDescription.Heading}");
}
private async Task<CustomDescription> ResolveCustomDescriptionAsync(CustomDescription newCustomDescription) {
newCustomDescription.Supplier = await genericController.GetAsync<Account>(a => a.AccountId.Equals(newCustomDescription.AccountId));
newCustomDescription.DataModificationByUser = "Gremlin Blazor Server GUI";
newCustomDescription.DataVersionNumber++;
return newCustomDescription;
}
}

@ -48,27 +48,3 @@
</NotAuthorized>
</AuthorizeView>
@code {
[CascadingParameter]
private Task<AuthenticationState>? AuthenticationStateTask { get; set; }
private IList<LineItem>? lineItems;
private LineItem? selectedLineItem;
private readonly CultureInfo cultureInfo = new("de-DE");
protected override async Task OnInitializedAsync() {
if (AuthenticationStateTask != null) {
ClaimsPrincipal user = (await AuthenticationStateTask).User;
if (user.Identity is {IsAuthenticated: true }) {
lineItems = GenericController.GetAll<LineItem>();
}
}
}
private void OnSelectedLineItemChanged(LineItem _selectedLineItem) {
selectedLineItem = _selectedLineItem;
}
}

@ -0,0 +1,27 @@
using Gremlin_BlazorServer.Data.EntityClasses;
using Gremlin_BlazorServer.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using System.Globalization;
using System.Security.Claims;
namespace Gremlin_BlazorServer.Pages;
public partial class LineItems {
[CascadingParameter]
private Task<AuthenticationState>? AuthenticationStateTask { get; set; }
private IList<LineItem>? lineItems;
private LineItem? selectedLineItem;
private readonly CultureInfo cultureInfo = new("de-DE");
protected override async Task OnInitializedAsync() {
if (AuthenticationStateTask != null) {
ClaimsPrincipal user = (await AuthenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
lineItems = GenericController.GetAll<LineItem>();
}
}
}
private void OnSelectedLineItemChanged(LineItem _selectedLineItem) => selectedLineItem = _selectedLineItem;
}

@ -84,60 +84,3 @@
</NotAuthorized>
</AuthorizeView>
@code {
[CascadingParameter] private Task<AuthenticationState>? authenticationStateTask { get; set; }
private IList<ProductLine>? productLines;
private ProductLine? selectedProductLine;
protected override async Task OnParametersSetAsync()
{
if (authenticationStateTask != null)
{
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true })
{
productLines = await genericController.GetAllAsync<ProductLine>();
}
await base.OnInitializedAsync();
}
}
private async Task OnSelectedProductLineChanged(ProductLine _selectedProductLine) {
if (_selectedProductLine != null)
{
await ApplicationLoadingIndicatorService.Show();
selectedProductLine = await genericController.GetAsync<ProductLine>(pL => pL.ProductLineCode == _selectedProductLine.ProductLineCode, "Products");
await ApplicationLoadingIndicatorService.Hide();
}
}
private async Task OnRowInsertedAsync(SavedRowItem<ProductLine, Dictionary<string, object>> productLine) {
ProductLine newProductLine = await ResolveProductAsync(productLine.Item);
if (newProductLine.ProductLineCode == null) return;
int count = await genericController.InsertAsync(newProductLine);
Console.WriteLine($"Inserted {count} properties for new ProductLine {newProductLine.ProductLineCode}.");
}
private async Task OnRowUpdatedAsync(SavedRowItem<ProductLine, Dictionary<string, object>> productLine) {
ProductLine newProductLine = await ResolveProductAsync(productLine.Item);
if (newProductLine.ProductLineCode == null) return;
int count = await genericController.UpdateAsync(productLine.Item);
Console.WriteLine($"Updated {count} properties in ProductLine {newProductLine.ProductLineCode}.");
}
private async Task OnRowRemovedAsync(ProductLine productLine) {
int count = await genericController.RemoveAsync(productLine);
Console.WriteLine($"Removed {count} properties and ProductLine {productLine.ProductLineCode}.");
}
private async Task<ProductLine> ResolveProductAsync(ProductLine newProductLine) {
newProductLine.DataModificationByUser = "Gremlin Blazor Server GUI";
newProductLine.DataVersionNumber++;
newProductLine.Products = await genericController.GetAllAsync<Product>(p => p.ProductLineCode == newProductLine.ProductLineCode);
return newProductLine;
}
}

@ -0,0 +1,61 @@
using Blazorise.DataGrid;
using Gremlin_BlazorServer.Data.EntityClasses;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Claims;
namespace Gremlin_BlazorServer.Pages;
public partial class ProductLines {
[CascadingParameter]
private Task<AuthenticationState>? authenticationStateTask { get; set; }
private IList<ProductLine>? productLines;
private ProductLine? selectedProductLine;
protected override async Task OnParametersSetAsync() {
if (authenticationStateTask != null) {
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
productLines = await genericController.GetAllAsync<ProductLine>();
}
await base.OnInitializedAsync();
}
}
private async Task OnSelectedProductLineChanged(ProductLine _selectedProductLine) {
if (_selectedProductLine != null) {
await ApplicationLoadingIndicatorService.Show();
selectedProductLine = await genericController.GetAsync<ProductLine>(pL => pL.ProductLineCode == _selectedProductLine.ProductLineCode, "Products");
await ApplicationLoadingIndicatorService.Hide();
}
}
private async Task OnRowInsertedAsync(SavedRowItem<ProductLine, Dictionary<string, object>> productLine) {
ProductLine newProductLine = await ResolveProductAsync(productLine.Item);
if (newProductLine.ProductLineCode == null)
return;
int count = await genericController.InsertAsync(newProductLine);
Console.WriteLine($"Inserted {count} properties for new ProductLine {newProductLine.ProductLineCode}.");
}
private async Task OnRowUpdatedAsync(SavedRowItem<ProductLine, Dictionary<string, object>> productLine) {
ProductLine newProductLine = await ResolveProductAsync(productLine.Item);
if (newProductLine.ProductLineCode == null)
return;
int count = await genericController.UpdateAsync(productLine.Item);
Console.WriteLine($"Updated {count} properties in ProductLine {newProductLine.ProductLineCode}.");
}
private async Task OnRowRemovedAsync(ProductLine productLine) {
int count = await genericController.RemoveAsync(productLine);
Console.WriteLine($"Removed {count} properties and ProductLine {productLine.ProductLineCode}.");
}
private async Task<ProductLine> ResolveProductAsync(ProductLine newProductLine) {
newProductLine.DataModificationByUser = "Gremlin Blazor Server GUI";
newProductLine.DataVersionNumber++;
newProductLine.Products = await genericController.GetAllAsync<Product>(p => p.ProductLineCode == newProductLine.ProductLineCode);
return newProductLine;
}
}

@ -115,37 +115,3 @@
</NotAuthorized>
</AuthorizeView>
@code {
[CascadingParameter] private Task<AuthenticationState>? authenticationStateTask { get; set; }
IList<Product>? products;
Product? selectedProduct;
protected override async Task OnInitializedAsync()
{
if (authenticationStateTask != null)
{
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true })
{
await ApplicationLoadingIndicatorService.Show();
products = await genericController.GetAllAsync<Product>();
await ApplicationLoadingIndicatorService.Hide();
}
await base.OnInitializedAsync();
}
}
private async Task OnSelectedProductChanged(Product _selectedProduct) {
selectedProduct = _selectedProduct;
selectedProduct.CustomDescription =
await genericController.GetAsync<CustomDescription>(
cD => cD.ProductNumber.Equals(selectedProduct.ProductNumber)
&& cD.OptionNumber.Equals(selectedProduct.OptionNumber)
);
}
}

@ -0,0 +1,31 @@
using Gremlin_BlazorServer.Data.EntityClasses;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Claims;
namespace Gremlin_BlazorServer.Pages;
public partial class Products {
[CascadingParameter]
private Task<AuthenticationState>? authenticationStateTask { get; set; }
private IList<Product>? products;
private Product? selectedProduct;
protected override async Task OnInitializedAsync() {
if (authenticationStateTask != null) {
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
await ApplicationLoadingIndicatorService.Show();
products = await genericController.GetAllAsync<Product>();
await ApplicationLoadingIndicatorService.Hide();
}
await base.OnInitializedAsync();
}
}
private async Task OnSelectedProductChanged(Product _selectedProduct) {
selectedProduct = _selectedProduct;
selectedProduct.CustomDescription = await genericController.GetAsync<CustomDescription>(cD => cD.ProductNumber.Equals(selectedProduct.ProductNumber) && cD.OptionNumber.Equals(selectedProduct.OptionNumber));
}
}

@ -181,8 +181,6 @@
<Paragraph>
<DataGrid TItem="LineItem"
Data="@quote.LineItems"
SelectedRow="@selectedLineItem"
SelectedRowChanged="@OnSelectedLineItemChanged"
Bordered Hoverable Striped ShowPager Responsive>
<DataGridCommandColumn/>
<DataGridColumn Field="@nameof(LineItem.Position)" Caption="Position" />
@ -190,44 +188,14 @@
<DataGridColumn Field="@nameof(LineItem.ProductNumber)" Caption="ProductNumber"/>
<DataGridColumn Field="@nameof(LineItem.OptionNumber)" Caption="OptionNumber"/>
<DataGridColumn Field="@nameof(LineItem.SapShortDescription)" Caption="SapShortDescription" />
<DataGridColumn Field="@nameof(LineItem.CustomDescription)" Caption="CustomDescription" />
<DataGridColumn Field="@nameof(LineItem.ListPrice)" DisplayFormat="{0:C}" DisplayFormatProvider=cultureInfo Caption="ListPrice" />
<DataGridColumn Field="@nameof(LineItem.TotalDiscount)" DisplayFormat="{0:n2}%" Caption="TotalDiscount" />
<DataGridColumn Field="@nameof(LineItem.Total)" DisplayFormat="{0:C}" DisplayFormatProvider=cultureInfo Caption="Total"/>
</DataGrid>
</Paragraph>
</Div>
@if (selectedLineItem != null && customDescriptionOfSelectedLineItem != null) {
<Div Margin="Margin.Is3"
Border="Border.Dark.OnAll"
Padding="Padding.Is3"
style="box-shadow: 10px 10px #343A40">
<Heading Size="HeadingSize.Is5">CustomDescription</Heading>
<Paragraph>
<Column ColumnSize="ColumnSize.Is12">
<Field>
<FieldLabel ColumnSize="ColumnSize.Is4">ProductNumber</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is6">@customDescriptionOfSelectedLineItem.ProductNumber</FieldBody>
</Field>
<Field>
<FieldLabel ColumnSize="ColumnSize.Is4">OptionNumber</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is6">@customDescriptionOfSelectedLineItem.OptionNumber</FieldBody>
</Field>
<Field>
<FieldLabel ColumnSize="ColumnSize.Is4">Heading</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is6">@customDescriptionOfSelectedLineItem.Heading</FieldBody>
</Field>
<Field>
<FieldLabel ColumnSize="ColumnSize.Is4">DescriptionText</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is6">@customDescriptionOfSelectedLineItem.DescriptionText</FieldBody>
</Field>
</Column>
</Paragraph>
</Div>
}
}
@if (quote.LineItems == null) {
<Div Margin="Margin.Is3"
@ -301,250 +269,3 @@
</NotAuthorized>
</AuthorizeView>
@code {
[CascadingParameter] private Task<AuthenticationState>? authenticationStateTask { get; set; }
[Inject] public IModalService modalService { get; set; }
private IList<Contact>? contacts;
private Quote quote = new();
private Contact? selectedContact;
private LineItem? selectedLineItem;
private CustomDescription? customDescriptionOfSelectedLineItem;
private readonly CultureInfo cultureInfo = new("de-DE");
private bool pdfNotReady = true;
private bool isCreatingPdf;
private bool texNotReady = true;
private bool isCreatingTex;
private bool lineItemsNotReady = true;
private string? url;
private bool debug;
private bool modalCustomDescriptionVisible;
private CustomDescription? newCustomDescription;
public Task ShowCustomDescriptionModal() {
return modalService.Show<CustomDescriptionModal>(builder => { builder.Add(parameter => parameter.customDescription, newCustomDescription); });
}
protected override async Task OnParametersSetAsync() {
if (authenticationStateTask != null) {
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
await ApplicationLoadingIndicatorService.Show();
contacts = await genericController.GetAllAsync<Contact>();
await ApplicationLoadingIndicatorService.Hide();
quote = await GenerateNewQuote(quote, "Woitschetzki");
}
}
await base.OnInitializedAsync();
}
private async Task<Quote> GenerateNewQuote(Quote _quote, string salesRepLastName) {
if (_quote == null) return new();
_quote.SalesRep = await genericController.GetAsync<Contact>(c => c.LastName.Equals(salesRepLastName), "Account");
Quote? lastQuote = genericController.GetLast<Quote>();
if (lastQuote != null)
{
_quote.QuoteId = lastQuote.QuoteId + 1;
}
else
{
_quote.QuoteId = 1;
}
if (_quote.SalesRep != null) {
_quote.QuotationNumber = _quote.SalesRep.LastName switch
{
"Woitschetzki" => $"DE-83PE89-{DateTime.Now:My}-{_quote.QuoteId}",
"Welsch" => $"DE-83RE32-{DateTime.Now:My}-{_quote.QuoteId}",
_ => $"DE-XXYYXX-{DateTime.Now:My}-{_quote.QuoteId}"
};
}
else {
_quote.QuotationNumber = $"DE-XXYYXX-{DateTime.Now:My}-{_quote.QuoteId}";
}
_quote.Description = "Gerät";
return _quote;
}
private async Task SelectQuoteOnChanged(FileChangedEventArgs e) {
try {
foreach (IFileEntry? file in e.Files) {
using MemoryStream stream = new();
await file.WriteToStreamAsync(stream);
stream.Seek(0, SeekOrigin.Begin);
using StreamReader reader = new(stream);
string fileContent = await reader.ReadToEndAsync();
quote = QuoteHandling.ReadLineItems(quote, fileContent);
if (quote.Recipient?.Account?.AccountName != null)
{
quote = hostingService.SetPath(quote);
}
if (quote.LineItems == null) return;
FileService.WriteQuoteToTsv(fileContent, quote);
//TODO Load all relevant CustomDescriptions upfront
for (int i = 0; i < quote.LineItems.Count(); i++) {
newCustomDescription = await genericController.GetAsync<CustomDescription>(newCustomDescription => newCustomDescription.ProductNumber.Equals(quote.LineItems[i].ProductNumber, StringComparison.Ordinal)
&& newCustomDescription.OptionNumber.Equals(quote.LineItems[i].OptionNumber, StringComparison.Ordinal));
if (newCustomDescription == null) {
Console.WriteLine($"Keine CustomDescription für {quote.LineItems[i].ProductNumber}#{quote.LineItems[i].OptionNumber} verfügbar!");
List<CustomDescription>? suggestedCustomDescriptions = await SuggestCustomDescriptions(quote.LineItems[i]);
//TODO generate new CustomDescription
newCustomDescription = new() {
ProductNumber = quote.LineItems[i].ProductNumber,
OptionNumber = quote.LineItems[i].OptionNumber,
Heading = quote.LineItems[i].SapShortDescription,
CoverletterText = quote.LineItems[i].SapShortDescription,
DescriptionText = quote.LineItems[i].SapLongDescription
};
await ShowCustomDescriptionModal();
}
quote.LineItems[i].CustomDescription = newCustomDescription;
}
}
}
catch (Exception exc) {
Console.WriteLine(exc.Message);
}
finally {
if (quote.Recipient != null) lineItemsNotReady = false;
StateHasChanged();
}
}
private async Task<List<CustomDescription>?> SuggestCustomDescriptions(LineItem lineItem) {
IList<CustomDescription>? fromProductNumber = await genericController.GetAllAsync<CustomDescription>(cD => cD.ProductNumber.Equals(lineItem.ProductNumber, StringComparison.Ordinal));
IList<CustomDescription>? fromOptionNumber = await genericController.GetAllAsync<CustomDescription>(cD => cD.OptionNumber.Equals(lineItem.OptionNumber, StringComparison.Ordinal));
if (fromOptionNumber == null && fromProductNumber == null) return null;
if (fromOptionNumber == null) return fromProductNumber.ToList();
if (fromProductNumber == null) return fromOptionNumber.ToList();
return fromProductNumber.Union(fromOptionNumber).ToList();
}
private static void SelectQuoteOnWritten(FileWrittenEventArgs e) {
Console.WriteLine($"File: {e.File.Name} Position: {e.Position} Data: {Convert.ToBase64String(e.Data)}");
}
private static void SelectQuoteOnProgressed(FileProgressedEventArgs e) {
Console.WriteLine($"File: {e.File.Name} Progress: {e.Percentage}");
}
private async Task OnSelectedContactChanged(Contact _selectedContact) {
selectedContact = _selectedContact;
quote.Recipient = selectedContact;
quote.Recipient.Account = await genericController.GetAsync<Account>(account => account.AccountId.Equals(quote.Recipient.AccountId));
if (quote.LineItems != null) lineItemsNotReady = false;
}
private async Task OnSave() {
if (await genericController.InsertAsync(quote) > 0)
navigationManager.NavigateTo("Quotes/QuoteIndex");
}
private async Task OnCreateTex() {
isCreatingTex = true;
StringBuilder? tex = await QuoteHandling.CreateTexAsync(quote);
if (tex == null) return;
quote.Tex = tex.ToString();
if (quote.Tex == null) return;
await FileService.WriteTexFile(quote);
isCreatingTex = false;
Console.WriteLine("Tex file succesfull created.");
texNotReady = false;
}
private async Task OnCreatePdf()
{
isCreatingPdf = true;
if(await PdfService.CreatePdf(quote))
{
pdfNotReady = false;
isCreatingPdf = false;
Console.WriteLine("PDF successfull written.");
url = HostingService.GetPdfUrl(quote);
Console.WriteLine($"URL to PDF is {url}");
}
}
private void OnOpenPdfApp()
{
PdfService.OpenPdfWithOkular(quote);
}
private async Task OnOpenPdfNewTab() {
await jSRuntime.InvokeVoidAsync("OpenNewTab", $"quotes/{url}");
}
private void OnDescriptionChanged(string description) {
quote.Description = description;
}
private void OnQuotationNumberChanged(string quotationNumber) {
quote.QuotationNumber = quotationNumber;
}
private void OnValidForChanged(string validFor) {
quote.ValidFor = byte.Parse(validFor);
}
private void OnVATChanged(string vat) {
quote.Vat = float.Parse(vat);
}
private void OnIsPriceInformationChanged(bool isPriceInformation) {
quote.IsPriceInformation = isPriceInformation;
}
private void OnShowBruttoChanged(bool onShowBrutto) {
quote.ShowBrutto = onShowBrutto;
}
private void OnShowDiscountsChanged(bool showDiscount) {
quote.ShowDiscounts = showDiscount;
}
private void OnShowSinglePricesChanged(bool showSinglePrices) {
quote.ShowSinglePrices = showSinglePrices;
}
private void OnWarrantyChanged(string warranty) {
quote.Warranty = int.Parse(warranty);
}
private void OnCancel() {
navigationManager.NavigateTo("Quotes/QuoteIndex");
}
private async Task OnSelectedLineItemChanged(LineItem lI) {
selectedLineItem = lI;
customDescriptionOfSelectedLineItem =
await genericController.GetAsync<CustomDescription>(cD => cD.ProductNumber.Equals(lI.ProductNumber) && cD.OptionNumber.Equals(lI.OptionNumber));
}
}

@ -0,0 +1,193 @@
using Blazorise;
using Gremlin_BlazorServer.Data.EntityClasses;
using Gremlin_BlazorServer.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.JSInterop;
using System.Globalization;
using System.Security.Claims;
using System.Text;
namespace Gremlin_BlazorServer.Pages.Quotes;
public partial class QuoteAdd {
[CascadingParameter]
private Task<AuthenticationState>? authenticationStateTask { get; set; }
[Inject]
public IModalService? modalService { get; set; }
private IList<Contact>? contacts;
private Quote quote = new();
private Contact? selectedContact;
private readonly CultureInfo cultureInfo = new("de-DE");
private bool pdfNotReady = true;
private bool isCreatingPdf;
private bool texNotReady = true;
private bool isCreatingTex;
private bool lineItemsNotReady = true;
private string? url;
private readonly bool debug;
private List<CustomDescription>? suggestedCustomDescriptions;
private CustomDescription? newCustomDescription;
public Task ShowCustomDescriptionModal() => modalService.Show<CustomDescriptionModal>(builder => {
builder.Add(parameter => parameter.customDescription, newCustomDescription);
builder.Add(parameter => parameter.suggestedCustomDescriptions, suggestedCustomDescriptions);
});
protected override async Task OnParametersSetAsync() {
if (authenticationStateTask != null) {
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
await ApplicationLoadingIndicatorService.Show();
contacts = await genericController.GetAllAsync<Contact>();
await ApplicationLoadingIndicatorService.Hide();
quote = await GenerateNewQuote(quote, "Woitschetzki");
}
}
await base.OnInitializedAsync();
}
private async Task<Quote> GenerateNewQuote(Quote _quote, string salesRepLastName) {
if (_quote == null)
return new();
_quote.SalesRep = await genericController.GetAsync<Contact>(c => c.LastName.Equals(salesRepLastName), "Account");
Quote? lastQuote = genericController.GetLast<Quote>();
_quote.QuoteId = lastQuote != null ? lastQuote.QuoteId + 1 : 1;
_quote.QuotationNumber = _quote.SalesRep != null
? _quote.SalesRep.LastName switch {
"Woitschetzki" => $"DE-83PE89-{DateTime.Now:My}-{_quote.QuoteId}",
"Welsch" => $"DE-83RE32-{DateTime.Now:My}-{_quote.QuoteId}",
_ => $"DE-XXYYXX-{DateTime.Now:My}-{_quote.QuoteId}"
}
: $"DE-XXYYXX-{DateTime.Now:My}-{_quote.QuoteId}";
_quote.Description = "Gerät";
return _quote;
}
private async Task SelectQuoteOnChanged(FileChangedEventArgs e) {
try {
foreach (IFileEntry? file in e.Files) {
using MemoryStream stream = new();
await file.WriteToStreamAsync(stream);
_ = stream.Seek(0, SeekOrigin.Begin);
using StreamReader reader = new(stream);
string fileContent = await reader.ReadToEndAsync();
quote = QuoteHandling.ReadLineItems(quote, fileContent);
if (quote.Recipient?.Account?.AccountName != null) {
quote = hostingService.SetPath(quote);
}
if (quote.LineItems == null)
return;
FileService.WriteQuoteToTsv(fileContent, quote);
//TODO Load all relevant CustomDescriptions upfront
for (int i = 0; i < quote.LineItems.Count(); i++) {
newCustomDescription = await genericController.GetAsync<CustomDescription>(newCustomDescription => newCustomDescription.ProductNumber.Equals(quote.LineItems[i].ProductNumber, StringComparison.Ordinal) && newCustomDescription.OptionNumber.Equals(quote.LineItems[i].OptionNumber, StringComparison.Ordinal));
if (newCustomDescription == null) {
Console.WriteLine($"Keine CustomDescription für {quote.LineItems[i].ProductNumber}#{quote.LineItems[i].OptionNumber} verfügbar!");
suggestedCustomDescriptions = await SuggestCustomDescriptions(quote.LineItems[i]);
//TODO generate new CustomDescription
newCustomDescription = new() {
ProductNumber = quote.LineItems[i].ProductNumber,
OptionNumber = quote.LineItems[i].OptionNumber,
Heading = quote.LineItems[i].SapShortDescription,
DescriptionText = quote.LineItems[i].SapLongDescription
};
await ShowCustomDescriptionModal();
}
quote.LineItems[i].CustomDescription = newCustomDescription;
}
}
}
catch (Exception exc) {
Console.WriteLine(exc.Message);
}
finally {
if (quote.Recipient != null)
lineItemsNotReady = false;
StateHasChanged();
}
}
private async Task<List<CustomDescription>?> SuggestCustomDescriptions(LineItem lineItem) {
//IList<CustomDescription>? fromProductNumber = await genericController.GetAllAsync<CustomDescription>(cD => cD.ProductNumber.Equals(lineItem.ProductNumber, StringComparison.Ordinal));
IList<CustomDescription>? fromOptionNumber = new List<CustomDescription>();
if (lineItem.OptionNumber != "")
fromOptionNumber = await genericController.GetAllAsync<CustomDescription>(cD => cD.OptionNumber.Equals(lineItem.OptionNumber, StringComparison.Ordinal));
//if (fromOptionNumber == null && fromProductNumber == null) return null;
//if (fromOptionNumber == null) return fromProductNumber.ToList();
//if (fromProductNumber == null) return fromOptionNumber.ToList();
//return fromProductNumber.Union(fromOptionNumber).ToList();
return fromOptionNumber.ToList();
}
private static void SelectQuoteOnWritten(FileWrittenEventArgs e) => Console.WriteLine($"File: {e.File.Name} Position: {e.Position} Data: {Convert.ToBase64String(e.Data)}");
private static void SelectQuoteOnProgressed(FileProgressedEventArgs e) => Console.WriteLine($"File: {e.File.Name} Progress: {e.Percentage}");
private async Task OnSelectedContactChanged(Contact _selectedContact) {
selectedContact = _selectedContact;
quote.Recipient = selectedContact;
quote.Recipient.Account = await genericController.GetAsync<Account>(account => account.AccountId.Equals(quote.Recipient.AccountId));
if (quote.LineItems != null)
lineItemsNotReady = false;
}
private async Task OnSave() {
if (await genericController.InsertAsync(quote) > 0)
navigationManager.NavigateTo("Quotes/QuoteIndex");
}
private async Task OnCreateTex() {
isCreatingTex = true;
StringBuilder? tex = await QuoteHandling.CreateTexAsync(quote);
if (tex == null)
return;
quote.Tex = tex.ToString();
if (quote.Tex == null)
return;
await FileService.WriteTexFile(quote);
isCreatingTex = false;
Console.WriteLine("Tex file succesfull created.");
texNotReady = false;
}
private async Task OnCreatePdf() {
isCreatingPdf = true;
if (await PdfService.CreatePdf(quote)) {
pdfNotReady = false;
isCreatingPdf = false;
Console.WriteLine("PDF successfull written.");
url = HostingService.GetPdfUrl(quote);
Console.WriteLine($"URL to PDF is {url}");
}
}
private void OnOpenPdfApp() => PdfService.OpenPdfWithOkular(quote);
private async Task OnOpenPdfNewTab() => await jSRuntime.InvokeVoidAsync("OpenNewTab", $"quotes/{url}");
private void OnDescriptionChanged(string description) => quote.Description = description;
private void OnQuotationNumberChanged(string quotationNumber) => quote.QuotationNumber = quotationNumber;
private void OnValidForChanged(string validFor) => quote.ValidFor = byte.Parse(validFor);
private void OnVATChanged(string vat) => quote.Vat = float.Parse(vat);
private void OnIsPriceInformationChanged(bool isPriceInformation) => quote.IsPriceInformation = isPriceInformation;
private void OnShowBruttoChanged(bool onShowBrutto) => quote.ShowBrutto = onShowBrutto;
private void OnShowDiscountsChanged(bool showDiscount) => quote.ShowDiscounts = showDiscount;
private void OnShowSinglePricesChanged(bool showSinglePrices) => quote.ShowSinglePrices = showSinglePrices;
private void OnWarrantyChanged(string warranty) => quote.Warranty = int.Parse(warranty);
private void OnCancel() => navigationManager.NavigateTo("Quotes/QuoteIndex");
}

@ -177,46 +177,3 @@
</NotAuthorized>
</AuthorizeView>
@code {
[CascadingParameter] private Task<AuthenticationState>? authenticationStateTask { get; set; }
private IList<Quote>? quotes;
private Quote? selectedQuote;
private readonly CultureInfo cultureInfo = new("de-DE");
private string selectedTab = "details";
protected override async Task OnInitializedAsync()
{
if (authenticationStateTask != null)
{
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true })
{
quotes = await genericController.GetAllAsync<Quote>();
}
}
await base.OnInitializedAsync();
}
private async Task OnSelectedQuoteChanged(Quote _selectedQuote) {
selectedQuote = _selectedQuote;
selectedQuote.Recipient = await genericController.GetAsync<Contact>(c => c.ContactId.Equals(selectedQuote.ContactId));
if (selectedQuote.Recipient != null && selectedQuote != null) {
selectedQuote = await genericController.GetAsync<Quote>(c => c.QuoteId.Equals(_selectedQuote.QuoteId), "Recipient", "LineItems");
selectedQuote.Recipient.Account = await genericController.GetAsync<Account>(a => a.AccountId.Equals(selectedQuote.Recipient.AccountId));
}
//selectedQuote.LineItems = await genericController.GetAllAsync<LineItem>(lI => lI.Quote.Equals(selectedQuote));
return;
}
private void OnCreateNewQuote() {
navigationManager.NavigateTo("Quotes/QuoteAdd");
}
private Task OnSelectedTabChanged(string _selectedTab) {
selectedTab = _selectedTab;
return Task.CompletedTask;
}
}

@ -0,0 +1,48 @@
using Gremlin_BlazorServer.Data.EntityClasses;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using System.Globalization;
using System.Security.Claims;
namespace Gremlin_BlazorServer.Pages.Quotes {
public partial class QuoteIndex {
[CascadingParameter]
private Task<AuthenticationState>? authenticationStateTask { get; set; }
private IList<Quote>? quotes;
private Quote? selectedQuote;
private readonly CultureInfo cultureInfo = new("de-DE");
private string selectedTab = "details";
protected override async Task OnInitializedAsync() {
if (authenticationStateTask != null) {
ClaimsPrincipal user = (await authenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
quotes = await genericController.GetAllAsync<Quote>();
}
}
await base.OnInitializedAsync();
}
private async Task OnSelectedQuoteChanged(Quote _selectedQuote) {
selectedQuote = _selectedQuote;
selectedQuote.Recipient = await genericController.GetAsync<Contact>(c => c.ContactId.Equals(selectedQuote.ContactId));
if (selectedQuote.Recipient != null && selectedQuote != null) {
selectedQuote = await genericController.GetAsync<Quote>(c => c.QuoteId.Equals(_selectedQuote.QuoteId), "Recipient", "LineItems");
selectedQuote.Recipient.Account = await genericController.GetAsync<Account>(a => a.AccountId.Equals(selectedQuote.Recipient.AccountId));
}
//selectedQuote.LineItems = await genericController.GetAllAsync<LineItem>(lI => lI.Quote.Equals(selectedQuote));
return;
}
private void OnCreateNewQuote() {
navigationManager.NavigateTo("Quotes/QuoteAdd");
}
private Task OnSelectedTabChanged(string _selectedTab) {
selectedTab = _selectedTab;
return Task.CompletedTask;
}
}
}