Loading .gitlab-ci.yml +2 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ stages: image: mcr.microsoft.com/dotnet/sdk:latest dotnet-release: DbManager-release: stage: build tags: - shared-fi # use shared-fi GitLab runner Loading @@ -12,3 +12,4 @@ dotnet-release: artifacts: paths: - build/ expire_in: 2 minutes DbLib/Controllers/Competition/RunController.cs +7 −6 Original line number Diff line number Diff line Loading @@ -5,18 +5,19 @@ using Microsoft.EntityFrameworkCore; namespace DbLib.Controllers.Competition { public class RunController(CompetitionContext context) : IControllerName<Run>, IController<Run> public class RunController(CompetitionContext context) : IControllerId<Run>, IController<Run> { private readonly CompetitionContext _context = context; public Run? Get(string name) public Run? Get(int id) => _context.Run .Include(run => run.Task) .Include(run => run.Result) .FirstOrDefault(run => run.Name == name); .FirstOrDefault(run => run.Id == id); public List<Run> GetAll() => [.. _context.Run.Include(run => run.Result)]; public bool Exists(string name) => _context.Run.Any(run => run.Name == name); public bool Exists(int id) => _context.Run.Any(run => run.Id == id); public Run Add(Run run) { Loading @@ -32,9 +33,9 @@ namespace DbLib.Controllers.Competition public void Update(Run run) => _context.Run.Update(run); public void Delete(string name) public void Delete(int id) { var run = _context.Run.FirstOrDefault(run => run.Name == name) ?? throw new Exception($"Run with given name ({name}) does not exist."); var run = _context.Run.FirstOrDefault(run => run.Id == id) ?? throw new Exception($"Run with given id ({id}) does not exist."); _context.Run.Remove(run); } Loading DbLib/Controllers/Competition/TaskController.cs 0 → 100644 +55 −0 Original line number Diff line number Diff line using DbLib.Controllers.Interfaces; using DbLib.DbContexts; using Microsoft.EntityFrameworkCore; namespace DbLib.Controllers.Competition { public class TaskController(CompetitionContext context) : IController<Models.Competition.Task> { private readonly CompetitionContext _context = context; /// <summary> /// Search controller's table for an entity. /// </summary> /// <param name="name">name of an entity to search for</param> /// <param name="property">name of the property this task belongs to</param> /// <returns>First found entity or <see langword="null"/> when no entity was found.</returns> public Models.Competition.Task? Get(string name, string property) => _context.Task.Include(task => task.Property).FirstOrDefault(task => task.Name == name && task.PropertyName == property); public List<Models.Competition.Task> GetAll() => [.. _context.Task.Include(task => task.Property)]; /// <summary> /// Check if an entity exists in controller's table. /// </summary> /// <param name="name">name of entity to check</param> /// <param name="property">name of the property this task belongs to</param> /// <returns><see langword="true"/> entity exists, <see langword="false"/> otherwise</returns> public bool Exists(string name, string property) => _context.Task.Any(task => task.Name == name && task.PropertyName == property); public Models.Competition.Task Add(Models.Competition.Task task) { _context.Task.Add(task); return task; } public void Update(Models.Competition.Task task) => _context.Task.Update(task); /// <summary> /// Delete an entity from controller's table. /// </summary> /// <param name="name">name of an entity to delete</param> /// <param name="property">name of the property this task belongs to</param> public void Delete(string name, string property) { var task = _context.Task.FirstOrDefault(task => task.Name == name && task.PropertyName == property) ?? throw new Exception($"Task with given name ({name}) does not exist."); _context.Task.Remove(task); } public void Delete(Models.Competition.Task task) => _context.Task.Remove(task); public void DeleteAll() => _context.Task.RemoveRange(_context.Task); } } DbLib/DbContexts/CompetitionContext.cs +3 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ namespace DbLib.DbContexts public DbSet<Property> Property { get; set; } public DbSet<Result> Result { get; set; } public DbSet<Run> Run { get; set; } public DbSet<Models.Competition.Task> Task { get; set; } public DbSet<Tool> Tool { get; set; } public DbSet<Witness> Witness { get; set; } Loading @@ -26,6 +27,7 @@ namespace DbLib.DbContexts public PropertyController PropertyController { get; } public ResultController ResultController { get; } public RunController RunController { get; } public TaskController TaskController { get; } public ToolController ToolController { get; } public WitnessController WitnessController { get; } Loading @@ -44,6 +46,7 @@ namespace DbLib.DbContexts PropertyController = new(this); ResultController = new(this); RunController = new(this); TaskController = new(this); ToolController = new(this); WitnessController = new(this); } Loading DbLib/Models/Competition/EResultCategory.cs +3 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ Unknown, Correct, Wrong, Error Error, Missing, CorrectUnconfirmed } } Loading
.gitlab-ci.yml +2 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ stages: image: mcr.microsoft.com/dotnet/sdk:latest dotnet-release: DbManager-release: stage: build tags: - shared-fi # use shared-fi GitLab runner Loading @@ -12,3 +12,4 @@ dotnet-release: artifacts: paths: - build/ expire_in: 2 minutes
DbLib/Controllers/Competition/RunController.cs +7 −6 Original line number Diff line number Diff line Loading @@ -5,18 +5,19 @@ using Microsoft.EntityFrameworkCore; namespace DbLib.Controllers.Competition { public class RunController(CompetitionContext context) : IControllerName<Run>, IController<Run> public class RunController(CompetitionContext context) : IControllerId<Run>, IController<Run> { private readonly CompetitionContext _context = context; public Run? Get(string name) public Run? Get(int id) => _context.Run .Include(run => run.Task) .Include(run => run.Result) .FirstOrDefault(run => run.Name == name); .FirstOrDefault(run => run.Id == id); public List<Run> GetAll() => [.. _context.Run.Include(run => run.Result)]; public bool Exists(string name) => _context.Run.Any(run => run.Name == name); public bool Exists(int id) => _context.Run.Any(run => run.Id == id); public Run Add(Run run) { Loading @@ -32,9 +33,9 @@ namespace DbLib.Controllers.Competition public void Update(Run run) => _context.Run.Update(run); public void Delete(string name) public void Delete(int id) { var run = _context.Run.FirstOrDefault(run => run.Name == name) ?? throw new Exception($"Run with given name ({name}) does not exist."); var run = _context.Run.FirstOrDefault(run => run.Id == id) ?? throw new Exception($"Run with given id ({id}) does not exist."); _context.Run.Remove(run); } Loading
DbLib/Controllers/Competition/TaskController.cs 0 → 100644 +55 −0 Original line number Diff line number Diff line using DbLib.Controllers.Interfaces; using DbLib.DbContexts; using Microsoft.EntityFrameworkCore; namespace DbLib.Controllers.Competition { public class TaskController(CompetitionContext context) : IController<Models.Competition.Task> { private readonly CompetitionContext _context = context; /// <summary> /// Search controller's table for an entity. /// </summary> /// <param name="name">name of an entity to search for</param> /// <param name="property">name of the property this task belongs to</param> /// <returns>First found entity or <see langword="null"/> when no entity was found.</returns> public Models.Competition.Task? Get(string name, string property) => _context.Task.Include(task => task.Property).FirstOrDefault(task => task.Name == name && task.PropertyName == property); public List<Models.Competition.Task> GetAll() => [.. _context.Task.Include(task => task.Property)]; /// <summary> /// Check if an entity exists in controller's table. /// </summary> /// <param name="name">name of entity to check</param> /// <param name="property">name of the property this task belongs to</param> /// <returns><see langword="true"/> entity exists, <see langword="false"/> otherwise</returns> public bool Exists(string name, string property) => _context.Task.Any(task => task.Name == name && task.PropertyName == property); public Models.Competition.Task Add(Models.Competition.Task task) { _context.Task.Add(task); return task; } public void Update(Models.Competition.Task task) => _context.Task.Update(task); /// <summary> /// Delete an entity from controller's table. /// </summary> /// <param name="name">name of an entity to delete</param> /// <param name="property">name of the property this task belongs to</param> public void Delete(string name, string property) { var task = _context.Task.FirstOrDefault(task => task.Name == name && task.PropertyName == property) ?? throw new Exception($"Task with given name ({name}) does not exist."); _context.Task.Remove(task); } public void Delete(Models.Competition.Task task) => _context.Task.Remove(task); public void DeleteAll() => _context.Task.RemoveRange(_context.Task); } }
DbLib/DbContexts/CompetitionContext.cs +3 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ namespace DbLib.DbContexts public DbSet<Property> Property { get; set; } public DbSet<Result> Result { get; set; } public DbSet<Run> Run { get; set; } public DbSet<Models.Competition.Task> Task { get; set; } public DbSet<Tool> Tool { get; set; } public DbSet<Witness> Witness { get; set; } Loading @@ -26,6 +27,7 @@ namespace DbLib.DbContexts public PropertyController PropertyController { get; } public ResultController ResultController { get; } public RunController RunController { get; } public TaskController TaskController { get; } public ToolController ToolController { get; } public WitnessController WitnessController { get; } Loading @@ -44,6 +46,7 @@ namespace DbLib.DbContexts PropertyController = new(this); ResultController = new(this); RunController = new(this); TaskController = new(this); ToolController = new(this); WitnessController = new(this); } Loading
DbLib/Models/Competition/EResultCategory.cs +3 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ Unknown, Correct, Wrong, Error Error, Missing, CorrectUnconfirmed } }