56 lines
1.7 KiB
C#
56 lines
1.7 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)
|
|
{
|
|
CustomDescription? CustomDescription = await gremlinContext.CustomDescriptions.FirstOrDefaultAsync(CustomDescription => CustomDescription.CustomDescriptionId.Equals(CustomDescriptionId));
|
|
return CustomDescription;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |