From 3f9d9ce6482c28a546035a3bc04f3809510c2ab2 Mon Sep 17 00:00:00 2001
From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com>
Date: Sun, 21 Apr 2024 19:12:38 +0400
Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D1=83=20=D1=81=D0=B4=D0=B5?=
=?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=B1=D0=B8=D0=B7=D0=BD?=
=?UTF-8?q?=D0=B5=D1=81-=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20+=20=D0=BD?=
=?UTF-8?q?=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?=
=?UTF-8?q?=D1=8B=20=D1=81=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B9=20=D0=B4=D0=B0?=
=?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../University/UniversityRestApi.csproj | 13 ++
.../BusinessLogics/AttestationLogic.cs | 136 ++++++++++++++++++
.../BusinessLogics/PlanOfStudyLogic.cs | 118 +++++++++++++++
.../BusinessLogics/StudentLogic.cs | 2 +-
.../BindingModels/AttestationBindingModel.cs | 3 +-
.../IAttestationLogic.cs | 2 +-
.../IPlanOfStudyLogic.cs | 2 +-
.../SearchModels/AttestationSearchModel.cs | 1 -
.../ViewModels/AttestationViewModel.cs | 3 +-
.../Enums/AttestationScore.cs | 25 ++++
.../Models/IAttestationModel.cs | 6 +-
.../Implements/StudentStorage.cs | 86 +++++++++++
12 files changed, 389 insertions(+), 8 deletions(-)
create mode 100644 University/University/UniversityRestApi.csproj
create mode 100644 University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs
create mode 100644 University/UniversityBusinessLogic/BusinessLogics/PlanOfStudyLogic.cs
create mode 100644 University/UniversityDataModels/Enums/AttestationScore.cs
diff --git a/University/University/UniversityRestApi.csproj b/University/University/UniversityRestApi.csproj
new file mode 100644
index 0000000..9daa180
--- /dev/null
+++ b/University/University/UniversityRestApi.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs
new file mode 100644
index 0000000..a369017
--- /dev/null
+++ b/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs
@@ -0,0 +1,136 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using UniversityContracts.BindingModels;
+using UniversityContracts.BusinessLogicsContracts;
+using UniversityContracts.SearchModels;
+using UniversityContracts.StorageContracts;
+using UniversityContracts.ViewModels;
+using UniversityDataModels.Enums;
+
+namespace UniversityBusinessLogic.BusinessLogics
+{/*
+ public class AttestationLogic : IAttestationLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IAttestationStorage _attestationStorage;
+ public AttestationLogic(ILogger logger, IAttestationStorage
+ attestationStorage)
+ {
+ _logger = logger;
+ _attestationStorage = attestationStorage;
+ }
+ public List? ReadList(AttestationSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. FormOfEvaluation: {FormOfEvaluation}.Id:{Id} ",
+ model?.FormOfEvaluation, model?.Id);
+ var list = model == null ? _attestationStorage.GetFullList() :
+ _attestationStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public AttestationViewModel? ReadElement(AttestationSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. FormOfEvaluation:{FormOfEvaluation}.Id:{Id}",
+ model.FormOfEvaluation, model.Id);
+ var element = _attestationStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+ public bool Create(AttestationBindingModel model)
+ {
+ CheckModel(model);
+
+ model.Score = AttestationScore.Неявка;
+
+ if (_attestationStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+
+ return true;
+ }
+ public bool StatusUpdate(AttestationBindingModel model, AttestationScore newScore)
+ {
+ CheckModel(model);
+ if (model.Score + 1 != newScore)
+ {
+ _logger.LogWarning("Status update to " + newScore.ToString() + " operation failed. Order status incorrect.");
+ return false;
+ }
+
+ model.Score = newScore;
+
+ if (model.Score == AttestationScore.Выдан)
+ model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
+
+ if (_attestationStorage.Update(model) == null)
+ {
+ model.Score--;
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+
+ return true;
+ }
+ public bool TakeOrderInWork(OrderBindingModel model)
+ {
+ return StatusUpdate(model, OrderStatus.Выполняется);
+ }
+
+ public bool DeliveryOrder(OrderBindingModel model)
+ {
+ return StatusUpdate(model, OrderStatus.Готов);
+ }
+
+ public bool FinishOrder(OrderBindingModel model)
+ {
+ return StatusUpdate(model, OrderStatus.Выдан);
+ }
+
+ private void CheckModel(OrderBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.WorkId < 0)
+ {
+ throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.WorkId));
+ }
+
+ if (model.Count <= 0)
+ {
+ throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
+ }
+
+ if (model.Sum <= 0)
+ {
+ throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
+ }
+ _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId);
+ }
+ }*/
+}
diff --git a/University/UniversityBusinessLogic/BusinessLogics/PlanOfStudyLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/PlanOfStudyLogic.cs
new file mode 100644
index 0000000..194f4b0
--- /dev/null
+++ b/University/UniversityBusinessLogic/BusinessLogics/PlanOfStudyLogic.cs
@@ -0,0 +1,118 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using UniversityContracts.BindingModels;
+using UniversityContracts.BusinessLogicsContracts;
+using UniversityContracts.SearchModels;
+using UniversityContracts.StorageContracts;
+using UniversityContracts.ViewModels;
+
+namespace UniversityBusinessLogic.BusinessLogics
+{
+ public class PlanOfStudyLogic : IPlanOfStudyLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IPlanOfStudyStorage _planOfStudyStorage;
+ public PlanOfStudyLogic(ILogger logger, IPlanOfStudyStorage
+ planOfStudyStorage)
+ {
+ _logger = logger;
+ _planOfStudyStorage = planOfStudyStorage;
+ }
+ public List? ReadList(PlanOfStudySearchModel? model)
+ {
+ _logger.LogInformation("ReadList. Profile: {Profile}.Id:{Id} ",
+ model?.Profile, model?.Id);
+ var list = model == null ? _planOfStudyStorage.GetFullList() :
+ _planOfStudyStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public PlanOfStudyViewModel? ReadElement(PlanOfStudySearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. Profile:{Profile}.Id:{Id}",
+ model.Profile, model.Id);
+ var element = _planOfStudyStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+ public bool Create(PlanOfStudyBindingModel model)
+ {
+ CheckModel(model);
+ if (_planOfStudyStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(PlanOfStudyBindingModel model)
+ {
+ CheckModel(model);
+ if (_planOfStudyStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(PlanOfStudyBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_planOfStudyStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(PlanOfStudyBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.Profile))
+ {
+ throw new ArgumentNullException("Нет названия профиля",
+ nameof(model.Profile));
+ }
+ if (string.IsNullOrEmpty(model.FormOfStudy))
+ {
+ throw new ArgumentNullException("Не указана форма обучения", nameof(model.FormOfStudy));
+ }
+ _logger.LogInformation("Student. Profile:{Profile}.FormOfStudy:{FormOfStudy}. Id: {Id}",
+ model.Profile, model.FormOfStudy, model.Id);
+ var element = _planOfStudyStorage.GetElement(new PlanOfStudySearchModel
+ {
+ Profile = model.Profile
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Данный план обучения уже существует");
+ }
+ }
+ }
+}
diff --git a/University/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs
index af56c14..a331058 100644
--- a/University/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs
+++ b/University/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs
@@ -107,7 +107,7 @@ namespace UniversityBusinessLogic.BusinessLogics
});
if (element != null && element.Id != model.Id)
{
- throw new InvalidOperationException("Student с таким названием уже есть");
+ throw new InvalidOperationException("Данный студент уже существует");
}
}
}
diff --git a/University/UniversityContracts/BindingModels/AttestationBindingModel.cs b/University/UniversityContracts/BindingModels/AttestationBindingModel.cs
index 95223d5..f85ab83 100644
--- a/University/UniversityContracts/BindingModels/AttestationBindingModel.cs
+++ b/University/UniversityContracts/BindingModels/AttestationBindingModel.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using UniversityDataModels.Enums;
using UniversityDataModels.Models;
namespace UniversityContracts.BindingModels
@@ -11,7 +12,7 @@ namespace UniversityContracts.BindingModels
{
public int Id { get; set; }
public string FormOfEvaluation { get; set; } = string.Empty;
- public string Score { get; set; } = string.Empty;
+ public AttestationScore Score { get; set; } = AttestationScore.Неявка;
public int StudentId { get; set; }
}
}
diff --git a/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs
index 7c5db3c..114058d 100644
--- a/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs
+++ b/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs
@@ -9,7 +9,7 @@ using UniversityContracts.ViewModels;
namespace UniversityContracts.BusinessLogicsContracts
{
- internal interface IAttestationLogic
+ public interface IAttestationLogic
{
List? ReadList(AttestationSearchModel? model);
AttestationViewModel? ReadElement(AttestationSearchModel model);
diff --git a/University/UniversityContracts/BusinessLogicsContracts/IPlanOfStudyLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IPlanOfStudyLogic.cs
index f64ca6f..ab4d193 100644
--- a/University/UniversityContracts/BusinessLogicsContracts/IPlanOfStudyLogic.cs
+++ b/University/UniversityContracts/BusinessLogicsContracts/IPlanOfStudyLogic.cs
@@ -9,7 +9,7 @@ using UniversityContracts.ViewModels;
namespace UniversityContracts.BusinessLogicsContracts
{
- internal interface IPlanOfStudyLogic
+ public interface IPlanOfStudyLogic
{
List? ReadList(PlanOfStudySearchModel? model);
PlanOfStudyViewModel? ReadElement(PlanOfStudySearchModel model);
diff --git a/University/UniversityContracts/SearchModels/AttestationSearchModel.cs b/University/UniversityContracts/SearchModels/AttestationSearchModel.cs
index df13d0f..91c4141 100644
--- a/University/UniversityContracts/SearchModels/AttestationSearchModel.cs
+++ b/University/UniversityContracts/SearchModels/AttestationSearchModel.cs
@@ -10,6 +10,5 @@ namespace UniversityContracts.SearchModels
{
public int? Id { get; set; }
public string? FormOfEvaluation { get; set; }
- public string? Score { get; set; }
}
}
diff --git a/University/UniversityContracts/ViewModels/AttestationViewModel.cs b/University/UniversityContracts/ViewModels/AttestationViewModel.cs
index eaf6eb9..53cd21d 100644
--- a/University/UniversityContracts/ViewModels/AttestationViewModel.cs
+++ b/University/UniversityContracts/ViewModels/AttestationViewModel.cs
@@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using UniversityDataModels.Enums;
using UniversityDataModels.Models;
namespace UniversityContracts.ViewModels
@@ -15,6 +16,6 @@ namespace UniversityContracts.ViewModels
[DisplayName("Форма оценивания")]
public string FormOfEvaluation { get; set; } = string.Empty;
[DisplayName("Оценка")]
- public string Score { get; set; } = string.Empty;
+ public AttestationScore Score { get; set; } = AttestationScore.Неявка;
}
}
diff --git a/University/UniversityDataModels/Enums/AttestationScore.cs b/University/UniversityDataModels/Enums/AttestationScore.cs
new file mode 100644
index 0000000..409fc6e
--- /dev/null
+++ b/University/UniversityDataModels/Enums/AttestationScore.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace UniversityDataModels.Enums
+{
+ public enum AttestationScore
+ {
+ Неявка = -1,
+
+ Незачёт = 0,
+
+ Зачёт = 1,
+
+ Неудовлетворительно = 2,
+
+ Удовлетворительно = 3,
+
+ Хорошо = 4,
+
+ Отлично = 5
+ }
+}
diff --git a/University/UniversityDataModels/Models/IAttestationModel.cs b/University/UniversityDataModels/Models/IAttestationModel.cs
index 66ab998..8a7a08a 100644
--- a/University/UniversityDataModels/Models/IAttestationModel.cs
+++ b/University/UniversityDataModels/Models/IAttestationModel.cs
@@ -1,9 +1,11 @@
-namespace UniversityDataModels.Models
+using UniversityDataModels.Enums;
+
+namespace UniversityDataModels.Models
{
public interface IAttestationModel : IId
{
string FormOfEvaluation { get; }
- string Score { get; }
+ AttestationScore Score { get; }
int StudentId { get; }
}
}
diff --git a/University/UniversityDatabaseImplement/Implements/StudentStorage.cs b/University/UniversityDatabaseImplement/Implements/StudentStorage.cs
index 6ab1cfe..446863c 100644
--- a/University/UniversityDatabaseImplement/Implements/StudentStorage.cs
+++ b/University/UniversityDatabaseImplement/Implements/StudentStorage.cs
@@ -1,13 +1,99 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using UniversityContracts.BindingModels;
+using UniversityContracts.SearchModels;
using UniversityContracts.StorageContracts;
+using UniversityContracts.ViewModels;
+using UniversityDatabaseImplement.Models;
namespace UniversityDatabaseImplement.Implements
{
public class StudentStorage : IStudentStorage
{
+ public List GetFullList()
+ {
+ using var context = new UniversityDatabase();
+
+ return context.Students.Select(x => x.GetViewModel).ToList();
+ }
+
+ public List GetFilteredList(StudentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ return new();
+ }
+
+ using var context = new UniversityDatabase();
+
+ return context.Students.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
+ }
+
+ public StudentViewModel? GetElement(StudentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
+ {
+ return null;
+ }
+
+ using var context = new UniversityDatabase();
+
+ return context.Students.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name)
+ && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
+ }
+
+ public StudentViewModel? Insert(StudentBindingModel model)
+ {
+ var newStudent = Student.Create(model);
+
+ if (newStudent == null)
+ {
+ return null;
+ }
+
+ using var context = new UniversityDatabase();
+
+ context.Students.Add(newStudent);
+ context.SaveChanges();
+
+ return newStudent.GetViewModel;
+ }
+
+ public StudentViewModel? Update(StudentBindingModel model)
+ {
+ using var context = new UniversityDatabase();
+
+ var student = context.Students.FirstOrDefault(x => x.Id == model.Id);
+
+ if (student == null)
+ {
+ return null;
+ }
+
+ student.Update(model);
+ context.SaveChanges();
+
+ return student.GetViewModel;
+ }
+
+ public StudentViewModel? Delete(StudentBindingModel model)
+ {
+ using var context = new UniversityDatabase();
+
+ var element = context.Students.FirstOrDefault(rec => rec.Id == model.Id);
+
+ if (element != null)
+ {
+ context.Students.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+
+ return null;
+ }
}
}