Синхронизация оценок основноая логика

This commit is contained in:
kotcheshir73 2022-12-21 10:34:50 +04:00
parent 7a94448f94
commit 5fa8270cc4
17 changed files with 445 additions and 19 deletions

View File

@ -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
{
/// <summary>
/// Логика работы с оценками студентов за дисциплины
/// </summary>
public class StudentMarkPassedDisciplineBusinessLogic : GenericBusinessLogic<StudentMarkPassedDisciplineGetBindingModel, StudentMarkPassedDisciplineSetBindingModel, StudentMarkPassedDisciplineListViewModel, StudentMarkPassedDisciplineViewModel>, IStudentMarkPassedDisciplineLogic
{
public StudentMarkPassedDisciplineBusinessLogic(IStudentMarkPassedDisciplineService service) : base(service, "Оценки студентов", AccessOperation.ОценкиСтудентов) { }
}
}

View File

@ -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
{
/// <summary>
/// Логика работы с оценками студентов за дисциплины
/// </summary>
public class StudentMarkPassedDisciplineLogic : GenericBusinessLogic<StudentMarkPassedDisciplineGetBindingModel, StudentMarkPassedDisciplineSetBindingModel, StudentMarkPassedDisciplineListViewModel, StudentMarkPassedDisciplineViewModel>, IStudentMarkPassedDisciplineLogic
{
public StudentMarkPassedDisciplineLogic(IStudentMarkPassedDisciplineService service) : base(service, "Оценки студентов", AccessOperation.ОценкиСтудентов) { }
}
}

View File

@ -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
{
/// <summary>
/// Логика работы с историями синхронизации оценок
/// </summary>
public class StudentMarkSyncHistoryBusinessLogic : GenericBusinessLogic<StudentMarkSyncHistoryGetBindingModel, StudentMarkSyncHistorySetBindingModel, StudentMarkSyncHistoryListViewModel, StudentMarkSyncHistoryViewModel>, IStudentMarkSyncHistoryLogic
{
public Task<bool> SyncMarks()
{
throw new NotImplementedException();
}
public Task<bool> SyncStudentMarks(Guid studentId)
{
throw new NotImplementedException();
}
}
}

View File

@ -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
{
/// <summary>
/// Логика работы с записями историй синхронизации оценок
/// </summary>
public class StudentMarkSyncHistoryRecordBusinessLogic : GenericBusinessLogic<StudentMarkSyncHistoryRecordGetBindingModel, StudentMarkSyncHistoryRecordSetBindingModel, StudentMarkSyncHistoryRecordListViewModel, StudentMarkSyncHistoryRecordViewModel>, IStudentMarkSyncHistoryRecordLogic
{
public StudentMarkSyncHistoryRecordBusinessLogic(IStudentMarkSyncHistoryRecordService service) : base(service, "Синхронизация Оценок", AccessOperation.ОценкиСтудентов) { }
}
}

View File

@ -45,7 +45,9 @@ namespace DepartmentBusinessLogic
DependencyManager.Instance.RegisterType<IBasicDepartmentLogic, BasicDepartmentBusinessLogic>();
DependencyManager.Instance.RegisterType<IStudentMarkPassedDisciplineLogic, StudentMarkPassedDisciplineLogic>();
DependencyManager.Instance.RegisterType<IStudentMarkPassedDisciplineLogic, StudentMarkPassedDisciplineBusinessLogic>();
DependencyManager.Instance.RegisterType<IStudentMarkSyncHistoryLogic, StudentMarkSyncHistoryBusinessLogic>();
DependencyManager.Instance.RegisterType<IStudentMarkSyncHistoryRecordLogic, StudentMarkSyncHistoryRecordBusinessLogic>();

View File

@ -0,0 +1,23 @@
using CoreModels.ModelsDepartment;
using System;
using System.ComponentModel.DataAnnotations;
using ToolsModule.ManagmentEntity;
namespace DepartmentContract.BindingModels
{
/// <summary>
/// Получение истории синхронизации оценок
/// </summary>
public class StudentMarkSyncHistoryGetBindingModel : GetBindingModel
{
}
/// <summary>
/// Сохранение истории синхронизации оценок
/// </summary>
public class StudentMarkSyncHistorySetBindingModel : SetBindingModel, IStudentMarkSyncHistoryModel
{
[Required(ErrorMessage = "required")]
public DateTime SyncDate { get; set; }
}
}

View File

