Changed models, added Application layer models

This commit is contained in:
2024-08-15 14:54:23 +03:00
parent 1d8405b4ec
commit c1a4acf414
50 changed files with 628 additions and 647 deletions

View File

@@ -2,18 +2,17 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration
namespace Infrastructure.Database.Applicants.Configuration;
public class AddressConfiguration : IEntityTypeConfiguration<Address>
{
public class AddressConfiguration : IEntityTypeConfiguration<Address>
public void Configure(EntityTypeBuilder<Address> entity)
{
public void Configure(EntityTypeBuilder<Address> entity)
{
entity.Property(p => p.Street)
.IsUnicode(false)
.HasMaxLength(100);
entity.Property(p => p.Building)
.IsUnicode(false)
.HasMaxLength(10);
}
entity.Property(p => p.Street)
.IsUnicode(false)
.HasMaxLength(100);
entity.Property(p => p.Building)
.IsUnicode(false)
.HasMaxLength(10);
}
}
}

View File

@@ -2,26 +2,25 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration
namespace Infrastructure.Database.Applicants.Configuration;
public class ApplicantConfiguration : IEntityTypeConfiguration<Applicant>
{
public class ApplicantConfiguration : IEntityTypeConfiguration<Applicant>
public void Configure(EntityTypeBuilder<Applicant> entity)
{
public void Configure(EntityTypeBuilder<Applicant> entity)
{
entity.ToTable("Applicants");
entity.ToTable("Applicants");
entity.OwnsOne(p => p.Name);
entity.OwnsOne(p => p.FatherName);
entity.OwnsOne(p => p.MotherName);
entity.OwnsOne(p => p.Passport);
entity.OwnsOne(p => p.Name);
entity.OwnsOne(p => p.FatherName);
entity.OwnsOne(p => p.MotherName);
entity.OwnsOne(p => p.Passport);
entity.Property(p => p.Citizenship)
.IsUnicode(false)
.HasMaxLength(30);
entity.Property(p => p.Citizenship)
.IsUnicode(false)
.HasMaxLength(30);
entity.Property(p => p.CitizenshipByBirth)
.IsUnicode(false)
.HasMaxLength(30);
}
entity.Property(p => p.CitizenshipByBirth)
.IsUnicode(false)
.HasMaxLength(30);
}
}
}

View File

@@ -2,23 +2,22 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration
namespace Infrastructure.Database.Applicants.Configuration;
public class NameConfiguration : IEntityTypeConfiguration<Name>
{
public class NameConfiguration : IEntityTypeConfiguration<Name>
public void Configure(EntityTypeBuilder<Name> entity)
{
public void Configure(EntityTypeBuilder<Name> entity)
{
entity.Property(p => p.FirstName)
.IsUnicode(false)
.HasMaxLength(50);
entity.Property(p => p.FirstName)
.IsUnicode(false)
.HasMaxLength(50);
entity.Property(p => p.Surname)
.IsUnicode(false)
.HasMaxLength(50);
entity.Property(p => p.Surname)
.IsUnicode(false)
.HasMaxLength(50);
entity.Property(p => p.Patronymic)
.IsUnicode(false)
.HasMaxLength(50);
}
entity.Property(p => p.Patronymic)
.IsUnicode(false)
.HasMaxLength(50);
}
}
}

View File

@@ -2,19 +2,18 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration
{
public class PassportConfiguration : IEntityTypeConfiguration<Passport>
{
public void Configure(EntityTypeBuilder<Passport> entity)
{
entity.Property(p => p.Number)
.IsUnicode(false)
.HasMaxLength(20);
namespace Infrastructure.Database.Applicants.Configuration;
entity.Property(p => p.Issuer)
.IsUnicode(false)
.HasMaxLength(200);
}
public class PassportConfiguration : IEntityTypeConfiguration<Passport>
{
public void Configure(EntityTypeBuilder<Passport> entity)
{
entity.Property(p => p.Number)
.IsUnicode(false)
.HasMaxLength(20);
entity.Property(p => p.Issuer)
.IsUnicode(false)
.HasMaxLength(200);
}
}
}

View File

@@ -2,21 +2,20 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration
namespace Infrastructure.Database.Applicants.Configuration;
public class PlaceOfWorkConfiguration : IEntityTypeConfiguration<PlaceOfWork>
{
public class PlaceOfWorkConfiguration : IEntityTypeConfiguration<PlaceOfWork>
public void Configure(EntityTypeBuilder<PlaceOfWork> entity)
{
public void Configure(EntityTypeBuilder<PlaceOfWork> entity)
{
entity.OwnsOne(p => p.Address);
entity.OwnsOne(p => p.Address);
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(200);
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(200);
entity.Property(p => p.PhoneNum)
.IsUnicode(false)
.HasMaxLength(20);
}
entity.Property(p => p.PhoneNum)
.IsUnicode(false)
.HasMaxLength(20);
}
}
}

View File

@@ -2,21 +2,20 @@
using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Applicants.Repositories
namespace Infrastructure.Database.Applicants.Repositories;
/// Repository pattern for <see cref="Applicant"/>
/// <param name="reader"><inheritdoc cref="IGenericReader"/></param>
/// <param name="writer"><inheritdoc cref="IGenericWriter"/></param>
/// <param name="unitOfWork"><inheritdoc cref="IUnitOfWork"/></param>
public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<Applicant>(reader, writer, unitOfWork), IApplicantsRepository
{
/// Repository pattern for <see cref="Applicant"/>
/// <param name="reader"><inheritdoc cref="IGenericReader"/></param>
/// <param name="writer"><inheritdoc cref="IGenericWriter"/></param>
/// <param name="unitOfWork"><inheritdoc cref="IUnitOfWork"/></param>
public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<Applicant>(reader, writer, unitOfWork), IApplicantsRepository
protected override IQueryable<Applicant> LoadDomain()
{
protected override IQueryable<Applicant> LoadDomain()
{
return base.LoadDomain()
.Include(a => a.CountryOfBirth)
.Include(a => a.CityOfBirth)
.Include(a => a.PlaceOfWork);
}
return base.LoadDomain()
.Include(a => a.CountryOfBirth)
.Include(a => a.CityOfBirth)
.Include(a => a.PlaceOfWork);
}
}
}

View File

@@ -1,8 +1,7 @@
using Domains.ApplicantDomain;
using Infrastructure.Database.Generic;
namespace Infrastructure.Database.Applicants.Repositories
{
/// Repository pattern for <see cref="Applicant"/>
public interface IApplicantsRepository : IGenericRepository<Applicant> { }
}
namespace Infrastructure.Database.Applicants.Repositories;
/// Repository pattern for <see cref="Applicant"/>
public interface IApplicantsRepository : IGenericRepository<Applicant> { }

View File

@@ -2,39 +2,38 @@
using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database
namespace Infrastructure.Database;
public class DbContext(DbContextOptions<DbContext> opts)
: Microsoft.EntityFrameworkCore.DbContext(opts), IGenericWriter, IGenericReader, IUnitOfWork
{
public class DbContext(DbContextOptions<DbContext> opts)
: Microsoft.EntityFrameworkCore.DbContext(opts), IGenericWriter, IGenericReader, IUnitOfWork
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}
async Task IGenericWriter.AddAsync<T>(T entity, CancellationToken cancellationToken)
{
await AddAsync(entity, cancellationToken);
}
void IGenericWriter.Update<T>(T entity)
{
Update(entity);
}
void IGenericWriter.Remove<T>(T entity)
{
Remove(entity);
}
IQueryable<T> IGenericReader.GetAll<T>()
{
return Set<T>();
}
async Task IUnitOfWork.SaveAsync(CancellationToken cancellationToken)
{
await SaveChangesAsync(cancellationToken);
}
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}
}
async Task IGenericWriter.AddAsync<T>(T entity, CancellationToken cancellationToken)
{
await AddAsync(entity, cancellationToken);
}
void IGenericWriter.Update<T>(T entity)
{
Update(entity);
}
void IGenericWriter.Remove<T>(T entity)
{
Remove(entity);
}
IQueryable<T> IGenericReader.GetAll<T>()
{
return Set<T>();
}
async Task IUnitOfWork.SaveAsync(CancellationToken cancellationToken)
{
await SaveChangesAsync(cancellationToken);
}
}

