58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using MMOserver.RDB.Models;
|
|
using MMOserver.RDB.Repositories;
|
|
|
|
namespace MMOserver.RDB.Services;
|
|
|
|
public class TestService
|
|
{
|
|
private readonly TestRepository repo;
|
|
|
|
public TestService(TestRepository repo)
|
|
{
|
|
this.repo = repo;
|
|
}
|
|
|
|
public Task<Test?> GetTestAsync(int id)
|
|
{
|
|
return repo.GetByIdAsync(id);
|
|
}
|
|
|
|
public Task<Test?> GetTestByUuidAsync(string uuid)
|
|
{
|
|
return repo.GetByUuidAsync(uuid);
|
|
}
|
|
|
|
public Task<IEnumerable<Test>> GetAllTestsAsync()
|
|
{
|
|
return repo.GetAllAsync();
|
|
}
|
|
|
|
public async Task<long> CreateTestAsync(int testA, string testB, double testC)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(testB))
|
|
{
|
|
throw new ArgumentException("TestB is required");
|
|
}
|
|
|
|
return await repo.InsertAsync(new Test { TestA = testA, TestB = testB, TestC = testC, Uuid = Guid.NewGuid().ToString() });
|
|
}
|
|
|
|
public async Task<bool> UpdateTestAsync(int id, int? testA, string? testB, double? testC)
|
|
{
|
|
Test entity = await repo.GetByIdAsync(id) ?? throw new KeyNotFoundException("Test not found");
|
|
|
|
entity.TestA = testA ?? entity.TestA;
|
|
entity.TestB = testB ?? entity.TestB;
|
|
entity.TestC = testC ?? entity.TestC;
|
|
|
|
return await repo.UpdateAsync(entity);
|
|
}
|
|
|
|
public async Task<bool> DeleteTestAsync(int id)
|
|
{
|
|
Test entity = await repo.GetByIdAsync(id) ?? throw new KeyNotFoundException("Test not found");
|
|
|
|
return await repo.DeleteAsync(entity);
|
|
}
|
|
}
|