70 lines
2.7 KiB
C#
70 lines
2.7 KiB
C#
using System.Globalization;
|
|
using System.Security.Claims;
|
|
using Blazorise.DataGrid;
|
|
using Gremlin_BlazorServer.Data.EntityClasses;
|
|
using Gremlin_BlazorServer.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
|
|
namespace Gremlin_BlazorServer.Pages.Quotes;
|
|
|
|
public partial class QuoteCreate {
|
|
private readonly CultureInfo cultureInfo = new("de-DE");
|
|
private IList<Product>? foundProducts;
|
|
private IList<LineItem> lineItems;
|
|
private string optionNumber = "";
|
|
private string productNumber = "";
|
|
private List<LineItem> selectedLineItems;
|
|
private Product selectedProduct;
|
|
[CascadingParameter] private Task<AuthenticationState>? AuthenticationStateTask { get; set; }
|
|
|
|
protected override async Task OnInitializedAsync() {
|
|
if (AuthenticationStateTask != null) {
|
|
ClaimsPrincipal user = (await AuthenticationStateTask).User;
|
|
if (user.Identity is { IsAuthenticated: true }) {
|
|
foundProducts = new List<Product>();
|
|
lineItems = new List<LineItem>();
|
|
}
|
|
}
|
|
|
|
await base.OnInitializedAsync();
|
|
}
|
|
|
|
private async Task OnSearchProductClicked() {
|
|
foundProducts = await GenericController.GetAllAsync<Product>(p => p.ProductNumber.Contains(productNumber) && p.OptionNumber.Contains(optionNumber));
|
|
Console.WriteLine($"Found {foundProducts.Count} products with ProductNumber '{productNumber}' and OptionNumber '{optionNumber}'.");
|
|
}
|
|
|
|
private Task OnSelectedProductChanged(Product product) {
|
|
selectedProduct = product;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private Task OnAddProductClicked() {
|
|
int position = lineItems.Count + 1;
|
|
LineItem newLineItem = new() {
|
|
Position = ushort.Parse(position.ToString()),
|
|
ProductNumber = selectedProduct.ProductNumber,
|
|
OptionNumber = selectedProduct.OptionNumber,
|
|
SapShortDescription = selectedProduct.SapShortDescription,
|
|
SapLongDescription = selectedProduct.SapLongDescription,
|
|
ListPrice = selectedProduct.ListPrice,
|
|
NetPrice = selectedProduct.ListPrice,
|
|
Total = selectedProduct.ListPrice
|
|
};
|
|
lineItems.Add(newLineItem);
|
|
Console.WriteLine($"Added {newLineItem.ProductNumber}#{newLineItem.OptionNumber} to LineItems as position {newLineItem.Position}.");
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private Task OnSelectionChanged(List<LineItem> listOfLineItems) {
|
|
selectedLineItems = listOfLineItems;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private Task OnLineItemInsertedAsync(SavedRowItem<LineItem, Dictionary<string, object>> arg) => throw new NotImplementedException();
|
|
|
|
private Task OnLineItemUpdatedAsync(SavedRowItem<LineItem, Dictionary<string, object>> arg) => throw new NotImplementedException();
|
|
|
|
private Task OnLineItemRemovedAsync(LineItem arg) => throw new NotImplementedException();
|
|
} |