View File

@@ -1,10 +1,9 @@
using Domains;
namespace Infrastructure.Database.GeneralExceptions
{
/// Exception to throw when entity with specific id not found
/// <param name="id">Identifier of entity</param>
/// <typeparam name="T">Not found entity type</typeparam>
public class EntityNotFoundException<T>(Guid id) : Exception($"Entity {typeof(T).Name} with id '{id}' not found")
where T : class, IEntity;
}
namespace Infrastructure.Database.GeneralExceptions;
/// Exception to throw when entity with specific id not found
/// <param name="id">Identifier of entity</param>
/// <typeparam name="T">Not found entity type</typeparam>
public class EntityNotFoundException<T>(Guid id) : Exception($"Entity {typeof(T).Name} with id '{id}' not found")
where T : class, IEntity;

View File

@@ -2,52 +2,51 @@
using Infrastructure.Database.GeneralExceptions;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Generic
namespace Infrastructure.Database.Generic;
/// Generic repository pattern
/// <param name="writer"><inheritdoc cref="IGenericWriter"/></param>
/// <param name="unitOfWork"><inheritdoc cref="IUnitOfWork"/></param>
/// <typeparam name="T">Type of entity</typeparam>
/// <remarks>Should be inherited to create typed repositories</remarks>
public abstract class GenericRepository<T>(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) : IGenericRepository<T>
where T : class, IEntity
{
/// Generic repository pattern
/// <param name="writer"><inheritdoc cref="IGenericWriter"/></param>
/// <param name="unitOfWork"><inheritdoc cref="IUnitOfWork"/></param>
/// <typeparam name="T">Type of entity</typeparam>
/// <remarks>Should be inherited to create typed repositories</remarks>
public abstract class GenericRepository<T>(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) : IGenericRepository<T>
where T : class, IEntity
/// <inheritdoc cref="IGenericRepository{T}.GetAllAsync"/>
public async Task<List<T>> GetAllAsync(CancellationToken cancellationToken)
=> await LoadDomain().ToListAsync(cancellationToken);
/// <inheritdoc cref="IGenericRepository{T}.GetOneAsync"/>
public async Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken)
{
/// <inheritdoc cref="IGenericRepository{T}.GetAllAsync"/>
public async Task<List<T>> GetAllAsync(CancellationToken cancellationToken)
=> await LoadDomain().ToListAsync(cancellationToken);
/// <inheritdoc cref="IGenericRepository{T}.GetOneAsync"/>
public async Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken)
{
var result = await LoadDomain().SingleOrDefaultAsync(a => a.Id == id, cancellationToken);
return result ?? throw new EntityNotFoundException<T>(id);
}
/// <inheritdoc cref="IGenericRepository{T}.AddAsync"/>
public async Task AddAsync(T entity, CancellationToken cancellationToken)
=> await writer.AddAsync(entity, cancellationToken);
/// <inheritdoc cref="IGenericRepository{T}.UpdateAsync"/>
public async Task UpdateAsync(T entity, CancellationToken cancellationToken)
{
await GetOneAsync(entity.Id, cancellationToken);
writer.Update(entity);
}
/// <inheritdoc cref="IGenericRepository{T}.Remove"/>
public void Remove(T entity)
{
writer.Remove(entity);
}
/// <inheritdoc cref="IGenericRepository{T}.SaveAsync"/>
public async Task SaveAsync(CancellationToken cancellationToken)
=> await unitOfWork.SaveAsync(cancellationToken);
/// Should be overriden to load navigation properties of entity
protected virtual IQueryable<T> LoadDomain()
{
return reader.GetAll<T>();
}
var result = await LoadDomain().SingleOrDefaultAsync(a => a.Id == id, cancellationToken);
return result ?? throw new EntityNotFoundException<T>(id);
}
}
/// <inheritdoc cref="IGenericRepository{T}.AddAsync"/>
public async Task AddAsync(T entity, CancellationToken cancellationToken)
=> await writer.AddAsync(entity, cancellationToken);
/// <inheritdoc cref="IGenericRepository{T}.UpdateAsync"/>
public async Task UpdateAsync(T entity, CancellationToken cancellationToken)
{
await GetOneAsync(entity.Id, cancellationToken);
writer.Update(entity);
}
/// <inheritdoc cref="IGenericRepository{T}.Remove"/>
public void Remove(T entity)
{
writer.Remove(entity);
}
/// <inheritdoc cref="IGenericRepository{T}.SaveAsync"/>
public async Task SaveAsync(CancellationToken cancellationToken)
=> await unitOfWork.SaveAsync(cancellationToken);
/// Should be overriden to load navigation properties of entity
protected virtual IQueryable<T> LoadDomain()
{
return reader.GetAll<T>();
}
}

