AccountTypes and ProductLines

pull/1/head
DJh2o2 2022-11-25 13:29:15 +07:00
parent a95e36bee0
commit 1f2090ac79
8 changed files with 241 additions and 25 deletions

@ -13,7 +13,7 @@ namespace Gremlin_BlazorServer.Data.EntityClasses
public List<Product> Products { get; set; }= new List<Product>();
//class properties:
public string? ProductLineDescription { get; set; }
public string ProductLineDescription { get; set; } = string.Empty;
//metadata:
public DateTime DataCreationDate { get; set; } = DateTime.Now;

@ -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
<h1>AccountTypes</h1>
@if (accountTypes is null)
{
<p><em>Loading... !</em></p>
}
else
{
<p>Es wurden @accountTypes.Count AccountTypes gefunden.</p>
@if (accountTypes != null)
{
<DataGrid
TItem="AccountType"
Data="@accountTypes"
@bind-SelectedRow="@selectedAccountType"
TotalItems="@totalAccountTypeLines"
PageSize="10"
ShowPager
Bordered
Hoverable
Striped
Responsive>
<DataGridCommandColumn />
<DataGridColumn Field="@nameof(AccountType.AccountTypeCode)" Caption="AccountTypeNumber"/>
<DataGridColumn Field="@nameof(AccountType.AccountTypeDescription)" Caption="AccountTypeDescription" Editable />
</DataGrid>
<p>AccountType @selectedAccountType.AccountTypeCode selected.</p>
}
}
@code {
private int totalAccountTypeLines;
public string searchAccountType = "";
CultureInfo cultureInfo = new("de-DE");
AccountType selectedAccountType = new();
List<AccountType> accountTypes = new();
protected override async Task OnParametersSetAsync()
{
accountTypes = await Task.Run(() => accountTypeService.GetAllAccountTypesAsync());
selectedAccountType = accountTypes.FirstOrDefault()!;
}
}

@ -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
<h1>ProductLines</h1>
@if (productLines is null)
{
<p><em>Loading... !</em></p>
}
else
{
<p>Es wurden @productLines.Count ProductLines gefunden.</p>
@if (productLines != null)
{
<DataGrid
TItem="ProductLine"
Data="@productLines"
@bind-SelectedRow="@selectedProductLine"
PageSize="10"
ShowPager
Bordered
Hoverable
Striped
Responsive>
<DataGridCommandColumn />
<DataGridColumn Field="@nameof(ProductLine.ProductLineCode)" Caption="ProductLineNumber"/>
<DataGridColumn Field="@nameof(ProductLine.ProductLineDescription)" Caption="ProductLineDescription" Editable />
</DataGrid>
<p>ProductLine @selectedProductLine.ProductLineCode selected.</p>
}
}
@code {
public string searchProductLine = "";
CultureInfo cultureInfo = new("de-DE");
ProductLine selectedProductLine = new();
List<ProductLine> productLines = new();
protected override async Task OnParametersSetAsync()
{
productLines = await Task.Run(() => productLineService.GetAllProductLinesAsync());
selectedProductLine = productLines.FirstOrDefault()!;
}
}

@ -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>
<DataGridCommandColumn />
@ -38,7 +35,7 @@ else
<DataGridColumn Field="@nameof(Product.OptionNumber)" Caption="OptionNumber" Editable />
<DataGridColumn Field="@nameof(Product.ListPrice)" Caption="ListPrice" DisplayFormat="{0:C}" DisplayFormatProvider=cultureInfo Editable />
<DataGridColumn Field="@nameof(Product.ProductStatus)" Caption="ProductStatus" Editable />
<DataGridColumn Field="@nameof(Product.IntroductionDate)" Caption="IntroductionDate" Editable />
@*<DataGridColumn Field="@nameof(Product.IntroductionDate)" Caption="IntroductionDate" Editable /> *@
</DataGrid>
<p>Product @selectedProduct.ProductNumber selected.</p>
@ -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<Product> eventArgs)
{
if (!eventArgs.CancellationToken.IsCancellationRequested)
{
List<Product> response = new();
//private async Task OnReadData(DataGridReadDataEventArgs<Product> eventArgs)
//{
// if (!eventArgs.CancellationToken.IsCancellationRequested)
// {
// List<Product> 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<Product>(response); // an actual data for the current page
}
}
}
// if (!eventArgs.CancellationToken.IsCancellationRequested)
// {
// totalProducts = (await productService.GetAllProductsAsync()).Count;
// products = new List<Product>(response); // an actual data for the current page
// }
// }
//}
}

@ -17,6 +17,8 @@ builder.Services.AddScoped<CustomDescriptionService>();
builder.Services.AddScoped<LineItemService>();
builder.Services.AddScoped<QuoteService>();
builder.Services.AddScoped<ProductService>();
builder.Services.AddScoped<ProductLineService>();
builder.Services.AddScoped<AccountTypeService>();
builder.Services.AddScoped<LoginService>();
builder.Services.AddBlazorise(options => { options.Immediate = true; }).AddBootstrapProviders().AddFontAwesomeIcons();

@ -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<GremlinContext>(ServiceLifetime.Scoped);
public async Task<List<AccountType>> GetAllAccountTypesAsync() => await gremlinContext.AccountTypes.ToListAsync();
public async Task<bool> 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<AccountType?> GetAccountTypeAsync(string accountTypeCode)
{
return await gremlinContext.AccountTypes.FirstOrDefaultAsync(AccountType => AccountType.AccountTypeCode.Equals(accountTypeCode));
}
public async Task<bool> UpdateAccountTypeAsync(AccountType AccountType)
{
_ = gremlinContext.AccountTypes.Update(AccountType);
_ = await gremlinContext.SaveChangesAsync();
return true;
}
public async Task<bool> DeleteAccountTypeAsync(AccountType AccountType)
{
_ = gremlinContext.Remove(AccountType);
_ = await gremlinContext.SaveChangesAsync();
return true;
}
}
}

@ -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<GremlinContext>(ServiceLifetime.Scoped);
public async Task<List<ProductLine>> GetAllProductLinesAsync() => await gremlinContext.ProductLines.ToListAsync();
public async Task<bool> 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<ProductLine?> GetProductLineAsync(string productLineCode)
{
return await gremlinContext.ProductLines.FirstOrDefaultAsync(ProductLine => ProductLine.ProductLineCode.Equals(productLineCode));
}
public async Task<bool> UpdateProductLineAsync(ProductLine ProductLine)
{
_ = gremlinContext.ProductLines.Update(ProductLine);
_ = await gremlinContext.SaveChangesAsync();
return true;
}
public async Task<bool> DeleteProductLineAsync(ProductLine ProductLine)
{
_ = gremlinContext.Remove(ProductLine);
_ = await gremlinContext.SaveChangesAsync();
return true;
}
}
}

@ -49,6 +49,16 @@
<span class="oi oi-box" aria-hidden="true"></span>Products
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="ProductLines/Index">
<span class="oi oi-battery-full" aria-hidden="true"></span>ProductLines
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="AccountTypes/Index">
<span class="oi oi-bell" aria-hidden="true"></span>AccountTypes
</NavLink>
</div>
</nav>
</div>