From f22799f1efadc23622e4b08d880e8762e00dab66 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 31 Oct 2024 17:02:48 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20Microsoft.EntityFrameworkCore.=20?= =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Persistence/Models/ChangeLogDto.cs | 42 ++++++++++++ Persistence/Models/IChangeLogAbstract.cs | 62 +++++++++++++++++ Persistence/Models/UserDto.cs | 66 +++++++++++++++++++ Persistence/Persistence.csproj | 4 ++ .../AbstractChangeLogRepository.cs | 52 +++++++++++---- .../Repositories/IChangeLogRepository.cs | 28 ++++---- Persistence/Repositories/ISyncRepository.cs | 6 +- 7 files changed, 228 insertions(+), 32 deletions(-) create mode 100644 Persistence/Models/ChangeLogDto.cs create mode 100644 Persistence/Models/IChangeLogAbstract.cs create mode 100644 Persistence/Models/UserDto.cs diff --git a/Persistence/Models/ChangeLogDto.cs b/Persistence/Models/ChangeLogDto.cs new file mode 100644 index 0000000..5d5e7f5 --- /dev/null +++ b/Persistence/Models/ChangeLogDto.cs @@ -0,0 +1,42 @@ +namespace Persistence.Models; + +/// +/// Часть записи описывающая изменение +/// +public class ChangeLogDto where T: class +{ + /// + /// Запись + /// + public required T Item { get; set; } + + /// + /// Автор + /// + public UserDto? Author { get; set; } + + /// + /// Автор + /// + public UserDto? Editor { get; set; } + + /// + /// Дата создания записи + /// + public DateTimeOffset Creation { get; set; } + + /// + /// Дата устаревания (например при удалении) + /// + public DateTimeOffset? Obsolete { get; set; } + + /// + /// Id состояния + /// + public int IdState { get; set; } + + /// + /// Id заменяемой записи + /// + public int? IdPrevious { get; set; } +} diff --git a/Persistence/Models/IChangeLogAbstract.cs b/Persistence/Models/IChangeLogAbstract.cs new file mode 100644 index 0000000..a23ab1b --- /dev/null +++ b/Persistence/Models/IChangeLogAbstract.cs @@ -0,0 +1,62 @@ +namespace Persistence.Models; + +/// +/// Часть записи описывающая изменение +/// +public interface IChangeLogAbstract +{ + /// + /// Актуальная + /// + public const int IdStateActual = 0; + + /// + /// Замененная + /// + public const int IdStateReplaced = 1; + + /// + /// Удаленная + /// + public const int IdStateDeleted = 2; + + /// + /// Очищено при импорте + /// + public const int IdCleared = 3; + + /// + /// Ид записи + /// + public int Id { get; set; } + + /// + /// Автор изменения + /// + public int IdAuthor { get; set; } + + /// + /// Редактор + /// + public int? IdEditor { get; set; } + + /// + /// Дата создания записи + /// + public DateTimeOffset Creation { get; set; } + + /// + /// Дата устаревания (например при удалении) + /// + public DateTimeOffset? Obsolete { get; set; } + + /// + /// "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная + /// + public int IdState { get; set; } + + /// + /// Id заменяемой записи + /// + public int? IdPrevious { get; set; } +} diff --git a/Persistence/Models/UserDto.cs b/Persistence/Models/UserDto.cs new file mode 100644 index 0000000..cb49514 --- /dev/null +++ b/Persistence/Models/UserDto.cs @@ -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 +{ + /// + public int Id { get; set; } + + /// + /// логин + /// + public string Login { get; set; } = null!; + + /// + /// Имя + /// + public string? Name { get; set; } + + /// + /// Фамилия + /// + public string? Surname { get; set; } + + /// + /// Отчество + /// + public string? Patronymic { get; set; } + + /// + /// Email + /// + public string Email { get; set; } = null!; + + /// + /// Phone + /// + public string? Phone { get; set; } + + /// + /// Должность + /// + public string? Position { get; set; } + + /// + /// Id компании + /// + public int IdCompany { get; set; } + + /// + /// Id состояния пользователя + /// 0 - не активен, + /// 1 - активен, + /// 2 - заблокирован + /// + public short IdState { get; set; } + + /// + /// Получение отображаемого имени + /// + /// +} diff --git a/Persistence/Persistence.csproj b/Persistence/Persistence.csproj index fa71b7a..1bd718e 100644 --- a/Persistence/Persistence.csproj +++ b/Persistence/Persistence.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/Persistence/Repositories/AbstractChangeLogRepository.cs b/Persistence/Repositories/AbstractChangeLogRepository.cs index fa68b20..687ccfc 100644 --- a/Persistence/Repositories/AbstractChangeLogRepository.cs +++ b/Persistence/Repositories/AbstractChangeLogRepository.cs @@ -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 : IChangeLogRepository +public abstract class AbstractChangeLogRepository : IChangeLogRepository + where TDto : class, new() + where TEntity : class, IChangeLogAbstract { + private readonly DbContext dbContext; + + protected AbstractChangeLogRepository(DbContext dbContext) + { + this.dbContext = dbContext; + } public Task Clear(int idUser, TRequest request, CancellationToken token) { throw new NotImplementedException(); } - public Task ClearAndInsertRange(int idUser, TRequest request, IEnumerable dtos, CancellationToken token) + public Task ClearAndInsertRange(int idUser, TRequest request, IEnumerable dtos, CancellationToken token) { throw new NotImplementedException(); } - public Task> GetCurrent(TRequest request, CancellationToken token) + public Task> GetCurrent(TRequest request, CancellationToken token) { throw new NotImplementedException(); } @@ -27,27 +33,47 @@ public abstract class AbstractChangeLogRepository : IChangeLogRepos throw new NotImplementedException(); } - public Task> GetGtDate(DateTimeOffset date, CancellationToken token) + public Task> GetGtDate(DateTimeOffset date, CancellationToken token) { throw new NotImplementedException(); } - public Task InsertRange(int idUser, IEnumerable dtos, CancellationToken token) + public Task InsertRange(int idUser, IEnumerable dtos, CancellationToken token) { - throw new NotImplementedException(); + this.dbContext.Set(); + 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 MarkAsDeleted(int idUser, IEnumerable ids, CancellationToken token) { throw new NotImplementedException(); } - public Task UpdateOrInsertRange(int idUser, IEnumerable dtos, CancellationToken token) + public Task UpdateOrInsertRange(int idUser, IEnumerable dtos, CancellationToken token) { throw new NotImplementedException(); } - public Task UpdateRange(int idUser, IEnumerable dtos, CancellationToken token) + public Task UpdateRange(int idUser, IEnumerable dtos, CancellationToken token) + { + throw new NotImplementedException(); + } + + public Task>> GetChangeLogForDate(TRequest request, DateOnly? date, CancellationToken token) { throw new NotImplementedException(); } diff --git a/Persistence/Repositories/IChangeLogRepository.cs b/Persistence/Repositories/IChangeLogRepository.cs index dc2aade..b75bde8 100644 --- a/Persistence/Repositories/IChangeLogRepository.cs +++ b/Persistence/Repositories/IChangeLogRepository.cs @@ -1,10 +1,13 @@ -namespace Persistence.Repositories; +using Persistence.Models; + +namespace Persistence.Repositories; /// /// /// -/// -public interface IChangeLogRepository : ISyncRepository +/// +public interface IChangeLogRepository : ISyncRepository + where TDto : class { /// /// Добавление записей @@ -13,7 +16,7 @@ public interface IChangeLogRepository : ISyncRepository /// /// /// - Task InsertRange(int idUser, IEnumerable dtos, CancellationToken token); + Task InsertRange(int idUser, IEnumerable dtos, CancellationToken token); /// /// Редактирование записей @@ -22,7 +25,7 @@ public interface IChangeLogRepository : ISyncRepository /// /// /// - Task UpdateRange(int idUser, IEnumerable dtos, CancellationToken token); + Task UpdateRange(int idUser, IEnumerable dtos, CancellationToken token); /// /// Добавляет Dto у которых id == 0, изменяет dto у которых id != 0 @@ -31,7 +34,7 @@ public interface IChangeLogRepository : ISyncRepository /// /// /// - Task UpdateOrInsertRange(int idUser, IEnumerable dtos, CancellationToken token); + Task UpdateOrInsertRange(int idUser, IEnumerable dtos, CancellationToken token); /// /// Помечает записи как удаленные @@ -50,7 +53,7 @@ public interface IChangeLogRepository : ISyncRepository /// /// /// - Task ClearAndInsertRange(int idUser, TRequest request, IEnumerable dtos, CancellationToken token); + Task ClearAndInsertRange(int idUser, TRequest request, IEnumerable dtos, CancellationToken token); /// /// Пометить записи как удаленные @@ -76,7 +79,7 @@ public interface IChangeLogRepository : ISyncRepository /// Фильтр по дате. Если null - вернет все записи, без привязки к дате /// /// - //Task>> GetChangeLogForDate(TRequest request, DateOnly? date, CancellationToken token); + Task>> GetChangeLogForDate(TRequest request, DateOnly? date, CancellationToken token); /// /// Получение текущих сейчас записей по параметрам @@ -84,12 +87,5 @@ public interface IChangeLogRepository : ISyncRepository /// /// /// - Task> GetCurrent(TRequest request, CancellationToken token); - - /// - /// Получение объекта, реализующего интерфейс IChangeLogRepositoryBuilder - /// для последующих вызовов методов фильтрации по запросам - /// - /// - //IChangeLogQueryBuilder GetQueryBuilder(ChangeLogRequest request); + Task> GetCurrent(TRequest request, CancellationToken token); } diff --git a/Persistence/Repositories/ISyncRepository.cs b/Persistence/Repositories/ISyncRepository.cs index 6e320f9..caf5119 100644 --- a/Persistence/Repositories/ISyncRepository.cs +++ b/Persistence/Repositories/ISyncRepository.cs @@ -3,8 +3,8 @@ /// /// /// -/// -public interface ISyncRepository +/// +public interface ISyncRepository { /// /// @@ -12,5 +12,5 @@ public interface ISyncRepository /// /// /// - Task> GetGtDate(DateTimeOffset date, CancellationToken token); + Task> GetGtDate(DateTimeOffset date, CancellationToken token); }