diff --git a/Gremlin_BlazorServer/Data/EntityClasses/ProductLine.cs b/Gremlin_BlazorServer/Data/EntityClasses/ProductLine.cs index a77bb93..df12690 100644 --- a/Gremlin_BlazorServer/Data/EntityClasses/ProductLine.cs +++ b/Gremlin_BlazorServer/Data/EntityClasses/ProductLine.cs @@ -13,7 +13,7 @@ namespace Gremlin_BlazorServer.Data.EntityClasses public List Products { get; set; }= new List(); //class properties: - public string? ProductLineDescription { get; set; } + public string ProductLineDescription { get; set; } = string.Empty; //metadata: public DateTime DataCreationDate { get; set; } = DateTime.Now; diff --git a/Gremlin_BlazorServer/Pages/AccountTypes/Index.razor b/Gremlin_BlazorServer/Pages/AccountTypes/Index.razor new file mode 100644 index 0000000..6be5ee4 --- /dev/null +++ b/Gremlin_BlazorServer/Pages/AccountTypes/Index.razor @@ -0,0 +1,54 @@ +@page "/AccountTypes/Index" + +@using Gremlin_BlazorServer.Data.EntityClasses; +@using Gremlin_BlazorServer.Services; +@using System.Globalization; +@using System.Diagnostics; + +@inject AccountTypeService accountTypeService + +

AccountTypes

+ +@if (accountTypes is null) +{ +

Loading... !

+} +else +{ +

Es wurden @accountTypes.Count AccountTypes gefunden.

+ @if (accountTypes != null) + { + + + + + + +

AccountType @selectedAccountType.AccountTypeCode selected.

+ } +} + +@code { + private int totalAccountTypeLines; + public string searchAccountType = ""; + CultureInfo cultureInfo = new("de-DE"); + + AccountType selectedAccountType = new(); + List accountTypes = new(); + + protected override async Task OnParametersSetAsync() + { + accountTypes = await Task.Run(() => accountTypeService.GetAllAccountTypesAsync()); + selectedAccountType = accountTypes.FirstOrDefault()!; + } +} \ No newline at end of file diff --git a/Gremlin_BlazorServer/Pages/ProductLines/Index.razor b/Gremlin_BlazorServer/Pages/ProductLines/Index.razor new file mode 100644 index 0000000..c7f2043 --- /dev/null +++ b/Gremlin_BlazorServer/Pages/ProductLines/Index.razor @@ -0,0 +1,52 @@ +@page "/ProductLines/Index" + +@using Gremlin_BlazorServer.Data.EntityClasses; +@using Gremlin_BlazorServer.Services; +@using System.Globalization; +@using System.Diagnostics; + +@inject ProductLineService productLineService + +

ProductLines

+ +@if (productLines is null) +{ +

Loading... !

+} +else +{ +

Es wurden @productLines.Count ProductLines gefunden.

+ @if (productLines != null) + { + + + + + + +

ProductLine @selectedProductLine.ProductLineCode selected.

+ } +} + +@code { + public string searchProductLine = ""; + CultureInfo cultureInfo = new("de-DE"); + + ProductLine selectedProductLine = new(); + List productLines = new(); + + protected override async Task OnParametersSetAsync() + { + productLines = await Task.Run(() => productLineService.GetAllProductLinesAsync()); + selectedProductLine = productLines.FirstOrDefault()!; + } +} \ No newline at end of file diff --git a/Gremlin_BlazorServer/Pages/Products/Index.razor b/Gremlin_BlazorServer/Pages/Products/Index.razor index c81d35b..f954e35 100644 --- a/Gremlin_BlazorServer/Pages/Products/Index.razor +++ b/Gremlin_BlazorServer/Pages/Products/Index.razor @@ -22,14 +22,11 @@ else TItem="Product" Data="@products" @bind-SelectedRow="@selectedProduct" - ReadData="@OnReadData" - TotalItems="@totalProducts" + @*ReadData="@OnReadData"*@ PageSize="10" ShowPager Bordered Hoverable - Filterable - Sortable Striped Responsive> @@ -38,7 +35,7 @@ else - + @* *@

Product @selectedProduct.ProductNumber selected.

@@ -46,7 +43,6 @@ else } @code { - private int totalProducts; public string searchProduct = ""; CultureInfo cultureInfo = new("de-DE"); @@ -59,24 +55,24 @@ else selectedProduct = products.FirstOrDefault()!; } - private async Task OnReadData(DataGridReadDataEventArgs eventArgs) - { - if (!eventArgs.CancellationToken.IsCancellationRequested) - { - List response = new(); + //private async Task OnReadData(DataGridReadDataEventArgs eventArgs) + //{ + // if (!eventArgs.CancellationToken.IsCancellationRequested) + // { + // List response = new(); - if (eventArgs.ReadDataMode is DataGridReadDataMode.Virtualize) - response = (await productService.GetAllProductsAsync()).Skip(eventArgs.VirtualizeOffset).Take(eventArgs.VirtualizeCount).ToList(); - else if (eventArgs.ReadDataMode is DataGridReadDataMode.Paging) - response = (await productService.GetAllProductsAsync()).Skip((eventArgs.Page - 1) * eventArgs.PageSize).Take(eventArgs.PageSize).ToList(); - else - throw new Exception("Unhandled ReadDataMode"); + // if (eventArgs.ReadDataMode is DataGridReadDataMode.Virtualize) + // response = (await productService.GetAllProductsAsync()).Skip(eventArgs.VirtualizeOffset).Take(eventArgs.VirtualizeCount).ToList(); + // else if (eventArgs.ReadDataMode is DataGridReadDataMode.Paging) + // response = (await productService.GetAllProductsAsync()).Skip((eventArgs.Page - 1) * eventArgs.PageSize).Take(eventArgs.PageSize).ToList(); + // else + // throw new Exception("Unhandled ReadDataMode"); - if (!eventArgs.CancellationToken.IsCancellationRequested) - { - totalProducts = (await productService.GetAllProductsAsync()).Count; - products = new List(response); // an actual data for the current page - } - } - } + // if (!eventArgs.CancellationToken.IsCancellationRequested) + // { + // totalProducts = (await productService.GetAllProductsAsync()).Count; + // products = new List(response); // an actual data for the current page + // } + // } + //} } \ No newline at end of file diff --git a/Gremlin_BlazorServer/Program.cs b/Gremlin_BlazorServer/Program.cs index 64208ab..8ef55bc 100644 --- a/Gremlin_BlazorServer/Program.cs +++ b/Gremlin_BlazorServer/Program.cs @@ -17,6 +17,8 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddBlazorise(options => { options.Immediate = true; }).AddBootstrapProviders().AddFontAwesomeIcons(); diff --git a/Gremlin_BlazorServer/Services/AccountTypeService.cs b/Gremlin_BlazorServer/Services/AccountTypeService.cs new file mode 100644 index 0000000..dbd58b4 --- /dev/null +++ b/Gremlin_BlazorServer/Services/AccountTypeService.cs @@ -0,0 +1,51 @@ +using Gremlin_BlazorServer.Data.DBClasses; +using Gremlin_BlazorServer.Data.EntityClasses; +using Microsoft.EntityFrameworkCore; +using System.Diagnostics; + +namespace Gremlin_BlazorServer.Services +{ + public class AccountTypeService + { + private readonly GremlinContext gremlinContext; + public AccountTypeService(GremlinContext gC) => gremlinContext = gC; + + public void ConfigureServices(IServiceCollection services) => services.AddDbContext(ServiceLifetime.Scoped); + + public async Task> GetAllAccountTypesAsync() => await gremlinContext.AccountTypes.ToListAsync(); + + public async Task InsertAccountTypeAsync(AccountType accountType) + { + try + { + _ = await gremlinContext.AccountTypes.AddAsync(accountType); + _ = await gremlinContext.SaveChangesAsync(); + return true; + } + catch (Exception exception) + { + Debug.WriteLine(exception.Message); + return false; + } + } + + public async Task GetAccountTypeAsync(string accountTypeCode) + { + return await gremlinContext.AccountTypes.FirstOrDefaultAsync(AccountType => AccountType.AccountTypeCode.Equals(accountTypeCode)); + } + + public async Task UpdateAccountTypeAsync(AccountType AccountType) + { + _ = gremlinContext.AccountTypes.Update(AccountType); + _ = await gremlinContext.SaveChangesAsync(); + return true; + } + + public async Task DeleteAccountTypeAsync(AccountType AccountType) + { + _ = gremlinContext.Remove(AccountType); + _ = await gremlinContext.SaveChangesAsync(); + return true; + } + } +} diff --git a/Gremlin_BlazorServer/Services/ProductLineService.cs b/Gremlin_BlazorServer/Services/ProductLineService.cs new file mode 100644 index 0000000..156ede7 --- /dev/null +++ b/Gremlin_BlazorServer/Services/ProductLineService.cs @@ -0,0 +1,51 @@ +using Gremlin_BlazorServer.Data.DBClasses; +using Gremlin_BlazorServer.Data.EntityClasses; +using Microsoft.EntityFrameworkCore; +using System.Diagnostics; + +namespace Gremlin_BlazorServer.Services +{ + public class ProductLineService + { + private readonly GremlinContext gremlinContext; + public ProductLineService(GremlinContext gC) => gremlinContext = gC; + + public void ConfigureServices(IServiceCollection services) => services.AddDbContext(ServiceLifetime.Scoped); + + public async Task> GetAllProductLinesAsync() => await gremlinContext.ProductLines.ToListAsync(); + + public async Task InsertProductLineAsync(ProductLine productLine) + { + try + { + _ = await gremlinContext.ProductLines.AddAsync(productLine); + _ = await gremlinContext.SaveChangesAsync(); + return true; + } + catch (Exception exception) + { + Debug.WriteLine(exception.Message); + return false; + } + } + + public async Task GetProductLineAsync(string productLineCode) + { + return await gremlinContext.ProductLines.FirstOrDefaultAsync(ProductLine => ProductLine.ProductLineCode.Equals(productLineCode)); + } + + public async Task UpdateProductLineAsync(ProductLine ProductLine) + { + _ = gremlinContext.ProductLines.Update(ProductLine); + _ = await gremlinContext.SaveChangesAsync(); + return true; + } + + public async Task DeleteProductLineAsync(ProductLine ProductLine) + { + _ = gremlinContext.Remove(ProductLine); + _ = await gremlinContext.SaveChangesAsync(); + return true; + } + } +} diff --git a/Gremlin_BlazorServer/Shared/NavMenu.razor b/Gremlin_BlazorServer/Shared/NavMenu.razor index a62d721..9aeb71f 100644 --- a/Gremlin_BlazorServer/Shared/NavMenu.razor +++ b/Gremlin_BlazorServer/Shared/NavMenu.razor @@ -49,6 +49,16 @@ Products + +