move razor code to seperate razor.cs file
parent
2ecff7a5ef
commit
cbf4249acf
@ -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,
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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");
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue