From 074fc405edff8314bc936721e4da51ff79c33f21 Mon Sep 17 00:00:00 2001 From: kotcheshir73 Date: Thu, 28 Apr 2022 11:35:15 +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=D1=81=D1=82=D1=83=D0=B4?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=BE=D0=B2,=20=D0=B4=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractGenerticEntityService.cs | 4 ++ .../ManagmentEntity/GetBindingModel.cs | 5 ++ .../OrderStudentRecordBusinessLogic.cs | 66 ++++++++++++++----- .../OrderSyncHistoryBusinessLogic.cs | 60 +++-------------- .../OrderStudentRecordBindingModel.cs | 3 + 5 files changed, 70 insertions(+), 68 deletions(-) diff --git a/DepartmentPortal/Common/CoreDatabase/AbstractGenerticEntityService.cs b/DepartmentPortal/Common/CoreDatabase/AbstractGenerticEntityService.cs index c9b629f..28ea40b 100644 --- a/DepartmentPortal/Common/CoreDatabase/AbstractGenerticEntityService.cs +++ b/DepartmentPortal/Common/CoreDatabase/AbstractGenerticEntityService.cs @@ -128,6 +128,10 @@ namespace CoreDatabase } if (entity.IsDeleted) { + if (model.IgnoreDeleted) + { + return OperationResultModel.Success(Mapper.MapToClass(entity, model.HaveRight)); + } return OperationResultModel.Error("Error:", "Элемент удален", ResultServiceStatusCode.WasDelete); } return OperationResultModel.Success(Mapper.MapToClass(entity, model.HaveRight)); diff --git a/DepartmentPortal/Common/ToolsModule/ManagmentEntity/GetBindingModel.cs b/DepartmentPortal/Common/ToolsModule/ManagmentEntity/GetBindingModel.cs index 53abec3..f950bbc 100644 --- a/DepartmentPortal/Common/ToolsModule/ManagmentEntity/GetBindingModel.cs +++ b/DepartmentPortal/Common/ToolsModule/ManagmentEntity/GetBindingModel.cs @@ -32,5 +32,10 @@ namespace ToolsModule.ManagmentEntity /// Иной признак, по которму отбираем записи (для списка) /// public string PageName { get; set; } + + /// + /// Игнорировать признак убдаленности записи и все равно ее возвращать + /// + public bool IgnoreDeleted { get; set; } = false; } } \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/OrderStudentRecordBusinessLogic.cs b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/OrderStudentRecordBusinessLogic.cs index ce4670d..c81f6c0 100644 --- a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/OrderStudentRecordBusinessLogic.cs +++ b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/OrderStudentRecordBusinessLogic.cs @@ -26,7 +26,7 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic { var studentLogic = DependencyManager.Instance.Resolve(); var userLogic = DependencyManager.Instance.Resolve(); - var student = studentLogic.GetElement(new StudentGetBindingModel { Id = result.StudentId }); + var student = model.StudentModel; if (student == null) { Errors.AddRange(studentLogic.Errors); @@ -36,28 +36,17 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic // изменять студента var st = Mapper.MapToClass(student, true); var studentName = student.ToString(); + + bool haveChages = false; if (student.StudentGroupId != result.StudentGroupToId) { st.StudentGroupId = result.StudentGroupToId; - student = studentLogic.Update(st); - if (student == null) - { - Errors.AddRange(studentLogic.Errors); - Errors.Add(("Ошибка изменения по студенту", $"Не удалось изменить группу у студента {studentName}")); - return null; - } + haveChages = true; } - if (student.Description != model.Info) { st.Description = model.Info; - student = studentLogic.Update(st); - if (student == null) - { - Errors.AddRange(studentLogic.Errors); - Errors.Add(("Ошибка изменения по студенту", $"Не удалось изменить описание у студента {studentName}")); - return null; - } + haveChages = true; } if ((result.OrderStudentMoveType == OrderStudentMoveType.ЗачислитьПоПриказу || @@ -69,6 +58,7 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic { st.StudentState = StudentState.Учится; student = studentLogic.Update(st); + haveChages = false; if (student == null) { Errors.AddRange(studentLogic.Errors); @@ -83,6 +73,7 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic { st.StudentState = StudentState.Академ; student = studentLogic.Update(st); + haveChages = false; if (student == null) { Errors.AddRange(studentLogic.Errors); @@ -95,6 +86,7 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic { st.StudentState = StudentState.Учится; student = studentLogic.Update(st); + haveChages = false; if (student == null) { Errors.AddRange(studentLogic.Errors); @@ -112,6 +104,7 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic { st.StudentState = result.OrderStudentMoveType == OrderStudentMoveType.ОтчислитьПоЗавершению ? StudentState.Завершил : StudentState.Отчислен; student = studentLogic.Update(st); + haveChages = false; if (student == null) { Errors.AddRange(studentLogic.Errors); @@ -136,8 +129,23 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic if (result.OrderStudentMoveType == OrderStudentMoveType.Восстановить && student.StudentState != StudentState.Учится) { + var deletedStudent = studentLogic.Restore(new StudentGetBindingModel { NumberOfBook = student.NumberOfBook }); + if (deletedStudent == null) + { + Errors.AddRange(studentLogic.Errors); + Errors.Add(("Ошибка при восстановлении студента", $"Не удалось восстановить студента {studentName}")); + return null; + } + var deletedUser = userLogic.Restore(new UserGetBindingModel { Id = deletedStudent.UserId }); + if (deletedUser == null) + { + Errors.AddRange(userLogic.Errors); + Errors.Add(("Ошибка при восстановлении пользователя студента", $"Не удалось восстановить пользователя студента {studentName}")); + return null; + } st.StudentState = StudentState.Учится; student = studentLogic.Update(st); + haveChages = false; if (student == null) { Errors.AddRange(studentLogic.Errors); @@ -150,12 +158,38 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic { st.StudentState = StudentState.Ушел; student = studentLogic.Update(st); + haveChages = false; if (student == null) { Errors.AddRange(studentLogic.Errors); Errors.Add(("Ошибка изменения по студенту", $"Не удалось изменить статус у студента {studentName}")); return null; } + var delete = studentLogic.Delete(new StudentGetBindingModel { Id = student.Id }); + if (!delete) + { + Errors.AddRange(studentLogic.Errors); + Errors.Add(("Ошибка удаления студента", $"Не удалось удалить студента {studentName}")); + return null; + } + delete = userLogic.Delete(new UserGetBindingModel { Id = student.UserId }); + if (!delete) + { + Errors.AddRange(studentLogic.Errors); + Errors.Add(("Ошибка удаления пользователя по студенту", $"Не удалось удалить пользователя по студенту {studentName}")); + return null; + } + } + + if (haveChages) + { + student = studentLogic.Update(st); + if (student == null) + { + Errors.AddRange(studentLogic.Errors); + Errors.Add(("Ошибка изменения по студенту", $"Не удалось изменить данные у студента {studentName}")); + return null; + } } } return result; diff --git a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/OrderSyncHistoryBusinessLogic.cs b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/OrderSyncHistoryBusinessLogic.cs index 2095822..afb3dd1 100644 --- a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/OrderSyncHistoryBusinessLogic.cs +++ b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/OrderSyncHistoryBusinessLogic.cs @@ -122,7 +122,7 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic // новые студенты и восстановленцы foreach (var student in studentFromServer.CurrentStudentsList) { - var deletedStudent = TryRestoreStudent(student); + var deletedStudent = _studentLogic.GetElement(new StudentGetBindingModel { NumberOfBook = student.recordBookName, IgnoreDeleted = true }); if (deletedStudent != null) { await SyncStudentOrders(deletedStudent, groups.List, client, address.Value); @@ -241,29 +241,6 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic return client; } - private StudentViewModel TryRestoreStudent(StudentSyncModel student) - { - var deletedStudent = _studentLogic.GetElement(new StudentGetBindingModel { NumberOfBook = student.recordBookName }); - if (deletedStudent == null && _studentLogic.Errors.FirstOrDefault(x => x.Message == "Элемент удален") != default) - { - // восстановленец - deletedStudent = _studentLogic.Restore(new StudentGetBindingModel { NumberOfBook = student.recordBookName }); - if (deletedStudent == null) - { - SaveErrors(_studentLogic.Errors, "Ошибка при восстановлении студента", $"Не удалось восстановить студента {student.lastName} {student.firstName} {student.patronymicName}"); - return null; - } - var deletedUser = _userLogic.Restore(new UserGetBindingModel { Id = deletedStudent.UserId }); - if (deletedUser == null) - { - SaveErrors(_userLogic.Errors, "Ошибка при восстановлении пользователя студента", $"Не удалось восстановить пользователя студента {student.lastName} {student.firstName} {student.patronymicName}"); - return null; - } - return deletedStudent; - } - return null; - } - private UserViewModel WorkWithUser(StudentSyncModel student) { var userName = $"{student.lastName}{(student.firstName.IsNotEmpty() ? $" {student.firstName[0]}." : string.Empty)}{(student.patronymicName.IsNotEmpty() ? $"{student.patronymicName[0]}." : string.Empty)}"; @@ -453,6 +430,8 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic continue; } + SetYearFinish(student, studentGroupTo, order, orderStudentMoveType); + // создаем, если не нашли var studentOrder = _orderStudentRecordLogic.Create(new OrderStudentRecordSetBindingModel { @@ -461,7 +440,8 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic Info = info, OrderStudentMoveType = orderStudentMoveType, StudentGroupFromId = studentGroupFrom?.Id, - StudentGroupToId = studentGroupTo?.Id + StudentGroupToId = studentGroupTo?.Id, + StudentModel = student }); if (studentOrder == null) { @@ -469,8 +449,6 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic continue; } - SetYearFinish(student, studentGroupTo, order, studentOrder); - SaveLog($"Добавили запись к приказу {order.OrderNumber} по студенту {student} с формулировкой {info}"); if (orderStudentMoveType == OrderStudentMoveType.ОтчислитьВСвязиСПереводом || @@ -595,14 +573,14 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic } } - private void SetYearFinish(StudentViewModel student, StudentGroupViewModel group, OrderViewModel order, OrderStudentRecordViewModel studentOrder) + private void SetYearFinish(StudentViewModel student, StudentGroupViewModel group, OrderViewModel order, OrderStudentMoveType studentOrderType) { - if (student == null || studentOrder == null) + if (student == null) { return; } int year = DateTime.Now.Year; - switch (studentOrder.OrderStudentMoveType) + switch (studentOrderType) { // у студента не меняется год зачисления case OrderStudentMoveType.ПродлитьАкадем: @@ -617,7 +595,6 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic case OrderStudentMoveType.ОтчислитьПоСобственному: case OrderStudentMoveType.УбратьПоПереводу: student.EnrollmentYearId = null; - UpdateStudent(student); return; // проблема с разными направлениями групп на разных курсах case OrderStudentMoveType.ПеревестиНаСтаршийКурс: @@ -700,27 +677,6 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic } student.EnrollmentYearId = yearEnrollment.Id; - UpdateStudent(student); - } - - private void UpdateStudent(StudentViewModel student) - { - if (student == null) - { - return; - } - var updateStudent = _studentLogic.GetElement(new StudentGetBindingModel { Id = student.Id }); - if (updateStudent == null) - { - SaveErrors(_studentLogic.Errors, "Ошибка обновления данных студента", $"Не удалось найти данные студента {student.LastName} {student.FirstName} {student.Patronymic}"); - return; - } - updateStudent.EnrollmentYearId = student.EnrollmentYearId; - updateStudent = _studentLogic.Update(Mapper.MapToClass(updateStudent, true)); - if (updateStudent == null) - { - SaveErrors(_studentLogic.Errors, "Ошибка обновления данных студента", $"Не удалось обновить данные студента {student?.LastName} {student?.FirstName} {student?.Patronymic}"); - } } private void SaveErrors(List<(string Title, string Message)> errors, string title, string message) diff --git a/DepartmentPortal/Department/DepartmentContract/BindingModels/OrderStudentRecordBindingModel.cs b/DepartmentPortal/Department/DepartmentContract/BindingModels/OrderStudentRecordBindingModel.cs index 4d9cde8..ee1bfef 100644 --- a/DepartmentPortal/Department/DepartmentContract/BindingModels/OrderStudentRecordBindingModel.cs +++ b/DepartmentPortal/Department/DepartmentContract/BindingModels/OrderStudentRecordBindingModel.cs @@ -1,5 +1,6 @@ using CoreModels.Enums.Department; using CoreModels.ModelsDepartment; +using DepartmentContract.ViewModels; using System; using System.ComponentModel.DataAnnotations; using ToolsModule.ManagmentEntity; @@ -39,5 +40,7 @@ namespace DepartmentContract.BindingModels public OrderStudentMoveType OrderStudentMoveType { get; set; } public string Info { get; set; } + + public StudentViewModel StudentModel { get; set; } } } \ No newline at end of file