View File

@@ -1,12 +1,11 @@
using Domains;
namespace Infrastructure.Database.Generic
namespace Infrastructure.Database.Generic;
/// Reads from data storage
public interface IGenericReader
{
/// Reads from data storage
public interface IGenericReader
{
/// Get all entities of type T stored in storage
/// <typeparam name="T">Entity type to seek in storage</typeparam>
IQueryable<T> GetAll<T>() where T : class, IEntity;
}
}
/// Get all entities of type T stored in storage
/// <typeparam name="T">Entity type to seek in storage</typeparam>
IQueryable<T> GetAll<T>() where T : class, IEntity;
}

View File

@@ -1,37 +1,36 @@
using Domains;
namespace Infrastructure.Database.Generic
namespace Infrastructure.Database.Generic;
/// <summary>
/// Generic repository pattern
/// </summary>
/// <typeparam name="T">Entity type</typeparam>
public interface IGenericRepository<T> where T : class, IEntity
{
/// Get all entities from data storage
Task<List<T>> GetAllAsync(CancellationToken cancellationToken);
/// Get one entity with specific id
/// <param name="id">Identifier of entity</param>
Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken);
/// Add entity to storage
/// <param name="entity">Entity to add</param>
Task AddAsync(T entity, CancellationToken cancellationToken);
/// <summary>
/// Generic repository pattern
/// Update entity in storage
/// </summary>
/// <typeparam name="T">Entity type</typeparam>
public interface IGenericRepository<T> where T : class, IEntity
{
/// Get all entities from data storage
Task<List<T>> GetAllAsync(CancellationToken cancellationToken);
/// <param name="entity">Entity to update</param>
Task UpdateAsync(T entity, CancellationToken cancellationToken);
/// Get one entity with specific id
/// <param name="id">Identifier of entity</param>
Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken);
/// <summary>
/// Remove entity from storage
/// </summary>
/// <param name="entity">Entity to remove</param>
void Remove(T entity);
/// Add entity to storage
/// <param name="entity">Entity to add</param>
Task AddAsync(T entity, CancellationToken cancellationToken);
/// <summary>
/// Update entity in storage
/// </summary>
/// <param name="entity">Entity to update</param>
Task UpdateAsync(T entity, CancellationToken cancellationToken);
/// <summary>
/// Remove entity from storage
/// </summary>
/// <param name="entity">Entity to remove</param>
void Remove(T entity);
/// Save changes in storage
Task SaveAsync(CancellationToken cancellationToken);
}
}
/// Save changes in storage
Task SaveAsync(CancellationToken cancellationToken);
}

View File

@@ -1,25 +1,24 @@
using Domains;
namespace Infrastructure.Database.Generic
namespace Infrastructure.Database.Generic;
/// Writes data to data storage
/// <remarks><see cref="IUnitOfWork"/> should be used to save changes</remarks>
public interface IGenericWriter
{
/// Writes data to data storage
/// <remarks><see cref="IUnitOfWork"/> should be used to save changes</remarks>
public interface IGenericWriter
{
/// Add entity to data storage
/// <param name="entity">Entity to add</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <typeparam name="T">Entity type</typeparam>
Task AddAsync<T>(T entity, CancellationToken cancellationToken) where T : class, IEntity;
/// Add entity to data storage
/// <param name="entity">Entity to add</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <typeparam name="T">Entity type</typeparam>
Task AddAsync<T>(T entity, CancellationToken cancellationToken) where T : class, IEntity;
/// Update entity in data storage
/// <param name="entity">Entity to update</param>
/// <typeparam name="T">Entity type</typeparam>
void Update<T>(T entity) where T : class, IEntity;
/// Update entity in data storage
/// <param name="entity">Entity to update</param>
/// <typeparam name="T">Entity type</typeparam>
void Update<T>(T entity) where T : class, IEntity;
/// Remove entity from data storage
/// <param name="entity">Entity to remove</param>
/// <typeparam name="T">Entity type</typeparam>
void Remove<T>(T entity) where T : class, IEntity;
}
}
/// Remove entity from data storage
/// <param name="entity">Entity to remove</param>
/// <typeparam name="T">Entity type</typeparam>
void Remove<T>(T entity) where T : class, IEntity;
}

