Подключение Microsoft.EntityFrameworkCore. Начало
This commit is contained in:
parent
5998d71562
commit
f22799f1ef
42
Persistence/Models/ChangeLogDto.cs
Normal file
42
Persistence/Models/ChangeLogDto.cs
Normal file
@ -0,0 +1,42 @@
|
||||
namespace Persistence.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Часть записи описывающая изменение
|
||||
/// </summary>
|
||||
public class ChangeLogDto<T> where T: class
|
||||
{
|
||||
/// <summary>
|
||||
/// Запись
|
||||
/// </summary>
|
||||
public required T Item { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Автор
|
||||
/// </summary>
|
||||
public UserDto? Author { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Автор
|
||||
/// </summary>
|
||||
public UserDto? Editor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата создания записи
|
||||
/// </summary>
|
||||
public DateTimeOffset Creation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата устаревания (например при удалении)
|
||||
/// </summary>
|
||||
public DateTimeOffset? Obsolete { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id состояния
|
||||
/// </summary>
|
||||
public int IdState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id заменяемой записи
|
||||
/// </summary>
|
||||
public int? IdPrevious { get; set; }
|
||||
}
|
62
Persistence/Models/IChangeLogAbstract.cs
Normal file
62
Persistence/Models/IChangeLogAbstract.cs
Normal file
@ -0,0 +1,62 @@
|
||||
namespace Persistence.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Часть записи описывающая изменение
|
||||
/// </summary>
|
||||
public interface IChangeLogAbstract
|
||||
{
|
||||
/// <summary>
|
||||
/// Актуальная
|
||||
/// </summary>
|
||||
public const int IdStateActual = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Замененная
|
||||
/// </summary>
|
||||
public const int IdStateReplaced = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Удаленная
|
||||
/// </summary>
|
||||
public const int IdStateDeleted = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Очищено при импорте
|
||||
/// </summary>
|
||||
public const int IdCleared = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Ид записи
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Автор изменения
|
||||
/// </summary>
|
||||
public int IdAuthor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Редактор
|
||||
/// </summary>
|
||||
public int? IdEditor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата создания записи
|
||||
/// </summary>
|
||||
public DateTimeOffset Creation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата устаревания (например при удалении)
|
||||
/// </summary>
|
||||
public DateTimeOffset? Obsolete { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная
|
||||
/// </summary>
|
||||
public int IdState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id заменяемой записи
|
||||
/// </summary>
|
||||
public int? IdPrevious { get; set; }
|
||||
}
|
66
Persistence/Models/UserDto.cs
Normal file
66
Persistence/Models/UserDto.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Persistence.Models;
|
||||
public class UserDto
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// логин
|
||||
/// </summary>
|
||||
public string Login { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Имя
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Фамилия
|
||||
/// </summary>
|
||||
public string? Surname { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Отчество
|
||||
/// </summary>
|
||||
public string? Patronymic { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Email
|
||||
/// </summary>
|
||||
public string Email { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Phone
|
||||
/// </summary>
|
||||
public string? Phone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Должность
|
||||
/// </summary>
|
||||
public string? Position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id компании
|
||||
/// </summary>
|
||||
public int IdCompany { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id состояния пользователя
|
||||
/// 0 - не активен,
|
||||
/// 1 - активен,
|
||||
/// 2 - заблокирован
|
||||
/// </summary>
|
||||
public short IdState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Получение отображаемого имени
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
}
|
@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,23 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Persistence.Models;
|
||||
|
||||
namespace Persistence.Repositories;
|
||||
public abstract class AbstractChangeLogRepository<T, TRequest> : IChangeLogRepository<T, TRequest>
|
||||
public abstract class AbstractChangeLogRepository<TEntity, TRequest, TDto> : IChangeLogRepository<TDto, TRequest>
|
||||
where TDto : class, new()
|
||||
where TEntity : class, IChangeLogAbstract
|
||||
{
|
||||
private readonly DbContext dbContext;
|
||||
|
||||
protected AbstractChangeLogRepository(DbContext dbContext)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
}
|
||||
public Task<int> Clear(int idUser, TRequest request, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<int> ClearAndInsertRange(int idUser, TRequest request, IEnumerable<T> dtos, CancellationToken token)
|
||||
public Task<int> ClearAndInsertRange(int idUser, TRequest request, IEnumerable<TDto> dtos, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IEnumerable<T>> GetCurrent(TRequest request, CancellationToken token)
|
||||
public Task<IEnumerable<TDto>> GetCurrent(TRequest request, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@ -27,27 +33,47 @@ public abstract class AbstractChangeLogRepository<T, TRequest> : IChangeLogRepos
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IEnumerable<T>> GetGtDate(DateTimeOffset date, CancellationToken token)
|
||||
public Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset date, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<int> InsertRange(int idUser, IEnumerable<T> dtos, CancellationToken token)
|
||||
public Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
this.dbContext.Set<TEntity>();
|
||||
var db = GetDataBase();
|
||||
using var transaction = db.BeginTransaction();
|
||||
try
|
||||
{
|
||||
//var result = await InsertRangeWithoutTransaction(idUser, dtos, token);
|
||||
//await transaction.CommitAsync(token);
|
||||
//return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
//await transaction.RollbackAsync(token);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract DatabaseFacade GetDataBase();
|
||||
|
||||
public Task<int> MarkAsDeleted(int idUser, IEnumerable<int> ids, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<int> UpdateOrInsertRange(int idUser, IEnumerable<T> dtos, CancellationToken token)
|
||||
public Task<int> UpdateOrInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<int> UpdateRange(int idUser, IEnumerable<T> dtos, CancellationToken token)
|
||||
public Task<int> UpdateRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLogForDate(TRequest request, DateOnly? date, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
namespace Persistence.Repositories;
|
||||
using Persistence.Models;
|
||||
|
||||
namespace Persistence.Repositories;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public interface IChangeLogRepository<T, TRequest> : ISyncRepository<T>
|
||||
/// <typeparam name="TDto"></typeparam>
|
||||
public interface IChangeLogRepository<TDto, TRequest> : ISyncRepository<TDto>
|
||||
where TDto : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавление записей
|
||||
@ -13,7 +16,7 @@ public interface IChangeLogRepository<T, TRequest> : ISyncRepository<T>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> InsertRange(int idUser, IEnumerable<T> dtos, CancellationToken token);
|
||||
Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Редактирование записей
|
||||
@ -22,7 +25,7 @@ public interface IChangeLogRepository<T, TRequest> : ISyncRepository<T>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> UpdateRange(int idUser, IEnumerable<T> dtos, CancellationToken token);
|
||||
Task<int> UpdateRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Добавляет Dto у которых id == 0, изменяет dto у которых id != 0
|
||||
@ -31,7 +34,7 @@ public interface IChangeLogRepository<T, TRequest> : ISyncRepository<T>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> UpdateOrInsertRange(int idUser, IEnumerable<T> dtos, CancellationToken token);
|
||||
Task<int> UpdateOrInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Помечает записи как удаленные
|
||||
@ -50,7 +53,7 @@ public interface IChangeLogRepository<T, TRequest> : ISyncRepository<T>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> ClearAndInsertRange(int idUser, TRequest request, IEnumerable<T> dtos, CancellationToken token);
|
||||
Task<int> ClearAndInsertRange(int idUser, TRequest request, IEnumerable<TDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Пометить записи как удаленные
|
||||
@ -76,7 +79,7 @@ public interface IChangeLogRepository<T, TRequest> : ISyncRepository<T>
|
||||
/// <param name="date">Фильтр по дате. Если null - вернет все записи, без привязки к дате</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
//Task<IEnumerable<ChangeLogDto<T>>> GetChangeLogForDate(TRequest request, DateOnly? date, CancellationToken token);
|
||||
Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLogForDate(TRequest request, DateOnly? date, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение текущих сейчас записей по параметрам
|
||||
@ -84,12 +87,5 @@ public interface IChangeLogRepository<T, TRequest> : ISyncRepository<T>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<T>> GetCurrent(TRequest request, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта, реализующего интерфейс IChangeLogRepositoryBuilder
|
||||
/// для последующих вызовов методов фильтрации по запросам
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//IChangeLogQueryBuilder<TDto, TRequest> GetQueryBuilder(ChangeLogRequest request);
|
||||
Task<IEnumerable<TDto>> GetCurrent(TRequest request, CancellationToken token);
|
||||
}
|
||||
|
@ -3,8 +3,8 @@
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public interface ISyncRepository<T>
|
||||
/// <typeparam name="TDto"></typeparam>
|
||||
public interface ISyncRepository<TDto>
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
@ -12,5 +12,5 @@ public interface ISyncRepository<T>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<T>> GetGtDate(DateTimeOffset date, CancellationToken token);
|
||||
Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset date, CancellationToken token);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user