@ -0,0 +1,27 @@
using CoreModels.ModelsDepartment;
using System;
using System.ComponentModel.DataAnnotations;
using ToolsModule.ManagmentEntity;
namespace DepartmentContract.BindingModels
{
/// <summary>
/// Получение записи истории синхронизации оценок
/// </summary>
public class StudentMarkSyncHistoryRecordGetBindingModel : GetBindingModel
{
public Guid? StudentMarkSyncHistoryId { get; set; }
}
/// <summary>
/// Сохранение записи истории синхронизации оценок
/// </summary>
public class StudentMarkSyncHistoryRecordSetBindingModel : SetBindingModel, IStudentMarkSyncHistoryRecordModel
{
[Required(ErrorMessage = "required")]
public Guid StudentMarkSyncHistoryId { get; set; }
[Required(ErrorMessage = "required")]
public string Information { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using DepartmentContract.BindingModels;
using DepartmentContract.ViewModels;
using System;
using System.Threading.Tasks;
using ToolsModule.ManagmentEntity;
namespace DepartmentContract.Logics.IGenericEntityLogic
{
/// <summary>
/// Логика работы с историями синхронизации оценок
/// </summary>
public interface IStudentMarkSyncHistoryLogic : IGenericEntityLogic<StudentMarkSyncHistoryGetBindingModel, StudentMarkSyncHistorySetBindingModel, StudentMarkSyncHistoryListViewModel, StudentMarkSyncHistoryViewModel>
{
Task<bool> SyncMarks();
Task<bool> SyncStudentMarks(Guid studentId);
}
}

View File

@ -0,0 +1,11 @@
using DepartmentContract.BindingModels;
using DepartmentContract.ViewModels;
using ToolsModule.ManagmentEntity;
namespace DepartmentContract.Logics.IGenericEntityLogic
{
/// <summary>
/// Логика работы с записями историй синхронизации оценок
/// </summary>
public interface IStudentMarkSyncHistoryRecordLogic : IGenericEntityLogic<StudentMarkSyncHistoryRecordGetBindingModel, StudentMarkSyncHistoryRecordSetBindingModel, StudentMarkSyncHistoryRecordListViewModel, StudentMarkSyncHistoryRecordViewModel> { }
}

View File

@ -0,0 +1,10 @@
using DepartmentContract.BindingModels;
using ToolsModule.ManagmentEntity;
namespace DepartmentContract.Services.IGenericEntityService
{
/// <summary>
/// Хранение записей историй синхронизации оценок
/// </summary>
public interface IStudentMarkSyncHistoryRecordService : IGenericEntityService<StudentMarkSyncHistoryRecordGetBindingModel, StudentMarkSyncHistoryRecordSetBindingModel> { }
}

View File

@ -0,0 +1,10 @@
using DepartmentContract.BindingModels;
using ToolsModule.ManagmentEntity;
namespace DepartmentContract.Services.IGenericEntityService
{
/// <summary>
/// Хранение историй синхронизации оценок
/// </summary>
public interface IStudentMarkSyncHistoryService : IGenericEntityService<StudentMarkSyncHistoryGetBindingModel, StudentMarkSyncHistorySetBindingModel> { }
}

View File

@ -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}";
}
}

View File

@ -0,0 +1,30 @@
using CoreModels.ModelsDepartment;
using System;
using ToolsModule.ManagmentEntity;
using ToolsModule.ManagmentMapping;
namespace DepartmentContract.ViewModels
{
/// <summary>
/// Список записей историй синхронизации оценок
/// </summary>
public class StudentMarkSyncHistoryRecordListViewModel : ListViewModel<StudentMarkSyncHistoryRecordViewModel> { }
/// <summary>
/// Элемент записи историй синхронизации оценок
/// </summary>
[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; }
}
}

View File

@ -0,0 +1,26 @@
using CoreModels.ModelsDepartment;
using System;
using ToolsModule.ManagmentEntity;
namespace DepartmentContract.ViewModels
{
/// <summary>
/// Список историй синхронизации оценок
/// </summary>
public class StudentMarkSyncHistoryListViewModel : ListViewModel<StudentMarkSyncHistoryViewModel> { }
/// <summary>
/// Элемент история синхронизации оценок
/// </summary>
[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}";
}
}

View File

@ -45,6 +45,8 @@ namespace DepartmentDatabaseImplementation
DependencyManager.Instance.RegisterType<IBasicDepartmentService, BasicDepartmentService>();
DependencyManager.Instance.RegisterType<IStudentMarkPassedDisciplineService, StudentMarkPassedDisciplineService>();
DependencyManager.Instance.RegisterType<IStudentMarkSyncHistoryService, StudentMarkSyncHistoryService>();
DependencyManager.Instance.RegisterType<IStudentMarkSyncHistoryRecordService, StudentMarkSyncHistoryRecordService>();
}
}
}

View File

@ -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
{
/// <summary>
/// Реализация IStudentMarkSyncHistoryRecordService
/// </summary>
public class StudentMarkSyncHistoryRecordService : IStudentMarkSyncHistoryRecordService
{
public OperationResultModel Create(StudentMarkSyncHistoryRecordSetBindingModel model)
{
using var context = DatabaseManager.GetContext;
var entity = Mapper.MapToClass<StudentMarkSyncHistoryRecordSetBindingModel, StudentMarkSyncHistoryRecord>(model, true);
context.StudentMarkSyncHistoryRecords.Add(entity);
context.SaveChanges();
return OperationResultModel.Success(Mapper.MapToClass<StudentMarkSyncHistoryRecord, StudentMarkSyncHistoryRecordViewModel>(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<StudentMarkSyncHistoryRecord, StudentMarkSyncHistoryRecordViewModel>(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<StudentMarkSyncHistoryRecord, StudentMarkSyncHistoryRecordViewModel>(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<StudentMarkSyncHistoryRecord, StudentMarkSyncHistoryRecordViewModel>(entity, true));
}
}
}

View File

@ -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
{
/// <summary>
/// Реализация IStudentMarkSyncHistoryService
/// </summary>
public class StudentMarkSyncHistoryService : IStudentMarkSyncHistoryService
{
public OperationResultModel Create(StudentMarkSyncHistorySetBindingModel model)
{
using var context = DatabaseManager.GetContext;
var entity = Mapper.MapToClass<StudentMarkSyncHistorySetBindingModel, StudentMarkSyncHistory>(model, true);
context.StudentMarkSyncHistories.Add(entity);
context.SaveChanges();
return OperationResultModel.Success(Mapper.MapToClass<StudentMarkSyncHistory, StudentMarkSyncHistoryViewModel>(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<StudentMarkSyncHistory, StudentMarkSyncHistoryViewModel>(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<StudentMarkSyncHistory, StudentMarkSyncHistoryViewModel>(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<StudentMarkSyncHistory, StudentMarkSyncHistoryViewModel>(entity, true));
}
}
}