From 59f18199a8a918006c20da38fa87304a111b1323 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Tue, 14 May 2024 23:07:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=81=D1=82=D0=B0=D0=BF=D0=B8=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/DirectionLogic.cs | 103 +++++++++++++ .../BusinessLogic/ExamLogic.cs | 92 ++++++++++++ .../BusinessLogic/ResultLogic.cs | 91 +++++++++++ .../BusinessLogic/StudentLogic.cs | 97 ++++++++++++ .../BusinessLogic/SubjectLogic.cs | 97 ++++++++++++ .../StoragesContracts/IDirectionStorage.cs | 12 +- .../StoragesContracts/IExamStorage.cs | 12 +- .../StoragesContracts/IResultStorage.cs | 12 +- .../StoragesContracts/IStudentStorage.cs | 12 +- .../StoragesContracts/ISubjectStorage.cs | 12 +- .../Controllers/MainController.cs | 141 +++++++++++++++--- TaskTrackerRestApi/Program.cs | 13 ++ TaskTrackerView/Program.cs | 14 +- 13 files changed, 656 insertions(+), 52 deletions(-) create mode 100644 TaskTrackerBusinessLogics/BusinessLogic/DirectionLogic.cs create mode 100644 TaskTrackerBusinessLogics/BusinessLogic/ExamLogic.cs create mode 100644 TaskTrackerBusinessLogics/BusinessLogic/ResultLogic.cs create mode 100644 TaskTrackerBusinessLogics/BusinessLogic/StudentLogic.cs create mode 100644 TaskTrackerBusinessLogics/BusinessLogic/SubjectLogic.cs diff --git a/TaskTrackerBusinessLogics/BusinessLogic/DirectionLogic.cs b/TaskTrackerBusinessLogics/BusinessLogic/DirectionLogic.cs new file mode 100644 index 0000000..03a22c8 --- /dev/null +++ b/TaskTrackerBusinessLogics/BusinessLogic/DirectionLogic.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TaskTrackerContracts.BindingModels; +using TaskTrackerContracts.BusinessLogicsContracts; +using TaskTrackerContracts.SearchModels; +using TaskTrackerContracts.StoragesContracts; +using TaskTrackerContracts.ViewModels; + +namespace TaskTrackerBusinessLogics.BusinessLogic +{ + public class DirectionLogic : IDirectionLogic + { + private readonly IDirectionStorage _directionStorage; + + public DirectionLogic(IDirectionStorage directionStorage) + { + _directionStorage = directionStorage; + } + + public List? ReadList(DirectionSearchModel? model) + { + var list = model == null ? _directionStorage.GetFullList() : _directionStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public DirectionViewModel? ReadElement(DirectionSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _directionStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public bool Create(DirectionBindingModel model) + { + CheckModel(model); + if (_directionStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Update(DirectionBindingModel model) + { + CheckModel(model); + if (_directionStorage.Update(model) == null) + { + + return false; + } + return true; + } + + public bool Delete(DirectionBindingModel model) + { + CheckModel(model, false); + if (_directionStorage.Delete(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(DirectionBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия", nameof(model.Name)); + } + + var element = _directionStorage.GetElement(new DirectionSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Организация с таким названием уже есть"); + } + } + } +} diff --git a/TaskTrackerBusinessLogics/BusinessLogic/ExamLogic.cs b/TaskTrackerBusinessLogics/BusinessLogic/ExamLogic.cs new file mode 100644 index 0000000..73408d7 --- /dev/null +++ b/TaskTrackerBusinessLogics/BusinessLogic/ExamLogic.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TaskTrackerContracts.BindingModels; +using TaskTrackerContracts.BusinessLogicsContracts; +using TaskTrackerContracts.SearchModels; +using TaskTrackerContracts.StoragesContracts; +using TaskTrackerContracts.ViewModels; + +namespace TaskTrackerBusinessLogics.BusinessLogic +{ + public class ResultLogic : IResultLogic + { + private readonly IResultStorage _resultStorage; + public ResultLogic(IResultStorage resultStorage) + { + _resultStorage = resultStorage; + } + public List? ReadList(ResultSearchModel? model) + { + var list = model == null ? _resultStorage.GetFullList() : _resultStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + public ResultViewModel? ReadElement(ResultSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _resultStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + public bool Create(ResultBindingModel model) + { + CheckModel(model); + if (_resultStorage.Insert(model) == null) + { + return false; + } + return true; + } + public bool Update(ResultBindingModel model) + { + CheckModel(model); + if (_resultStorage.Update(model) == null) + { + return false; + } + return true; + } + public bool Delete(ResultBindingModel model) + { + CheckModel(model, false); + if (_resultStorage.Delete(model) == null) + { + return false; + } + return true; + } + private void CheckModel(ResultBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + var element = _resultStorage.GetElement(new ResultSearchModel + { + StudentId = model.StudentId, + SubjectId = model.SubjectId, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Проект с таким названием уже есть"); + } + } + } +} diff --git a/TaskTrackerBusinessLogics/BusinessLogic/ResultLogic.cs b/TaskTrackerBusinessLogics/BusinessLogic/ResultLogic.cs new file mode 100644 index 0000000..fb66309 --- /dev/null +++ b/TaskTrackerBusinessLogics/BusinessLogic/ResultLogic.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TaskTrackerContracts.BindingModels; +using TaskTrackerContracts.BusinessLogicsContracts; +using TaskTrackerContracts.SearchModels; +using TaskTrackerContracts.StoragesContracts; +using TaskTrackerContracts.ViewModels; + +namespace TaskTrackerBusinessLogics.BusinessLogic +{ + public class ExamLogic : IExamLogic + { + private readonly IExamStorage _examStorage; + public ExamLogic(IExamStorage examStorage) + { + _examStorage = examStorage; + } + public List? ReadList(ExamSearchModel? model) + { + var list = model == null ? _examStorage.GetFullList() : _examStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + public ExamViewModel? ReadElement(ExamSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _examStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + public bool Create(ExamBindingModel model) + { + CheckModel(model); + if (_examStorage.Insert(model) == null) + { + return false; + } + return true; + } + public bool Update(ExamBindingModel model) + { + CheckModel(model); + if (_examStorage.Update(model) == null) + { + return false; + } + return true; + } + public bool Delete(ExamBindingModel model) + { + CheckModel(model, false); + if (_examStorage.Delete(model) == null) + { + return false; + } + return true; + } + private void CheckModel(ExamBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + var element = _examStorage.GetElement(new ExamSearchModel + { + SubjectId = model.SubjectId, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Проект с таким названием уже есть"); + } + } + } +} diff --git a/TaskTrackerBusinessLogics/BusinessLogic/StudentLogic.cs b/TaskTrackerBusinessLogics/BusinessLogic/StudentLogic.cs new file mode 100644 index 0000000..3c311c9 --- /dev/null +++ b/TaskTrackerBusinessLogics/BusinessLogic/StudentLogic.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TaskTrackerContracts.BindingModels; +using TaskTrackerContracts.BusinessLogicsContracts; +using TaskTrackerContracts.SearchModels; +using TaskTrackerContracts.StoragesContracts; +using TaskTrackerContracts.ViewModels; + +namespace TaskTrackerBusinessLogics.BusinessLogic +{ + public class SubjectLogic : ISubjectLogic + { + private readonly ISubjectStorage _subjectStorage; + public SubjectLogic(ISubjectStorage subjectStorage) + { + _subjectStorage = subjectStorage; + } + + public List? ReadList(SubjectSearchModel? model) + { + var list = model == null ? _subjectStorage.GetFullList() : _subjectStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public SubjectViewModel? ReadElement(SubjectSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _subjectStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public bool Create(SubjectBindingModel model) + { + CheckModel(model); + if (_subjectStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Update(SubjectBindingModel model) + { + CheckModel(model); + if (_subjectStorage.Update(model) == null) + { + return false; + } + return true; + } + + public bool Delete(SubjectBindingModel model) + { + CheckModel(model, false); + if (_subjectStorage.Delete(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(SubjectBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + var element = _subjectStorage.GetElement(new SubjectSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пользователя с таким логином(почтой) уже есть"); + } + } + } + +} diff --git a/TaskTrackerBusinessLogics/BusinessLogic/SubjectLogic.cs b/TaskTrackerBusinessLogics/BusinessLogic/SubjectLogic.cs new file mode 100644 index 0000000..7cff3bf --- /dev/null +++ b/TaskTrackerBusinessLogics/BusinessLogic/SubjectLogic.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TaskTrackerContracts.BindingModels; +using TaskTrackerContracts.BusinessLogicsContracts; +using TaskTrackerContracts.SearchModels; +using TaskTrackerContracts.StoragesContracts; +using TaskTrackerContracts.ViewModels; + +namespace TaskTrackerBusinessLogics.BusinessLogic +{ + public class StudentLogic : IStudentLogic + { + private readonly IStudentStorage _studentStorage; + public StudentLogic(IStudentStorage studentStorage) + { + _studentStorage = studentStorage; + } + + public List? ReadList(StudentSearchModel? model) + { + var list = model == null ? _studentStorage.GetFullList() : _studentStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public StudentViewModel? ReadElement(StudentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _studentStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public bool Create(StudentBindingModel model) + { + CheckModel(model); + if (_studentStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Update(StudentBindingModel model) + { + CheckModel(model); + if (_studentStorage.Update(model) == null) + { + return false; + } + return true; + } + + public bool Delete(StudentBindingModel model) + { + CheckModel(model, false); + if (_studentStorage.Delete(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(StudentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + var element = _studentStorage.GetElement(new StudentSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пользователя с таким логином(почтой) уже есть"); + } + } + } + +} diff --git a/TaskTrackerContracts/StoragesContracts/IDirectionStorage.cs b/TaskTrackerContracts/StoragesContracts/IDirectionStorage.cs index 60bfd31..d0eb611 100644 --- a/TaskTrackerContracts/StoragesContracts/IDirectionStorage.cs +++ b/TaskTrackerContracts/StoragesContracts/IDirectionStorage.cs @@ -11,11 +11,11 @@ namespace TaskTrackerContracts.StoragesContracts { public interface IDirectionStorage { - /*List GetFullList(); - List GetFilteredList(DirectionSearchModel model); - DirectionBindingModel? GetElement(DirectionSearchModel model); - DirectionBindingModel? Insert(DirectionBindingModel model); - DirectionBindingModel? Update(DirectionBindingModel model); - DirectionBindingModel? Delete(DirectionBindingModel model);*/ + List GetFullList(); + List GetFilteredList(DirectionSearchModel model); + DirectionViewModel? GetElement(DirectionSearchModel model); + DirectionViewModel? Insert(DirectionBindingModel model); + DirectionViewModel? Update(DirectionBindingModel model); + DirectionViewModel? Delete(DirectionBindingModel model); } } diff --git a/TaskTrackerContracts/StoragesContracts/IExamStorage.cs b/TaskTrackerContracts/StoragesContracts/IExamStorage.cs index 4edb345..0b9b154 100644 --- a/TaskTrackerContracts/StoragesContracts/IExamStorage.cs +++ b/TaskTrackerContracts/StoragesContracts/IExamStorage.cs @@ -11,11 +11,11 @@ namespace TaskTrackerContracts.StoragesContracts { public interface IExamStorage { - /*List GetFullList(); - List GetFilteredList(ExamSearchModel model); - ExamBindingModel? GetElement(ExamSearchModel model); - ExamBindingModel? Insert(ExamBindingModel model); - ExamBindingModel? Update(ExamBindingModel model); - ExamBindingModel? Delete(ExamBindingModel model);*/ + List GetFullList(); + List GetFilteredList(ExamSearchModel model); + ExamViewModel? GetElement(ExamSearchModel model); + ExamViewModel? Insert(ExamBindingModel model); + ExamViewModel? Update(ExamBindingModel model); + ExamViewModel? Delete(ExamBindingModel model); } } diff --git a/TaskTrackerContracts/StoragesContracts/IResultStorage.cs b/TaskTrackerContracts/StoragesContracts/IResultStorage.cs index ed0d66a..887e59f 100644 --- a/TaskTrackerContracts/StoragesContracts/IResultStorage.cs +++ b/TaskTrackerContracts/StoragesContracts/IResultStorage.cs @@ -11,11 +11,11 @@ namespace TaskTrackerContracts.StoragesContracts { public interface IResultStorage { - /*List GetFullList(); - List GetFilteredList(ResultSearchModel model); - ResultBindingModel? GetElement(ResultSearchModel model); - ResultBindingModel? Insert(ResultBindingModel model); - ResultBindingModel? Update(ResultBindingModel model); - ResultBindingModel? Delete(ResultBindingModel model);*/ + List GetFullList(); + List GetFilteredList(ResultSearchModel model); + ResultViewModel? GetElement(ResultSearchModel model); + ResultViewModel? Insert(ResultBindingModel model); + ResultViewModel? Update(ResultBindingModel model); + ResultViewModel? Delete(ResultBindingModel model); } } diff --git a/TaskTrackerContracts/StoragesContracts/IStudentStorage.cs b/TaskTrackerContracts/StoragesContracts/IStudentStorage.cs index 275f3dc..4e6a8bb 100644 --- a/TaskTrackerContracts/StoragesContracts/IStudentStorage.cs +++ b/TaskTrackerContracts/StoragesContracts/IStudentStorage.cs @@ -11,11 +11,11 @@ namespace TaskTrackerContracts.StoragesContracts { public interface IStudentStorage { - /* List GetFullList(); - List GetFilteredList(StudentSearchModel model); - StudentBindingModel? GetElement(StudentSearchModel model); - StudentBindingModel? Insert(StudentBindingModel model); - StudentBindingModel? Update(StudentBindingModel model); - StudentBindingModel? Delete(StudentBindingModel model);*/ + List GetFullList(); + List GetFilteredList(StudentSearchModel model); + StudentViewModel? GetElement(StudentSearchModel model); + StudentViewModel? Insert(StudentBindingModel model); + StudentViewModel? Update(StudentBindingModel model); + StudentViewModel? Delete(StudentBindingModel model); } } diff --git a/TaskTrackerContracts/StoragesContracts/ISubjectStorage.cs b/TaskTrackerContracts/StoragesContracts/ISubjectStorage.cs index 1506971..cbecdf6 100644 --- a/TaskTrackerContracts/StoragesContracts/ISubjectStorage.cs +++ b/TaskTrackerContracts/StoragesContracts/ISubjectStorage.cs @@ -11,11 +11,11 @@ namespace TaskTrackerContracts.StoragesContracts { public interface ISubjectStorage { - /*List GetFullList(); - List GetFilteredList(SubjectSearchModel model); - SubjectBindingModel? GetElement(SubjectSearchModel model); - SubjectBindingModel? Insert(SubjectBindingModel model); - SubjectBindingModel? Update(SubjectBindingModel model); - SubjectBindingModel? Delete(SubjectBindingModel model);*/ + List GetFullList(); + List GetFilteredList(SubjectSearchModel model); + SubjectViewModel? GetElement(SubjectSearchModel model); + SubjectViewModel? Insert(SubjectBindingModel model); + SubjectViewModel? Update(SubjectBindingModel model); + SubjectViewModel? Delete(SubjectBindingModel model); } } diff --git a/TaskTrackerRestApi/Controllers/MainController.cs b/TaskTrackerRestApi/Controllers/MainController.cs index f5caa06..9ab3037 100644 --- a/TaskTrackerRestApi/Controllers/MainController.cs +++ b/TaskTrackerRestApi/Controllers/MainController.cs @@ -3,6 +3,7 @@ using TaskTrackerContracts.BindingModels; using TaskTrackerContracts.BusinessLogicsContracts; using TaskTrackerContracts.SearchModels; using TaskTrackerContracts.ViewModels; +using TaskTrackerDatabase.Models; namespace TaskTrackerRestApi.Controllers { @@ -11,22 +12,36 @@ namespace TaskTrackerRestApi.Controllers public class MainController : Controller { - private readonly ITaskLogic _task; + /*private readonly ITaskLogic _task; - private readonly IProjectLogic _project; + private readonly IProjectLogic _project;*/ - public MainController(ITaskLogic task, IProjectLogic project) + private readonly IStudentLogic _student; + private readonly ISubjectLogic _subject; + private readonly IResultLogic _result; + private readonly IDirectionLogic _direction; + private readonly IExamLogic _exam; + + + public MainController(IDirectionLogic direction, IStudentLogic student, ISubjectLogic subject, IResultLogic result, IExamLogic exam) { - _task = task; + /*_task = task; _project = project; +*/ + _student = student; + _subject = subject; + _direction = direction; + _result = result; + _exam = exam; + } [HttpGet] - public List? GetProjectList() + public List? GetStudentList() { try { - return _project.ReadList(null); + return _student.ReadList(null); } catch { @@ -34,7 +49,102 @@ namespace TaskTrackerRestApi.Controllers } } - [HttpGet] + + [HttpPost] + public void CreateStudent(StudentBindingModel model) + { + try + { + _student.Create(model); + } + catch + { + throw; + } + } + + [HttpGet] + public List? GetDirectionList() + { + try + { + return _direction.ReadList(null); + } + catch + { + throw; + } + } + + + [HttpPost] + public void CreateSubject(SubjectBindingModel model) + { + try + { + _subject.Create(model); + } + catch + { + throw; + } + } + + [HttpGet] + public List? GetExamList() + { + try + { + return _exam.ReadList(null); + } + catch + { + throw; + } + } + + + [HttpPost] + public void CreateExam(ExamBindingModel model) + { + try + { + _exam.Create(model); + } + catch + { + throw; + } + } + + [HttpGet] + public List? GetResultList() + { + try + { + return _result.ReadList(null); + } + catch + { + throw; + } + } + + + [HttpPost] + public void CreateResult(ResultBindingModel model) + { + try + { + _result.Create(model); + } + catch + { + throw; + } + } + + /*[HttpGet] public ProjectViewModel? GetProject(int projectId) { try @@ -58,19 +168,8 @@ namespace TaskTrackerRestApi.Controllers { throw; } - } + }*/ - [HttpPost] - public void CreateTask(TaskBindingModel model) - { - try - { - _task.CreateTask(model); - } - catch - { - throw; - } - } - } + + } } diff --git a/TaskTrackerRestApi/Program.cs b/TaskTrackerRestApi/Program.cs index a7fe96f..f53f801 100644 --- a/TaskTrackerRestApi/Program.cs +++ b/TaskTrackerRestApi/Program.cs @@ -14,6 +14,19 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); + + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); diff --git a/TaskTrackerView/Program.cs b/TaskTrackerView/Program.cs index 3d8d8ee..1a7d966 100644 --- a/TaskTrackerView/Program.cs +++ b/TaskTrackerView/Program.cs @@ -38,7 +38,19 @@ namespace TaskTrackerView services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient();