76 lines
2.2 KiB
C#
76 lines
2.2 KiB
C#
using Gremlin_BlazorServer.Data.DBClasses;
|
|
using Gremlin_BlazorServer.Data.EntityClasses;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Diagnostics;
|
|
|
|
namespace Gremlin_BlazorServer.Services
|
|
{
|
|
public class CustomDescriptionService
|
|
{
|
|
private readonly GremlinDb gremlinDb;
|
|
|
|
public CustomDescriptionService(GremlinDb gC)
|
|
{
|
|
gremlinDb = gC;
|
|
}
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
_ = services.AddDbContext<GremlinDb>(ServiceLifetime.Scoped);
|
|
}
|
|
|
|
public async Task<List<CustomDescription>> GetAllCustomDescriptionsAsync()
|
|
{
|
|
return await gremlinDb.CustomDescriptions.ToListAsync();
|
|
}
|
|
|
|
public async Task<bool> InsertCustomDescriptionAsync(CustomDescription customDescription)
|
|
{
|
|
try
|
|
{
|
|
_ = await gremlinDb.CustomDescriptions.AddAsync(customDescription);
|
|
_ = await gremlinDb.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Debug.WriteLine(exception.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public async Task<CustomDescription> GetCustomDescriptionAsync(uint customDescriptionId)
|
|
{
|
|
return await gremlinDb.CustomDescriptions.FirstOrDefaultAsync(cD => cD.CustomDescriptionId.Equals(customDescriptionId)) ?? new CustomDescription();
|
|
}
|
|
|
|
public async Task<CustomDescription> GetCustomDescriptionAsync(string productNumber, string optionNumber)
|
|
{
|
|
CustomDescription? customDescription = await gremlinDb.CustomDescriptions.FirstOrDefaultAsync(cD => cD.ProductNumber == productNumber && cD.OptionNumber == optionNumber);
|
|
if (customDescription != null)
|
|
{
|
|
//Debug.WriteLine($"{productNumber}#{optionNumber}: {customDescription.DescriptionText}");
|
|
return customDescription;
|
|
}
|
|
else
|
|
{
|
|
Debug.WriteLine($"{productNumber}#{optionNumber}: keine CustomDescription gefunden!");
|
|
return new();
|
|
}
|
|
}
|
|
|
|
public async Task<bool> UpdateCustomDescriptionAsync(CustomDescription customDescription)
|
|
{
|
|
_ = gremlinDb.CustomDescriptions.Update(customDescription);
|
|
_ = await gremlinDb.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
|
|
public async Task<bool> DeleteCustomDescriptionAsync(CustomDescription customDescription)
|
|
{
|
|
_ = gremlinDb.Remove(customDescription);
|
|
_ = await gremlinDb.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
}
|
|
} |