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; } } }