View File

@@ -1,9 +1,8 @@
namespace Infrastructure.Database
namespace Infrastructure.Database;
public interface IUnitOfWork
{
public interface IUnitOfWork
{
/// Saves changes in data storage
/// <param name="cancellationToken">Cancellation Token</param>
Task SaveAsync(CancellationToken cancellationToken);
}
}
/// Saves changes in data storage
/// <param name="cancellationToken">Cancellation Token</param>
Task SaveAsync(CancellationToken cancellationToken);
}

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Locations.Configuration
namespace Infrastructure.Database.Locations.Configuration;
public class CityConfiguration : IEntityTypeConfiguration<City>
{
public class CityConfiguration : IEntityTypeConfiguration<City>
public void Configure(EntityTypeBuilder<City> entity)
{
public void Configure(EntityTypeBuilder<City> entity)
{
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
}
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
}
}
}

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Locations.Configuration
namespace Infrastructure.Database.Locations.Configuration;
public class CountryConfiguration : IEntityTypeConfiguration<Country>
{
public class CountryConfiguration : IEntityTypeConfiguration<Country>
public void Configure(EntityTypeBuilder<Country> entity)
{
public void Configure(EntityTypeBuilder<Country> entity)
{
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
}
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
}
}
}

View File

@@ -2,14 +2,13 @@
using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Locations.Repositories.Cities
namespace Infrastructure.Database.Locations.Repositories.Cities;
public sealed class CitiesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<City>(reader, writer, unitOfWork), ICitiesRepository
{
public sealed class CitiesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<City>(reader, writer, unitOfWork), ICitiesRepository
protected override IQueryable<City> LoadDomain()
{
protected override IQueryable<City> LoadDomain()
{
return base.LoadDomain().Include(c => c.Country);
}
return base.LoadDomain().Include(c => c.Country);
}
}
}

View File

@@ -1,7 +1,6 @@
using Domains.LocationDomain;
using Infrastructure.Database.Generic;
namespace Infrastructure.Database.Locations.Repositories.Cities
{
public interface ICitiesRepository : IGenericRepository<City> { }
}
namespace Infrastructure.Database.Locations.Repositories.Cities;
public interface ICitiesRepository : IGenericRepository<City> { }

View File

@@ -2,14 +2,13 @@
using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Locations.Repositories.Countries
namespace Infrastructure.Database.Locations.Repositories.Countries;
public sealed class CountriesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<Country>(reader, writer, unitOfWork), ICountriesRepository
{
public sealed class CountriesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<Country>(reader, writer, unitOfWork), ICountriesRepository
protected override IQueryable<Country> LoadDomain()
{
protected override IQueryable<Country> LoadDomain()
{
return base.LoadDomain().Include(c => c.Cities);
}
return base.LoadDomain().Include(c => c.Cities);
}
}
}

View File

