Updating
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.ArchiverApiModel.Entities;
|
||||
|
||||
namespace LCU.Library.Internal.ArchiverApiLib.Extensions
|
||||
{
|
||||
public static class QueryableIncludeAll
|
||||
{
|
||||
public static IQueryable<ApplicationMapping> IncludeAll(this IQueryable<ApplicationMapping> queryable)
|
||||
{
|
||||
return queryable.Include(applicationMapping => applicationMapping.ParameterMappings).Include(applicationMapping => applicationMapping.RegexMappings);
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Description>1.0.0 - Initial Creation</Description>
|
||||
<PackageReleaseNotes>1.0.0 - Initial Creation</PackageReleaseNotes>
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EntityFramework" Version="6.4.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LCU.Library.Internal.ArchiverApiModel\LCU.Library.Internal.ArchiverApiModel.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.ArchiverApiModel.Entities;
|
||||
|
||||
namespace LCU.Library.Internal.ArchiverApiLib.Persistence
|
||||
{
|
||||
public class AppDbContext : DbContext
|
||||
{
|
||||
public DbSet<ApplicationMapping> ApplicationMappings { get; set; }
|
||||
public DbSet<ParameterMapping> ParameterMappings { get; set; }
|
||||
public DbSet<RegexMapping> RegexMappings { get; set; }
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.Entity<ApplicationMapping>().ToTable("ApplicationMapping");
|
||||
builder.Entity<ParameterMapping>().ToTable("ParameterMapping");
|
||||
builder.Entity<RegexMapping>().ToTable("RegexMapping");
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.ArchiverApiLib.Extensions;
|
||||
using LCU.Library.Internal.ArchiverApiLib.Persistence;
|
||||
using LCU.Library.Internal.ArchiverApiModel.Entities;
|
||||
|
||||
namespace LCU.Library.Internal.ArchiverApiLib.Repositories
|
||||
{
|
||||
public class ApplicationMappingRepository : BaseRepository, IApplicationMappingRepository
|
||||
{
|
||||
public ApplicationMappingRepository(AppDbContext context) : base(context) { }
|
||||
|
||||
public async Task<IEnumerable<ApplicationMapping>> ListAsync()
|
||||
{
|
||||
return await _context.ApplicationMappings.IncludeAll().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<ApplicationMapping> FindByIdAsync(int id)
|
||||
{
|
||||
return await _context.ApplicationMappings.Where(applicationMapping => applicationMapping.ApplicationMappingId == id).IncludeAll().FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ApplicationMapping>> FindByIdentifierAsync(string identifier)
|
||||
{
|
||||
return await _context.ApplicationMappings.Where(applicationMapping => applicationMapping.Identifier == identifier).IncludeAll().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<ApplicationMapping> AddAsync(ApplicationMapping applicationMapping)
|
||||
{
|
||||
var result = await _context.ApplicationMappings.AddAsync(applicationMapping);
|
||||
return result.Entity;
|
||||
}
|
||||
|
||||
public void Update(ApplicationMapping applicationMapping)
|
||||
{
|
||||
_context.ApplicationMappings.Update(applicationMapping);
|
||||
}
|
||||
|
||||
public void Remove(ApplicationMapping applicationMapping)
|
||||
{
|
||||
_context.ApplicationMappings.Remove(applicationMapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using LCU.Library.Internal.ArchiverApiLib.Persistence;
|
||||
|
||||
namespace LCU.Library.Internal.ArchiverApiLib.Repositories
|
||||
{
|
||||
public abstract class BaseRepository
|
||||
{
|
||||
protected readonly AppDbContext _context;
|
||||
|
||||
public BaseRepository(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.Library.Internal.ArchiverApiModel.Entities;
|
||||
|
||||
namespace LCU.Library.Internal.ArchiverApiLib.Repositories
|
||||
{
|
||||
public interface IApplicationMappingRepository
|
||||
{
|
||||
Task<IEnumerable<ApplicationMapping>> ListAsync();
|
||||
Task<ApplicationMapping> FindByIdAsync(int id);
|
||||
Task<IEnumerable<ApplicationMapping>> FindByIdentifierAsync(string identifier);
|
||||
Task<ApplicationMapping> AddAsync(ApplicationMapping applicationMapping);
|
||||
void Update(ApplicationMapping applicationMapping);
|
||||
void Remove(ApplicationMapping applicationMapping);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using LCU.Library.Internal.ArchiverApiModel.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.Library.Internal.ArchiverApiLib.Repositories
|
||||
{
|
||||
public interface IRegexMappingRepository
|
||||
{
|
||||
Task<IEnumerable<RegexMapping>> ListAsync();
|
||||
Task<RegexMapping> FindByApplicationMappingIdAsync(int id);
|
||||
Task<RegexMapping> FindByRegexMappingIdAsync(int id);
|
||||
Task<RegexMapping> AddAsync(RegexMapping regexMapping);
|
||||
void Update(RegexMapping regexMapping);
|
||||
void Remove(RegexMapping regexMapping);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.Library.Internal.ArchiverApiLib.Repositories
|
||||
{
|
||||
public interface IUnitOfWork
|
||||
{
|
||||
Task CompleteAsync();
|
||||
void Complete();
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
using LCU.Library.Internal.ArchiverApiLib.Persistence;
|
||||
using LCU.Library.Internal.ArchiverApiModel.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using LCU.Library.Internal.ArchiverApiLib.Extensions;
|
||||
|
||||
namespace LCU.Library.Internal.ArchiverApiLib.Repositories
|
||||
{
|
||||
public class RegexMappingRepository : BaseRepository, IRegexMappingRepository
|
||||
{
|
||||
public RegexMappingRepository(AppDbContext context) : base(context) { }
|
||||
|
||||
public async Task<RegexMapping> AddAsync(RegexMapping regexMapping)
|
||||
{
|
||||
var result = await _context.RegexMappings.AddAsync(regexMapping);
|
||||
return result.Entity;
|
||||
}
|
||||
|
||||
public async Task<RegexMapping> FindByApplicationMappingIdAsync(int id)
|
||||
{
|
||||
return await _context.RegexMappings.Where(regexMapping => regexMapping.ApplicationMappingId == id).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<RegexMapping> FindByRegexMappingIdAsync(int id)
|
||||
{
|
||||
return await _context.RegexMappings.Where(regexMapping => regexMapping.RegexMappingId == id).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RegexMapping>> ListAsync()
|
||||
{
|
||||
return await _context.RegexMappings.ToListAsync();
|
||||
}
|
||||
|
||||
public void Remove(RegexMapping regexMapping)
|
||||
{
|
||||
_context.RegexMappings.Remove(regexMapping);
|
||||
}
|
||||
|
||||
public void Update(RegexMapping regexMapping)
|
||||
{
|
||||
_context.RegexMappings.Update(regexMapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
using LCU.Library.Internal.ArchiverApiLib.Persistence;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.Library.Internal.ArchiverApiLib.Repositories
|
||||
{
|
||||
public class UnitOfWork : IUnitOfWork
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UnitOfWork(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task CompleteAsync()
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user