61 lines
1.5 KiB
C#
61 lines
1.5 KiB
C#
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 GremlinDb gremlinDb;
|
|
public ProductLineService(GremlinDb gC)
|
|
{
|
|
gremlinDb = gC;
|
|
}
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
_ = services.AddDbContext<GremlinDb>(ServiceLifetime.Scoped);
|
|
}
|
|
|
|
public async Task<List<ProductLine>> GetAllProductLinesAsync()
|
|
{
|
|
return await gremlinDb.ProductLines.ToListAsync();
|
|
}
|
|
|
|
public async Task<bool> InsertProductLineAsync(ProductLine productLine)
|
|
{
|
|
try
|
|
{
|
|
_ = await gremlinDb.ProductLines.AddAsync(productLine);
|
|
_ = await gremlinDb.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Debug.WriteLine(exception.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public async Task<ProductLine?> GetProductLineAsync(string productLineCode)
|
|
{
|
|
return await gremlinDb.ProductLines.FirstOrDefaultAsync(productLine => productLine.ProductLineCode.Equals(productLineCode));
|
|
}
|
|
|
|
public async Task<bool> UpdateProductLineAsync(ProductLine productLine)
|
|
{
|
|
_ = gremlinDb.ProductLines.Update(productLine);
|
|
_ = await gremlinDb.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
|
|
public async Task<bool> DeleteProductLineAsync(ProductLine productLine)
|
|
{
|
|
_ = gremlinDb.Remove(productLine);
|
|
_ = await gremlinDb.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
}
|
|
}
|