@@ -1,7 +1,6 @@
using Domains.LocationDomain;
using Infrastructure.Database.Generic;
namespace Infrastructure.Database.Locations.Repositories.Countries
{
public interface ICountriesRepository : IGenericRepository<Country> { }
}
namespace Infrastructure.Database.Locations.Repositories.Countries;
public interface ICountriesRepository : IGenericRepository<Country> { }

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.VisaApplications.Configuration
namespace Infrastructure.Database.VisaApplications.Configuration;
public class PastVisaConfiguration : IEntityTypeConfiguration<PastVisa>
{
public class PastVisaConfiguration : IEntityTypeConfiguration<PastVisa>
public void Configure(EntityTypeBuilder<PastVisa> entity)
{
public void Configure(EntityTypeBuilder<PastVisa> entity)
{
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
}
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
}
}
}

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.VisaApplications.Configuration
namespace Infrastructure.Database.VisaApplications.Configuration;
public class PermissionToDestCountryConfiguration : IEntityTypeConfiguration<PermissionToDestCountry>
{
public class PermissionToDestCountryConfiguration : IEntityTypeConfiguration<PermissionToDestCountry>
public void Configure(EntityTypeBuilder<PermissionToDestCountry> entity)
{
public void Configure(EntityTypeBuilder<PermissionToDestCountry> entity)
{
entity.Property(p => p.Issuer)
.IsUnicode(false)
.HasMaxLength(200);
}
entity.Property(p => p.Issuer)
.IsUnicode(false)
.HasMaxLength(200);
}
}
}

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.VisaApplications.Configuration
namespace Infrastructure.Database.VisaApplications.Configuration;
public class ReentryPermitConfiguration : IEntityTypeConfiguration<ReentryPermit>
{
public class ReentryPermitConfiguration : IEntityTypeConfiguration<ReentryPermit>
public void Configure(EntityTypeBuilder<ReentryPermit> entity)
{
public void Configure(EntityTypeBuilder<ReentryPermit> entity)
{
entity.Property(p => p.Number)
.IsUnicode(false)
.HasMaxLength(25);
}
entity.Property(p => p.Number)
.IsUnicode(false)
.HasMaxLength(25);
}
}
}

View File

@@ -2,21 +2,22 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.VisaApplications.Configuration
namespace Infrastructure.Database.VisaApplications.Configuration;
public class VisaApplicationConfiguration : IEntityTypeConfiguration<VisaApplication>
{
public class VisaApplicationConfiguration : IEntityTypeConfiguration<VisaApplication>
public void Configure(EntityTypeBuilder<VisaApplication> entity)
{
public void Configure(EntityTypeBuilder<VisaApplication> entity)
{
entity.ToTable("VisaApplications");
entity.ToTable("VisaApplications");
entity.HasOne(va => va.Applicant)
.WithMany(a => a.VisaApplications)
.HasForeignKey(va => va.ApplicantId)
.IsRequired();
entity.HasOne(va => va.Applicant)
.WithMany(a => a.VisaApplications)
.HasForeignKey(va => va.ApplicantId)
.IsRequired();
entity.OwnsOne(p => p.ReentryPermit);
entity.OwnsOne(p => p.PermissionToDestCountry);
}
entity.OwnsOne(p => p.ReentryPermit);
entity.OwnsOne(p => p.PermissionToDestCountry);
entity.OwnsMany(p => p.PastVisits).ToTable("PastVisits");
entity.OwnsMany(p => p.PastVisas).ToTable("PastVisas");
}
}

View File

@@ -1,7 +1,6 @@
using Domains.VisaApplicationDomain;
using Infrastructure.Database.Generic;
namespace Infrastructure.Database.VisaApplications.Repositories
{
public interface IVisaApplicationsRepository : IGenericRepository<VisaApplication> { }
}
namespace Infrastructure.Database.VisaApplications.Repositories;
public interface IVisaApplicationsRepository : IGenericRepository<VisaApplication> { }

View File

@@ -2,17 +2,16 @@
using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.VisaApplications.Repositories
namespace Infrastructure.Database.VisaApplications.Repositories;
public sealed class VisaApplicationsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<VisaApplication>(reader, writer, unitOfWork), IVisaApplicationsRepository
{
public sealed class VisaApplicationsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<VisaApplication>(reader, writer, unitOfWork), IVisaApplicationsRepository
protected override IQueryable<VisaApplication> LoadDomain()
{
protected override IQueryable<VisaApplication> LoadDomain()
{
return base.LoadDomain()
.Include(a => a.DestinationCountry)
.Include(a => a.PastVisas)
.Include(a => a.PastVisits);
}
return base.LoadDomain()
.Include(a => a.DestinationCountry)
.Include(a => a.PastVisas)
.Include(a => a.PastVisits);
}
}
}