Добавьте файлы проекта.
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ApplicationSystem.Configurations.Configurations
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры подключение базы данных
|
||||
/// </summary>
|
||||
public class ConnectionStringsConfiguration
|
||||
{
|
||||
[Required(AllowEmptyStrings = false)]
|
||||
public string ApplicationDatabase { get; init; } = null!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,39 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
using ApplicationSystem.Database.Applications.Database.Context.Configurations;
|
||||
using ApplicationSystem.Database.Applications.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#nullable disable
|
||||
|
||||
namespace ApplicationSystem.Database.Applications.Database.Context;
|
||||
|
||||
public partial class ApplicationContext : DbContext
|
||||
{
|
||||
public ApplicationContext()
|
||||
{
|
||||
}
|
||||
|
||||
public ApplicationContext(DbContextOptions<ApplicationContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual DbSet<Application> Applications { get; set; }
|
||||
|
||||
public virtual DbSet<ApplicationType> ApplicationTypes { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
|
||||
=> optionsBuilder.UseSqlServer("Data Source=localhost,6001;Initial Catalog=application_system_application;Persist Security Info=True;User ID=sa;Password=Jf5R0Ob4v!");
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.ApplyConfiguration(new Configurations.ApplicationConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new Configurations.ApplicationTypeConfiguration());
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
using ApplicationSystem.Database.Applications.Database.Context;
|
||||
using ApplicationSystem.Database.Applications.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ApplicationSystem.Database.Applications.Database.Context.Configurations
|
||||
{
|
||||
public partial class ApplicationConfiguration : IEntityTypeConfiguration<Application>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Application> entity)
|
||||
{
|
||||
entity.Property(e => e.Deleted).HasDefaultValueSql("(NULL)");
|
||||
|
||||
entity.HasOne(d => d.Type).WithMany(p => p.Applications).HasConstraintName("FK_application_type_id");
|
||||
|
||||
OnConfigurePartial(entity);
|
||||
}
|
||||
|
||||
partial void OnConfigurePartial(EntityTypeBuilder<Application> entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
using ApplicationSystem.Database.Applications.Database.Context;
|
||||
using ApplicationSystem.Database.Applications.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ApplicationSystem.Database.Applications.Database.Context.Configurations
|
||||
{
|
||||
public partial class ApplicationTypeConfiguration : IEntityTypeConfiguration<ApplicationType>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ApplicationType> entity)
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PK_application_type_id");
|
||||
|
||||
entity.Property(e => e.Id).ValueGeneratedNever();
|
||||
|
||||
OnConfigurePartial(entity);
|
||||
}
|
||||
|
||||
partial void OnConfigurePartial(EntityTypeBuilder<ApplicationType> entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApplicationSystem.Database.Applications.Database.Models;
|
||||
|
||||
[PrimaryKey("Id", "Updated")]
|
||||
[Table("application")]
|
||||
public partial class Application
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[Key]
|
||||
[Column("updated")]
|
||||
public DateTime Updated { get; set; }
|
||||
|
||||
[Column("deleted")]
|
||||
public DateTime? Deleted { get; set; }
|
||||
|
||||
[Required]
|
||||
[Column("text")]
|
||||
[StringLength(1000)]
|
||||
public string Text { get; set; }
|
||||
|
||||
[Column("status")]
|
||||
public int Status { get; set; }
|
||||
|
||||
[Column("type_id")]
|
||||
public Guid TypeId { get; set; }
|
||||
|
||||
[ForeignKey("TypeId")]
|
||||
[InverseProperty("Applications")]
|
||||
public virtual ApplicationType Type { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApplicationSystem.Database.Applications.Database.Models;
|
||||
|
||||
[Table("application_type")]
|
||||
public partial class ApplicationType
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[Column("name")]
|
||||
[StringLength(50)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[InverseProperty("Type")]
|
||||
public virtual ICollection<Application> Applications { get; set; } = new List<Application>();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace ApplicationSystem.Database.Models.Interfaces
|
||||
{
|
||||
public interface IEntity : IId, IUpdated, IDeleted
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace ApplicationSystem.Database.Models.Interfaces
|
||||
{
|
||||
public interface IDeleted
|
||||
{
|
||||
DateTime DeletedTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace ApplicationSystem.Database.Models.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель с идентификатором
|
||||
/// </summary>
|
||||
public interface IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор сущности
|
||||
/// </summary>
|
||||
Guid Id { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace ApplicationSystem.Database.Models.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель с поддержкой мягкого изменения
|
||||
/// </summary>
|
||||
public interface IUpdated
|
||||
{
|
||||
/// <summary>
|
||||
/// Время изменения
|
||||
/// </summary>
|
||||
DateTime UpdatedTime { get; set; }
|
||||
}
|
||||
}
|
||||
44
ApplicationSystem.Database.Applications/Models/Pagination.cs
Normal file
44
ApplicationSystem.Database.Applications/Models/Pagination.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
namespace ApplicationSystem.Database.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Страничное представление данных
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel"></typeparam>
|
||||
public class Pagination<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Текущая страница
|
||||
/// </summary>
|
||||
public int CurrentPage { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Размер страницы
|
||||
/// </summary>
|
||||
public int PageSize { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Всего сущностей
|
||||
/// </summary>
|
||||
public int TotalCount { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Всего страниц
|
||||
/// </summary>
|
||||
public int TotalPages => (TotalCount + PageSize - 1) / PageSize;
|
||||
|
||||
/// <summary>
|
||||
/// Флаг наличия предыдущей страницы
|
||||
/// </summary>
|
||||
public bool HasRevues => CurrentPage > 1;
|
||||
|
||||
/// <summary>
|
||||
/// Флаг наличия следующей страницы
|
||||
/// </summary>
|
||||
public bool HasNext => CurrentPage * PageSize < TotalCount;
|
||||
|
||||
/// <summary>
|
||||
/// Данные текущей страницы
|
||||
/// </summary>
|
||||
public List<TModel> Items { get; init; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using ApplicationSystem.Database.Models;
|
||||
using ApplicationSystem.Database.Models.Interfaces;
|
||||
using ApplicationSystem.Database.Services.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ApplicationSystem.Database.Services.Implementations
|
||||
{
|
||||
public abstract class AbstractRepository<TEntity, TEntityDto>()
|
||||
: IRepository<TEntity, TEntityDto> where TEntity : class, IEntity where TEntityDto : class
|
||||
{
|
||||
protected IQueryable<TEntity> _entities = null!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<int> CountAsync(
|
||||
Expression<Func<TEntity, bool>> expression,
|
||||
CancellationToken cancellationToken)
|
||||
=> await _entities
|
||||
.CountAsync(expression, cancellationToken);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<TEntityDto?> GetAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _entities.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return await MapEntity(entity, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<Pagination<TEntityDto>> GetAsync(
|
||||
Expression<Func<TEntity, bool>> expression,
|
||||
int pageNumber = 1,
|
||||
int pageSize = 100,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (pageNumber < 1 || pageSize < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Неверные параметры страницы");
|
||||
}
|
||||
|
||||
var query = _entities.Where(expression);
|
||||
|
||||
return await MapEntityList(query, pageNumber, pageSize, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<Pagination<TEntityDto>> GetAsync(
|
||||
int pageNumber = 1,
|
||||
int pageSize = 100,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (pageNumber < 1 || pageSize < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Неверные параметры страницы");
|
||||
}
|
||||
|
||||
return await MapEntityList(_entities, pageNumber, pageSize, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<TEntityDto?> DeleteAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _entities.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
entity.DeletedTime = DateTime.UtcNow;
|
||||
entity.UpdatedTime = DateTime.UtcNow;
|
||||
|
||||
await AddAsync(entity, cancellationToken);
|
||||
|
||||
return await MapEntity(entity, cancellationToken);
|
||||
}
|
||||
|
||||
public abstract Task<TEntityDto?> UpdateAsync(
|
||||
TEntityDto newValue,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
protected abstract Task<TEntityDto> MapEntity(
|
||||
TEntity entity,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
protected abstract Task<TEntity> MapEntity(
|
||||
TEntityDto entity,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
protected abstract Task<Pagination<TEntityDto>> MapEntityList(
|
||||
IQueryable<TEntity> entity,
|
||||
int pageNumber,
|
||||
int pageSize,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
protected abstract Task AddAsync(TEntity entity, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using ApplicationSystem.Database.Models;
|
||||
using ApplicationSystem.Database.Models.Interfaces;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ApplicationSystem.Database.Services.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Репозиторий для взаимодействия c с сущностями бд
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <typeparam name="TEntityDto"></typeparam>
|
||||
public interface IRepository<TEntity, TEntityDto>
|
||||
where TEntity : class, IEntity
|
||||
where TEntityDto : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить сущность по ключу
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<TEntityDto?> GetAsync(Guid id, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Получить список сущностей удовлетворяющих условию
|
||||
/// </summary>
|
||||
/// <param name="expression"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<TEntityDto>> GetAsync(
|
||||
Expression<Func<TEntity, bool>> expression,
|
||||
int page = 1,
|
||||
int pageSize = 100,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Получить список сущностей
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<TEntityDto>> GetAsync(
|
||||
int page = 1,
|
||||
int pageSize = 100,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Количество сущностей удовлетворяющих условию
|
||||
/// </summary>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> CountAsync(
|
||||
Expression<Func<TEntity, bool>> expression,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Обновить сущность
|
||||
/// </summary>
|
||||
/// <param name="newValue"></param>
|
||||
/// <returns></returns>
|
||||
Task<TEntityDto?> UpdateAsync(
|
||||
TEntityDto newValue,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить сущность
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<TEntityDto?> DeleteAsync(
|
||||
Guid id,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
50
ApplicationSystem.Database.Applications/efpt.config.json
Normal file
50
ApplicationSystem.Database.Applications/efpt.config.json
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"CodeGenerationMode": 4,
|
||||
"ContextClassName": "ApplicationContext",
|
||||
"ContextNamespace": null,
|
||||
"FilterSchemas": false,
|
||||
"IncludeConnectionString": true,
|
||||
"ModelNamespace": null,
|
||||
"OutputContextPath": "Database\/Context",
|
||||
"OutputPath": "Database\/Models",
|
||||
"PreserveCasingWithRegex": true,
|
||||
"ProjectRootNamespace": "ApplicationSystem.Database.Applications",
|
||||
"Schemas": null,
|
||||
"SelectedHandlebarsLanguage": 2,
|
||||
"SelectedToBeGenerated": 0,
|
||||
"T4TemplatePath": null,
|
||||
"Tables": [
|
||||
{
|
||||
"Name": "[dbo].[application]",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "[dbo].[application_type]",
|
||||
"ObjectType": 0
|
||||
}
|
||||
],
|
||||
"UiHint": null,
|
||||
"UncountableWords": null,
|
||||
"UseAsyncStoredProcedureCalls": true,
|
||||
"UseBoolPropertiesWithoutDefaultSql": false,
|
||||
"UseDatabaseNames": false,
|
||||
"UseDateOnlyTimeOnly": true,
|
||||
"UseDbContextSplitting": true,
|
||||
"UseDecimalDataAnnotationForSprocResult": true,
|
||||
"UseFluentApiOnly": false,
|
||||
"UseHandleBars": false,
|
||||
"UseHierarchyId": false,
|
||||
"UseInflector": true,
|
||||
"UseLegacyPluralizer": false,
|
||||
"UseManyToManyEntity": false,
|
||||
"UseNoDefaultConstructor": false,
|
||||
"UseNoNavigations": false,
|
||||
"UseNoObjectFilter": false,
|
||||
"UseNodaTime": false,
|
||||
"UseNullableReferences": false,
|
||||
"UsePrefixNavigationNaming": false,
|
||||
"UseSchemaFolders": false,
|
||||
"UseSchemaNamespaces": false,
|
||||
"UseSpatial": false,
|
||||
"UseT4": false
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.15" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,103 @@
|
||||
using ApplicationSystem.Database.Contracts.Models;
|
||||
using ApplicationSystem.Database.Contracts.Models.Interfaces;
|
||||
using ApplicationSystem.Database.Contracts.Services.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ApplicationSystem.Database.Contracts.Services.Implementations
|
||||
{
|
||||
public abstract class AbstractRepository<TEntity, TEntityDto>()
|
||||
: IRepository<TEntity, TEntityDto> where TEntity : class, IEntity where TEntityDto : class
|
||||
{
|
||||
protected IQueryable<TEntity> _entities = null!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<int> CountAsync(
|
||||
Expression<Func<TEntity, bool>> expression,
|
||||
CancellationToken cancellationToken)
|
||||
=> await _entities
|
||||
.CountAsync(expression, cancellationToken);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<TEntityDto?> GetAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _entities.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return await MapEntity(entity, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<Pagination<TEntityDto>> GetAsync(
|
||||
Expression<Func<TEntity, bool>> expression,
|
||||
int pageNumber = 1,
|
||||
int pageSize = 100,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (pageNumber < 1 || pageSize < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Неверные параметры страницы");
|
||||
}
|
||||
|
||||
var query = _entities.Where(expression);
|
||||
|
||||
return await MapEntityList(query, pageNumber, pageSize, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<Pagination<TEntityDto>> GetAsync(
|
||||
int pageNumber = 1,
|
||||
int pageSize = 100,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (pageNumber < 1 || pageSize < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Неверные параметры страницы");
|
||||
}
|
||||
|
||||
return await MapEntityList(_entities, pageNumber, pageSize, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<TEntityDto?> DeleteAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _entities.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
entity.DeletedTime = DateTime.UtcNow;
|
||||
entity.UpdatedTime = DateTime.UtcNow;
|
||||
|
||||
await AddAsync(entity, cancellationToken);
|
||||
|
||||
return await MapEntity(entity, cancellationToken);
|
||||
}
|
||||
|
||||
public abstract Task<TEntityDto?> UpdateAsync(
|
||||
TEntityDto newValue,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
protected abstract Task<TEntityDto> MapEntity(
|
||||
TEntity entity,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
protected abstract Task<TEntity> MapEntity(
|
||||
TEntityDto entity,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
protected abstract Task<Pagination<TEntityDto>> MapEntityList(
|
||||
IQueryable<TEntity> entity,
|
||||
int pageNumber,
|
||||
int pageSize,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
protected abstract Task AddAsync(TEntity entity, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using ApplicationSystem.Database.Contracts.Models;
|
||||
using ApplicationSystem.Database.Contracts.Models.Interfaces;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ApplicationSystem.Database.Contracts.Services.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Репозиторий для взаимодействия c с сущностями бд
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <typeparam name="TEntityDto"></typeparam>
|
||||
public interface IRepository<TEntity, TEntityDto>
|
||||
where TEntity : class, IEntity
|
||||
where TEntityDto : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить сущность по ключу
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<TEntityDto?> GetAsync(Guid id, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Получить список сущностей удовлетворяющих условию
|
||||
/// </summary>
|
||||
/// <param name="expression"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<TEntityDto>> GetAsync(
|
||||
Expression<Func<TEntity, bool>> expression,
|
||||
int page = 1,
|
||||
int pageSize = 100,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Получить список сущностей
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<TEntityDto>> GetAsync(
|
||||
int page = 1,
|
||||
int pageSize = 100,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Количество сущностей удовлетворяющих условию
|
||||
/// </summary>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> CountAsync(
|
||||
Expression<Func<TEntity, bool>> expression,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Обновить сущность
|
||||
/// </summary>
|
||||
/// <param name="newValue"></param>
|
||||
/// <returns></returns>
|
||||
Task<TEntityDto?> UpdateAsync(
|
||||
TEntityDto newValue,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить сущность
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<TEntityDto?> DeleteAsync(
|
||||
Guid id,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
25
ApplicationSystem.Identity/ApplicationSystem.Identity.csproj
Normal file
25
ApplicationSystem.Identity/ApplicationSystem.Identity.csproj
Normal file
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ApplicationSystem.Configurations\ApplicationSystem.Configurations.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Database\Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,33 @@
|
||||
using ApplicationSystem.Identity.Database.Models;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApplicationSystem.Identity.Database.Context
|
||||
{
|
||||
public class IdentityContext : IdentityDbContext<
|
||||
ApplicationSystemUser,
|
||||
ApplicationSystemRole,
|
||||
Guid,
|
||||
IdentityUserClaim<Guid>,
|
||||
IdentityUserRole<Guid>,
|
||||
IdentityUserLogin<Guid>,
|
||||
IdentityRoleClaim<Guid>,
|
||||
IdentityUserToken<Guid>>
|
||||
{
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.HasDefaultSchema("identity");
|
||||
|
||||
builder.Entity<ApplicationSystemUser>().ToTable("user");
|
||||
builder.Entity<ApplicationSystemRole>().ToTable("role");
|
||||
builder.Entity<IdentityUserClaim<Guid>>().ToTable("user_claim");
|
||||
builder.Entity<IdentityUserRole<Guid>>().ToTable("user_role");
|
||||
builder.Entity<IdentityUserLogin<Guid>>().ToTable("user_login");
|
||||
builder.Entity<IdentityRoleClaim<Guid>>().ToTable("role_claim");
|
||||
builder.Entity<IdentityUserToken<Guid>>().ToTable("user_token");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace ApplicationSystem.Identity.Database.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель роли пользователя
|
||||
/// </summary>
|
||||
public class ApplicationSystemRole : IdentityRole<Guid>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace ApplicationSystem.Identity.Database.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель пользователя
|
||||
/// </summary>
|
||||
public class ApplicationSystemUser : IdentityUser<Guid>
|
||||
{
|
||||
}
|
||||
}
|
||||
34
ApplicationSystem.Identity/Extensions/DiExtensions.cs
Normal file
34
ApplicationSystem.Identity/Extensions/DiExtensions.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using ApplicationSystem.Identity.Database.Context;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ApplicationSystem.Configurations.Configurations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ApplicationSystem.Identity.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Расширения инверсии зависимостей для подключения ролевой системы
|
||||
/// </summary>
|
||||
public static class DiExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавить базу данных ролевой системы
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddApplicationSystemIdentityDatabase(this IServiceCollection services)
|
||||
{
|
||||
services.AddOptions<ConnectionStringsConfiguration>();
|
||||
|
||||
services.AddDbContext<IdentityContext>((sp, opt) =>
|
||||
{
|
||||
var configuration = sp.GetRequiredService<IOptions<ConnectionStringsConfiguration>>().Value;
|
||||
|
||||
opt.UseSqlServer(configuration.ApplicationDatabase);
|
||||
opt.ConfigureWarnings(_ => { });
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
ApplicationSystem.Identity/Properties/launchSettings.json
Normal file
12
ApplicationSystem.Identity/Properties/launchSettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"ApplicationSystem.Identity": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:63049;http://localhost:63050"
|
||||
}
|
||||
}
|
||||
}
|
||||
43
ApplicationSystem.sln
Normal file
43
ApplicationSystem.sln
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.11.35327.3
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationSystem", "ApplicationSystem\ApplicationSystem.csproj", "{FBFAB28E-27E0-499F-9845-1E7499A1CB82}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationSystem.Database", "ApplicationSystem.Database.Applications\ApplicationSystem.Database.csproj", "{580C7B7A-E7EB-4718-A318-55DD20DFAEFB}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationSystem.Identity", "ApplicationSystem.Identity\ApplicationSystem.Identity.csproj", "{73E95BBE-82B6-4DD6-BA95-BC3A52E79394}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplicationSystem.Configurations", "ApplicationSystem.Configurations\ApplicationSystem.Configurations.csproj", "{F8BF79B4-B8C9-4A31-A9C7-4C1AB4C66E76}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FBFAB28E-27E0-499F-9845-1E7499A1CB82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FBFAB28E-27E0-499F-9845-1E7499A1CB82}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FBFAB28E-27E0-499F-9845-1E7499A1CB82}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FBFAB28E-27E0-499F-9845-1E7499A1CB82}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{580C7B7A-E7EB-4718-A318-55DD20DFAEFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{580C7B7A-E7EB-4718-A318-55DD20DFAEFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{580C7B7A-E7EB-4718-A318-55DD20DFAEFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{580C7B7A-E7EB-4718-A318-55DD20DFAEFB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{73E95BBE-82B6-4DD6-BA95-BC3A52E79394}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{73E95BBE-82B6-4DD6-BA95-BC3A52E79394}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{73E95BBE-82B6-4DD6-BA95-BC3A52E79394}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{73E95BBE-82B6-4DD6-BA95-BC3A52E79394}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F8BF79B4-B8C9-4A31-A9C7-4C1AB4C66E76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F8BF79B4-B8C9-4A31-A9C7-4C1AB4C66E76}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F8BF79B4-B8C9-4A31-A9C7-4C1AB4C66E76}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F8BF79B4-B8C9-4A31-A9C7-4C1AB4C66E76}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {9F778F2E-29FA-4398-8816-C76CA1E39212}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
14
ApplicationSystem/ApplicationSystem.csproj
Normal file
14
ApplicationSystem/ApplicationSystem.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>2c00b334-ff00-4c24-817a-6d2eb414b604</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
46
ApplicationSystem/Controllers/ApplicationController.cs
Normal file
46
ApplicationSystem/Controllers/ApplicationController.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ApplicationSystem.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class ApplicationController : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CreateApplicationAsync()
|
||||
{
|
||||
await Task.Delay(100);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetApplicationsAsync()
|
||||
{
|
||||
await Task.Delay(100);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> GetApplicationAsync([FromRoute] Guid id)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteApplicationAsync([FromRoute] Guid id)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost("{id}/status")]
|
||||
public async Task<IActionResult> UpdateApplicationStatusAsync([FromRoute] Guid id)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
6
ApplicationSystem/Program.cs
Normal file
6
ApplicationSystem/Program.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapGet("/", () => "Hello World!");
|
||||
|
||||
app.Run();
|
||||
38
ApplicationSystem/Properties/launchSettings.json
Normal file
38
ApplicationSystem/Properties/launchSettings.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:4737",
|
||||
"sslPort": 44306
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5053",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7164;http://localhost:5053",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
ApplicationSystem/appsettings.Development.json
Normal file
8
ApplicationSystem/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
ApplicationSystem/appsettings.json
Normal file
9
ApplicationSystem/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user