70 lines
2.3 KiB
C#
70 lines
2.3 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 GremlinContext gremlinContext;
|
|
|
|
public CustomDescriptionService(GremlinContext gC)
|
|
=> gremlinContext = gC;
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
=> _ = services.AddDbContext<GremlinContext>(ServiceLifetime.Scoped);
|
|
|
|
public async Task<List<CustomDescription>> GetAllCustomDescriptionsAsync()
|
|
=> await gremlinContext.CustomDescriptions.ToListAsync();
|
|
|
|
public async Task<bool> InsertCustomDescriptionAsync(CustomDescription customDescription)
|
|
{
|
|
try
|
|
{
|
|
_ = await gremlinContext.CustomDescriptions.AddAsync(customDescription);
|
|
_ = await gremlinContext.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Debug.WriteLine(exception.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public async Task<CustomDescription> GetCustomDescriptionAsync(uint customDescriptionId)
|
|
{
|
|
return await gremlinContext.CustomDescriptions.FirstOrDefaultAsync(cD => cD.CustomDescriptionId.Equals(customDescriptionId)) ?? new CustomDescription();
|
|
}
|
|
|
|
public async Task<CustomDescription> GetCustomDescriptionAsync(string productNumber, string optionNumber)
|
|
{
|
|
CustomDescription? customDescription = await gremlinContext.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)
|
|
{
|
|
_ = gremlinContext.CustomDescriptions.Update(customDescription);
|
|
_ = await gremlinContext.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
|
|
public async Task<bool> DeleteCustomDescriptionAsync(CustomDescription customDescription)
|
|
{
|
|
_ = gremlinContext.Remove(customDescription);
|
|
_ = await gremlinContext.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
}
|
|
} |