From 5fa8270cc486771e94c89a9e76b94bde80a9c412 Mon Sep 17 00:00:00 2001 From: kotcheshir73 Date: Wed, 21 Dec 2022 10:34:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BE=D1=86=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=D0=BA=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=BD=D0=BE=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tudentMarkPassedDisciplineBusinessLogic.cs | 17 +++ .../StudentMarkPassedDisciplineLogic.cs | 17 --- .../StudentMarkSyncHistoryBusinessLogic.cs | 28 +++++ ...udentMarkSyncHistoryRecordBusinessLogic.cs | 17 +++ .../DepartmentLogicDependencyRegistration.cs | 4 +- .../StudentMarkSyncHistoryBindingModels.cs | 23 ++++ ...udentMarkSyncHistoryRecordBindingModels.cs | 27 ++++ .../IStudentMarkSyncHistoryLogic.cs | 18 +++ .../IStudentMarkSyncHistoryRecordLogic.cs | 11 ++ .../IStudentMarkSyncHistoryRecordService.cs | 10 ++ .../IStudentMarkSyncHistoryService.cs | 10 ++ .../ViewModels/OrderSyncHistoryViewModels.cs | 2 +- .../StudentMarkSyncHistoryRecordViewModels.cs | 30 +++++ .../StudentMarkSyncHistoryViewModels.cs | 26 ++++ ...entImplementationDependencyRegistration.cs | 2 + .../StudentMarkSyncHistoryRecordService.cs | 107 ++++++++++++++++ .../StudentMarkSyncHistoryService.cs | 115 ++++++++++++++++++ 17 files changed, 445 insertions(+), 19 deletions(-) create mode 100644 DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkPassedDisciplineBusinessLogic.cs delete mode 100644 DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkPassedDisciplineLogic.cs create mode 100644 DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkSyncHistoryBusinessLogic.cs create mode 100644 DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkSyncHistoryRecordBusinessLogic.cs create mode 100644 DepartmentPortal/Department/DepartmentContract/BindingModels/StudentMarkSyncHistoryBindingModels.cs create mode 100644 DepartmentPortal/Department/DepartmentContract/BindingModels/StudentMarkSyncHistoryRecordBindingModels.cs create mode 100644 DepartmentPortal/Department/DepartmentContract/Logics/IGenericEntityLogic/IStudentMarkSyncHistoryLogic.cs create mode 100644 DepartmentPortal/Department/DepartmentContract/Logics/IGenericEntityLogic/IStudentMarkSyncHistoryRecordLogic.cs create mode 100644 DepartmentPortal/Department/DepartmentContract/Services/IGenericEntityService/IStudentMarkSyncHistoryRecordService.cs create mode 100644 DepartmentPortal/Department/DepartmentContract/Services/IGenericEntityService/IStudentMarkSyncHistoryService.cs create mode 100644 DepartmentPortal/Department/DepartmentContract/ViewModels/StudentMarkSyncHistoryRecordViewModels.cs create mode 100644 DepartmentPortal/Department/DepartmentContract/ViewModels/StudentMarkSyncHistoryViewModels.cs create mode 100644 DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/StudentMarkSyncHistoryRecordService.cs create mode 100644 DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/StudentMarkSyncHistoryService.cs diff --git a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkPassedDisciplineBusinessLogic.cs b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkPassedDisciplineBusinessLogic.cs new file mode 100644 index 0000000..3ab771c --- /dev/null +++ b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkPassedDisciplineBusinessLogic.cs @@ -0,0 +1,17 @@ +using DepartmentContract.BindingModels; +using DepartmentContract.Logics.IGenericEntityLogic; +using DepartmentContract.Services.IGenericEntityService; +using DepartmentContract.ViewModels; +using ToolsModule.ManagmentEntity; +using ToolsModule.ManagmentSecurity; + +namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic +{ + /// + /// Логика работы с оценками студентов за дисциплины + /// + public class StudentMarkPassedDisciplineBusinessLogic : GenericBusinessLogic, IStudentMarkPassedDisciplineLogic + { + public StudentMarkPassedDisciplineBusinessLogic(IStudentMarkPassedDisciplineService service) : base(service, "Оценки студентов", AccessOperation.ОценкиСтудентов) { } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkPassedDisciplineLogic.cs b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkPassedDisciplineLogic.cs deleted file mode 100644 index c59ee42..0000000 --- a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkPassedDisciplineLogic.cs +++ /dev/null @@ -1,17 +0,0 @@ -using DepartmentContract.BindingModels; -using DepartmentContract.Logics.IGenericEntityLogic; -using DepartmentContract.Services.IGenericEntityService; -using DepartmentContract.ViewModels; -using ToolsModule.ManagmentEntity; -using ToolsModule.ManagmentSecurity; - -namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic -{ - /// - /// Логика работы с оценками студентов за дисциплины - /// - public class StudentMarkPassedDisciplineLogic : GenericBusinessLogic, IStudentMarkPassedDisciplineLogic - { - public StudentMarkPassedDisciplineLogic(IStudentMarkPassedDisciplineService service) : base(service, "Оценки студентов", AccessOperation.ОценкиСтудентов) { } - } -} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkSyncHistoryBusinessLogic.cs b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkSyncHistoryBusinessLogic.cs new file mode 100644 index 0000000..a406ee5 --- /dev/null +++ b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkSyncHistoryBusinessLogic.cs @@ -0,0 +1,28 @@ +using DepartmentContract.BindingModels; +using DepartmentContract.Logics.IGenericEntityLogic; +using DepartmentContract.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ToolsModule.ManagmentEntity; + +namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic +{ + /// + /// Логика работы с историями синхронизации оценок + /// + public class StudentMarkSyncHistoryBusinessLogic : GenericBusinessLogic, IStudentMarkSyncHistoryLogic + { + public Task SyncMarks() + { + throw new NotImplementedException(); + } + + public Task SyncStudentMarks(Guid studentId) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkSyncHistoryRecordBusinessLogic.cs b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkSyncHistoryRecordBusinessLogic.cs new file mode 100644 index 0000000..3dea5bb --- /dev/null +++ b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentMarkSyncHistoryRecordBusinessLogic.cs @@ -0,0 +1,17 @@ +using DepartmentContract.BindingModels; +using DepartmentContract.Logics.IGenericEntityLogic; +using DepartmentContract.Services.IGenericEntityService; +using DepartmentContract.ViewModels; +using ToolsModule.ManagmentEntity; +using ToolsModule.ManagmentSecurity; + +namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic +{ + /// + /// Логика работы с записями историй синхронизации оценок + /// + public class StudentMarkSyncHistoryRecordBusinessLogic : GenericBusinessLogic, IStudentMarkSyncHistoryRecordLogic + { + public StudentMarkSyncHistoryRecordBusinessLogic(IStudentMarkSyncHistoryRecordService service) : base(service, "Синхронизация Оценок", AccessOperation.ОценкиСтудентов) { } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentBusinessLogic/DepartmentLogicDependencyRegistration.cs b/DepartmentPortal/Department/DepartmentBusinessLogic/DepartmentLogicDependencyRegistration.cs index 8120242..9a2a9cb 100644 --- a/DepartmentPortal/Department/DepartmentBusinessLogic/DepartmentLogicDependencyRegistration.cs +++ b/DepartmentPortal/Department/DepartmentBusinessLogic/DepartmentLogicDependencyRegistration.cs @@ -45,7 +45,9 @@ namespace DepartmentBusinessLogic DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); diff --git a/DepartmentPortal/Department/DepartmentContract/BindingModels/StudentMarkSyncHistoryBindingModels.cs b/DepartmentPortal/Department/DepartmentContract/BindingModels/StudentMarkSyncHistoryBindingModels.cs new file mode 100644 index 0000000..2ff25a0 --- /dev/null +++ b/DepartmentPortal/Department/DepartmentContract/BindingModels/StudentMarkSyncHistoryBindingModels.cs @@ -0,0 +1,23 @@ +using CoreModels.ModelsDepartment; +using System; +using System.ComponentModel.DataAnnotations; +using ToolsModule.ManagmentEntity; + +namespace DepartmentContract.BindingModels +{ + /// + /// Получение истории синхронизации оценок + /// + public class StudentMarkSyncHistoryGetBindingModel : GetBindingModel + { + } + + /// + /// Сохранение истории синхронизации оценок + /// + public class StudentMarkSyncHistorySetBindingModel : SetBindingModel, IStudentMarkSyncHistoryModel + { + [Required(ErrorMessage = "required")] + public DateTime SyncDate { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentContract/BindingModels/StudentMarkSyncHistoryRecordBindingModels.cs b/DepartmentPortal/Department/DepartmentContract/BindingModels/StudentMarkSyncHistoryRecordBindingModels.cs new file mode 100644 index 0000000..3596e49 --- /dev/null +++ b/DepartmentPortal/Department/DepartmentContract/BindingModels/StudentMarkSyncHistoryRecordBindingModels.cs @@ -0,0 +1,27 @@ +using CoreModels.ModelsDepartment; +using System; +using System.ComponentModel.DataAnnotations; +using ToolsModule.ManagmentEntity; + +namespace DepartmentContract.BindingModels +{ + /// + /// Получение записи истории синхронизации оценок + /// + public class StudentMarkSyncHistoryRecordGetBindingModel : GetBindingModel + { + public Guid? StudentMarkSyncHistoryId { get; set; } + } + + /// + /// Сохранение записи истории синхронизации оценок + /// + public class StudentMarkSyncHistoryRecordSetBindingModel : SetBindingModel, IStudentMarkSyncHistoryRecordModel + { + [Required(ErrorMessage = "required")] + public Guid StudentMarkSyncHistoryId { get; set; } + + [Required(ErrorMessage = "required")] + public string Information { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentContract/Logics/IGenericEntityLogic/IStudentMarkSyncHistoryLogic.cs b/DepartmentPortal/Department/DepartmentContract/Logics/IGenericEntityLogic/IStudentMarkSyncHistoryLogic.cs new file mode 100644 index 0000000..cf4ba1a --- /dev/null +++ b/DepartmentPortal/Department/DepartmentContract/Logics/IGenericEntityLogic/IStudentMarkSyncHistoryLogic.cs @@ -0,0 +1,18 @@ +using DepartmentContract.BindingModels; +using DepartmentContract.ViewModels; +using System; +using System.Threading.Tasks; +using ToolsModule.ManagmentEntity; + +namespace DepartmentContract.Logics.IGenericEntityLogic +{ + /// + /// Логика работы с историями синхронизации оценок + /// + public interface IStudentMarkSyncHistoryLogic : IGenericEntityLogic + { + Task SyncMarks(); + + Task SyncStudentMarks(Guid studentId); + } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentContract/Logics/IGenericEntityLogic/IStudentMarkSyncHistoryRecordLogic.cs b/DepartmentPortal/Department/DepartmentContract/Logics/IGenericEntityLogic/IStudentMarkSyncHistoryRecordLogic.cs new file mode 100644 index 0000000..9349c2d --- /dev/null +++ b/DepartmentPortal/Department/DepartmentContract/Logics/IGenericEntityLogic/IStudentMarkSyncHistoryRecordLogic.cs @@ -0,0 +1,11 @@ +using DepartmentContract.BindingModels; +using DepartmentContract.ViewModels; +using ToolsModule.ManagmentEntity; + +namespace DepartmentContract.Logics.IGenericEntityLogic +{ + /// + /// Логика работы с записями историй синхронизации оценок + /// + public interface IStudentMarkSyncHistoryRecordLogic : IGenericEntityLogic { } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentContract/Services/IGenericEntityService/IStudentMarkSyncHistoryRecordService.cs b/DepartmentPortal/Department/DepartmentContract/Services/IGenericEntityService/IStudentMarkSyncHistoryRecordService.cs new file mode 100644 index 0000000..b920166 --- /dev/null +++ b/DepartmentPortal/Department/DepartmentContract/Services/IGenericEntityService/IStudentMarkSyncHistoryRecordService.cs @@ -0,0 +1,10 @@ +using DepartmentContract.BindingModels; +using ToolsModule.ManagmentEntity; + +namespace DepartmentContract.Services.IGenericEntityService +{ + /// + /// Хранение записей историй синхронизации оценок + /// + public interface IStudentMarkSyncHistoryRecordService : IGenericEntityService { } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentContract/Services/IGenericEntityService/IStudentMarkSyncHistoryService.cs b/DepartmentPortal/Department/DepartmentContract/Services/IGenericEntityService/IStudentMarkSyncHistoryService.cs new file mode 100644 index 0000000..1e0299e --- /dev/null +++ b/DepartmentPortal/Department/DepartmentContract/Services/IGenericEntityService/IStudentMarkSyncHistoryService.cs @@ -0,0 +1,10 @@ +using DepartmentContract.BindingModels; +using ToolsModule.ManagmentEntity; + +namespace DepartmentContract.Services.IGenericEntityService +{ + /// + /// Хранение историй синхронизации оценок + /// + public interface IStudentMarkSyncHistoryService : IGenericEntityService { } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentContract/ViewModels/OrderSyncHistoryViewModels.cs b/DepartmentPortal/Department/DepartmentContract/ViewModels/OrderSyncHistoryViewModels.cs index 9dc83a4..fe47ed2 100644 --- a/DepartmentPortal/Department/DepartmentContract/ViewModels/OrderSyncHistoryViewModels.cs +++ b/DepartmentPortal/Department/DepartmentContract/ViewModels/OrderSyncHistoryViewModels.cs @@ -21,6 +21,6 @@ namespace DepartmentContract.ViewModels public DateTime SyncDate { get; set; } [ViewModelControlListProperty("Дата")] - public string SyncDateTitle => $"Синхронизация данных от {SyncDate.ToString("dd.MM.yyyy HH:mm")}"; + public string SyncDateTitle => $"Синхронизация данных от {SyncDate:dd.MM.yyyy HH:mm}"; } } \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentContract/ViewModels/StudentMarkSyncHistoryRecordViewModels.cs b/DepartmentPortal/Department/DepartmentContract/ViewModels/StudentMarkSyncHistoryRecordViewModels.cs new file mode 100644 index 0000000..fdbaafa --- /dev/null +++ b/DepartmentPortal/Department/DepartmentContract/ViewModels/StudentMarkSyncHistoryRecordViewModels.cs @@ -0,0 +1,30 @@ +using CoreModels.ModelsDepartment; +using System; +using ToolsModule.ManagmentEntity; +using ToolsModule.ManagmentMapping; + +namespace DepartmentContract.ViewModels +{ + /// + /// Список записей историй синхронизации оценок + /// + public class StudentMarkSyncHistoryRecordListViewModel : ListViewModel { } + + /// + /// Элемент записи историй синхронизации оценок + /// + [ViewModelControlElementClass(HaveDependenceEntities = false, Width = 800, Height = 500)] + public class StudentMarkSyncHistoryRecordViewModel : ElementViewModel, IStudentMarkSyncHistoryRecordModel + { + [ViewModelControlElementProperty("История", ControlType.ControlGuid, MustHaveValue = true, ReadOnly = false, ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlStudentMarkSyncHistoryList, DepartmentWindowsDesktop")] + public Guid StudentMarkSyncHistoryId { get; set; } + + [ViewModelControlListProperty("Дата", ColumnWidth = 100, DefaultCellStyleFormat = "dd.MM.yyyy")] + [MapConfiguration("StudentMarkSyncHistory.SyncDate")] + public DateTime SyncDate { get; set; } + + [ViewModelControlListProperty("Описание")] + [ViewModelControlElementProperty("Описание", ControlType.ControlText, Height = 200, MustHaveValue = true)] + public string Information { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentContract/ViewModels/StudentMarkSyncHistoryViewModels.cs b/DepartmentPortal/Department/DepartmentContract/ViewModels/StudentMarkSyncHistoryViewModels.cs new file mode 100644 index 0000000..128f6b4 --- /dev/null +++ b/DepartmentPortal/Department/DepartmentContract/ViewModels/StudentMarkSyncHistoryViewModels.cs @@ -0,0 +1,26 @@ +using CoreModels.ModelsDepartment; +using System; +using ToolsModule.ManagmentEntity; + +namespace DepartmentContract.ViewModels +{ + /// + /// Список историй синхронизации оценок + /// + public class StudentMarkSyncHistoryListViewModel : ListViewModel { } + + /// + /// Элемент история синхронизации оценок + /// + [ViewModelControlElementClass(HaveDependenceEntities = true, Width = 800, Height = 500)] + [ViewModelControlElementDependenceEntity(Title = "Записи", Order = 1, ParentPropertyName = "StudentMarkSyncHistoryId", + ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlStudentMarkSyncHistoryRecordList, DepartmentWindowsDesktop")] + public class StudentMarkSyncHistoryViewModel : ElementViewModel, IStudentMarkSyncHistoryModel + { + [ViewModelControlElementProperty("Дата", ControlType.ControlDateTime, MustHaveValue = true, ReadOnly = true)] + public DateTime SyncDate { get; set; } + + [ViewModelControlListProperty("Дата")] + public string SyncDateTitle => $"Синхронизация данных от {SyncDate:dd.MM.yyyy HH:mm}"; + } +} diff --git a/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/DepartmentImplementationDependencyRegistration.cs b/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/DepartmentImplementationDependencyRegistration.cs index 4c7f861..a755c98 100644 --- a/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/DepartmentImplementationDependencyRegistration.cs +++ b/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/DepartmentImplementationDependencyRegistration.cs @@ -45,6 +45,8 @@ namespace DepartmentDatabaseImplementation DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } } } \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/StudentMarkSyncHistoryRecordService.cs b/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/StudentMarkSyncHistoryRecordService.cs new file mode 100644 index 0000000..a16be4c --- /dev/null +++ b/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/StudentMarkSyncHistoryRecordService.cs @@ -0,0 +1,107 @@ +using CoreDatabase; +using CoreDatabase.Models.Department; +using DepartmentContract.BindingModels; +using DepartmentContract.Services.IGenericEntityService; +using DepartmentContract.ViewModels; +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using ToolsModule.ManagmentEntity; +using ToolsModule.ManagmentMapping; + +namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService +{ + /// + /// Реализация IStudentMarkSyncHistoryRecordService + /// + public class StudentMarkSyncHistoryRecordService : IStudentMarkSyncHistoryRecordService + { + public OperationResultModel Create(StudentMarkSyncHistoryRecordSetBindingModel model) + { + using var context = DatabaseManager.GetContext; + + var entity = Mapper.MapToClass(model, true); + context.StudentMarkSyncHistoryRecords.Add(entity); + context.SaveChanges(); + return OperationResultModel.Success(Mapper.MapToClass(entity, true)); + } + + public OperationResultModel Delete(StudentMarkSyncHistoryRecordGetBindingModel model) + { + using var context = DatabaseManager.GetContext; + var entity = context.StudentMarkSyncHistoryRecords.FirstOrDefault(x => x.Id == model.Id); + if (entity == null) + { + return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound); + } + context.StudentMarkSyncHistoryRecords.Remove(entity); + context.SaveChanges(); + + return OperationResultModel.Success(true); + } + + public OperationResultModel Read(StudentMarkSyncHistoryRecordGetBindingModel model) + { + int countPages = 0; + using var context = DatabaseManager.GetContext; + + // для одной записи + if (model.Id.HasValue) + { + var entity = context.StudentMarkSyncHistoryRecords.FirstOrDefault(x => x.Id == model.Id.Value); + if (entity == null) + { + return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound); + } + return OperationResultModel.Success(Mapper.MapToClass(entity, model.HaveRight)); + } + + var query = context.StudentMarkSyncHistoryRecords.AsQueryable(); + + if (model.StudentMarkSyncHistoryId.HasValue) + { + query = query.Where(x => x.StudentMarkSyncHistoryId == model.StudentMarkSyncHistoryId.Value); + } + + query = query.OrderByDescending(x => x.Information); + + query = query.Include(x => x.StudentMarkSyncHistory); + + if (model.PageNumber.HasValue && model.PageSize.HasValue) + { + countPages = (int)Math.Ceiling((double)query.Count() / model.PageSize.Value); + query = query + .Skip(model.PageSize.Value * model.PageNumber.Value) + .Take(model.PageSize.Value); + } + var result = new StudentMarkSyncHistoryRecordListViewModel + { + MaxCount = countPages, + List = query.Select(x => Mapper.MapToClass(x, model.HaveRight)).ToList() + }; + + return OperationResultModel.Success(result); + } + + public OperationResultModel Restore(StudentMarkSyncHistoryRecordGetBindingModel model) + { + throw new NotImplementedException(); + } + + public OperationResultModel Update(StudentMarkSyncHistoryRecordSetBindingModel model) + { + using var context = DatabaseManager.GetContext; + + var entity = context.StudentMarkSyncHistoryRecords.FirstOrDefault(x => x.Id == model.Id); + if (entity == null) + { + return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound); + } + entity = Mapper.MapToClass(model, entity, true); + + context.SaveChanges(); + + return OperationResultModel.Success(Mapper.MapToClass(entity, true)); + } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/StudentMarkSyncHistoryService.cs b/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/StudentMarkSyncHistoryService.cs new file mode 100644 index 0000000..b93d828 --- /dev/null +++ b/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/StudentMarkSyncHistoryService.cs @@ -0,0 +1,115 @@ +using CoreDatabase; +using CoreDatabase.Models.Department; +using DepartmentContract.BindingModels; +using DepartmentContract.Services.IGenericEntityService; +using DepartmentContract.ViewModels; +using System; +using System.Linq; +using ToolsModule.ManagmentEntity; +using ToolsModule.ManagmentMapping; + +namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService +{ + /// + /// Реализация IStudentMarkSyncHistoryService + /// + public class StudentMarkSyncHistoryService : IStudentMarkSyncHistoryService + { + public OperationResultModel Create(StudentMarkSyncHistorySetBindingModel model) + { + using var context = DatabaseManager.GetContext; + + var entity = Mapper.MapToClass(model, true); + context.StudentMarkSyncHistories.Add(entity); + context.SaveChanges(); + return OperationResultModel.Success(Mapper.MapToClass(entity, true)); + } + + public OperationResultModel Delete(StudentMarkSyncHistoryGetBindingModel model) + { + using var context = DatabaseManager.GetContext; + using var transaction = context.Database.BeginTransaction(); + try + { + var entity = context.StudentMarkSyncHistories.FirstOrDefault(x => x.Id == model.Id); + if (entity == null) + { + return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound); + } + + context.StudentMarkSyncHistories.Remove(entity); + context.SaveChanges(); + + var records = context.StudentMarkSyncHistoryRecords.Where(x => x.StudentMarkSyncHistoryId == model.Id); + context.StudentMarkSyncHistoryRecords.RemoveRange(records); + context.SaveChanges(); + + transaction.Commit(); + } + catch (Exception) + { + transaction.Rollback(); + throw; + } + + return OperationResultModel.Success(true); + } + + public OperationResultModel Read(StudentMarkSyncHistoryGetBindingModel model) + { + int countPages = 0; + using var context = DatabaseManager.GetContext; + + // для одной записи + if (model.Id.HasValue) + { + var entity = context.StudentMarkSyncHistories.FirstOrDefault(x => x.Id == model.Id.Value); + if (entity == null) + { + return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound); + } + return OperationResultModel.Success(Mapper.MapToClass(entity, model.HaveRight)); + } + + var query = context.StudentMarkSyncHistories.AsQueryable(); + + query = query.OrderByDescending(x => x.SyncDate); + + if (model.PageNumber.HasValue && model.PageSize.HasValue) + { + countPages = (int)Math.Ceiling((double)query.Count() / model.PageSize.Value); + query = query + .Skip(model.PageSize.Value * model.PageNumber.Value) + .Take(model.PageSize.Value); + } + var result = new StudentMarkSyncHistoryListViewModel + { + MaxCount = countPages, + List = query.Select(x => Mapper.MapToClass(x, model.HaveRight)).ToList() + }; + + return OperationResultModel.Success(result); + } + + public OperationResultModel Restore(StudentMarkSyncHistoryGetBindingModel model) + { + throw new NotImplementedException(); + } + + public OperationResultModel Update(StudentMarkSyncHistorySetBindingModel model) + { + using var context = DatabaseManager.GetContext; + + var entity = context.StudentMarkSyncHistories.FirstOrDefault(x => x.Id == model.Id); + if (entity == null) + { + return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound); + } + entity = Mapper.MapToClass(model, entity, true); + + context.SaveChanges(); + + return OperationResultModel.Success(Mapper.MapToClass(entity, true)); + } + } +} \ No newline at end of file