From 047c48fa86fdd4d2cb63dbcd0879aed18194323a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Thu, 6 Apr 2023 21:07:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D1=81=D1=83=D1=89?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SchoolAgainStudy/SchoolAgainStudy.sln | 12 +- .../BusinessLogic/DiyLogic.cs | 122 +++++++++++++++++ .../BusinessLogic/InterestLogic.cs | 118 ++++++++++++++++ .../BusinessLogic/LessonLogic.cs | 118 ++++++++++++++++ .../BusinessLogic/MaterialLogic.cs | 118 ++++++++++++++++ .../BusinessLogic/ProductLogic.cs | 120 +++++++++++++++++ .../BusinessLogic/StudentLogic.cs | 125 +++++++++++++++++ .../BusinessLogic/TaskLogic.cs | 115 ++++++++++++++++ .../BusinessLogic/TeacherLogic.cs | 126 ++++++++++++++++++ .../SchoolAgainStudyBusinessLogic.csproj | 26 ++++ .../Implements/DiyStorage.cs | 10 +- .../Implements/InterestStorage.cs | 6 +- .../Implements/LessonStorage.cs | 10 +- .../Implements/MaterialStorage.cs | 6 +- .../Implements/ProductStorage.cs | 8 +- .../Implements/TaskStorage.cs | 6 +- 16 files changed, 1016 insertions(+), 30 deletions(-) create mode 100644 SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/DiyLogic.cs create mode 100644 SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/InterestLogic.cs create mode 100644 SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/LessonLogic.cs create mode 100644 SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/MaterialLogic.cs create mode 100644 SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ProductLogic.cs create mode 100644 SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/StudentLogic.cs create mode 100644 SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/TaskLogic.cs create mode 100644 SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/TeacherLogic.cs create mode 100644 SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj diff --git a/SchoolAgainStudy/SchoolAgainStudy.sln b/SchoolAgainStudy/SchoolAgainStudy.sln index 3ee18f1..96d97b9 100644 --- a/SchoolAgainStudy/SchoolAgainStudy.sln +++ b/SchoolAgainStudy/SchoolAgainStudy.sln @@ -5,11 +5,13 @@ VisualStudioVersion = 17.5.33414.496 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolAgainStudy", "SchoolAgainStudy\SchoolAgainStudy.csproj", "{4D41BF0A-F462-45D6-9488-C11CB7711E34}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolAgainStudyDataModels", "SchoolAgainStudyDataModels\SchoolAgainStudyDataModels.csproj", "{F4F2EDE5-975A-4A60-8C1F-9AEF303AC0B3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolAgainStudyDataModels", "SchoolAgainStudyDataModels\SchoolAgainStudyDataModels.csproj", "{F4F2EDE5-975A-4A60-8C1F-9AEF303AC0B3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolAgainStudyContracts", "SchoolAgainStudyContracts\SchoolAgainStudyContracts.csproj", "{5D678B52-4EDB-439A-BF15-E18280D39585}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolAgainStudyContracts", "SchoolAgainStudyContracts\SchoolAgainStudyContracts.csproj", "{5D678B52-4EDB-439A-BF15-E18280D39585}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolAgainStudyDataBaseImplements", "SchoolAgainStudyDataBaseImplements\SchoolAgainStudyDataBaseImplements.csproj", "{7B3598B3-8AE0-4353-B967-0D9141F2798F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolAgainStudyDataBaseImplements", "SchoolAgainStudyDataBaseImplements\SchoolAgainStudyDataBaseImplements.csproj", "{7B3598B3-8AE0-4353-B967-0D9141F2798F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolAgainStudyBusinessLogic", "SchoolAgainStudyBusinessLogic\SchoolAgainStudyBusinessLogic.csproj", "{B4AA1719-2B64-4DE1-9C26-D81E1A2BD7A7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {7B3598B3-8AE0-4353-B967-0D9141F2798F}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B3598B3-8AE0-4353-B967-0D9141F2798F}.Release|Any CPU.ActiveCfg = Release|Any CPU {7B3598B3-8AE0-4353-B967-0D9141F2798F}.Release|Any CPU.Build.0 = Release|Any CPU + {B4AA1719-2B64-4DE1-9C26-D81E1A2BD7A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4AA1719-2B64-4DE1-9C26-D81E1A2BD7A7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4AA1719-2B64-4DE1-9C26-D81E1A2BD7A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4AA1719-2B64-4DE1-9C26-D81E1A2BD7A7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/DiyLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/DiyLogic.cs new file mode 100644 index 0000000..0e5ef6d --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/DiyLogic.cs @@ -0,0 +1,122 @@ +using Microsoft.Extensions.Logging; +using SchoolAgainStudyContracts.BindingModel; +using SchoolAgainStudyContracts.BusinessLogicContracts; +using SchoolAgainStudyContracts.SearchModel; +using SchoolAgainStudyContracts.StorageContracts; +using SchoolAgainStudyContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SchoolAgainStudyBusinessLogic.BusinessLogic +{ + public class DiyLogic : IDiyLogic + { + private readonly ILogger _logger; + private readonly IDiyStorage _diyStorage; + public DiyLogic(ILogger logger, IDiyStorage diyStorage) + { + _logger = logger; + _diyStorage = diyStorage; + } + public List? ReadList(DiySearchModel? model) + { + _logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _diyStorage.GetFullList() : _diyStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public DiyViewModel? ReadElement(DiySearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Title:{Title}. Id:{ Id}", model.Title, model.Id); + var element = _diyStorage.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(DiyBindingModel model) + { + CheckModel(model); + if (_diyStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(DiyBindingModel model) + { + CheckModel(model); + if (_diyStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(DiyBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_diyStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(DiyBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Не задано название", nameof(model.Title)); + } + if (string.IsNullOrEmpty(model.Description)) + { + throw new ArgumentNullException("Не задано описание", nameof(model.Description)); + } + if (model.StudentId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор школьника", nameof(model.StudentId)); + } + if (model.TaskId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор задания", nameof(model.TaskId)); + } + + _logger.LogInformation("Diy. Titel:{Title}.Description{Description}.StudentId:{StudentId}.TaskId{TaskId} Id: {Id}", model.Title,model.Description, model.StudentId,model.TaskId, model.Id); + var element = _diyStorage.GetElement(new DiySearchModel + { + Title = model.Title, + StudentId = model.StudentId + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Поделка с таким названием уже есть"); + } + } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/InterestLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/InterestLogic.cs new file mode 100644 index 0000000..55036f9 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/InterestLogic.cs @@ -0,0 +1,118 @@ +using Microsoft.Extensions.Logging; +using SchoolAgainStudyContracts.BindingModel; +using SchoolAgainStudyContracts.BusinessLogicContracts; +using SchoolAgainStudyContracts.SearchModel; +using SchoolAgainStudyContracts.StorageContracts; +using SchoolAgainStudyContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.BusinessLogic +{ + public class InterestLogic : IInterestLogic + { + private readonly ILogger _logger; + private readonly IInterestStorage _interestStorage; + public InterestLogic(ILogger logger, IInterestStorage interestStorage) + { + _logger = logger; + _interestStorage = interestStorage; + } + public List? ReadList(InterestSearchModel? model) + { + _logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _interestStorage.GetFullList() : _interestStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public InterestViewModel? ReadElement(InterestSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Title:{Title}. Id:{ Id}", model.Title, model.Id); + var element = _interestStorage.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(InterestBindingModel model) + { + CheckModel(model); + if (_interestStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(InterestBindingModel model) + { + CheckModel(model); + if (_interestStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(InterestBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_interestStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(InterestBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Не задано название", nameof(model.Title)); + } + if (string.IsNullOrEmpty(model.Description)) + { + throw new ArgumentNullException("Не задан пароль", nameof(model.Description)); + } + if (model.StudentId <=0) + { + throw new ArgumentNullException("Неверно задан идентификатор школьника", nameof(model.StudentId)); + } + _logger.LogInformation("Interest. Titel:{Title}.Description{Description}.StudentId:{StudentId}. Id: {Id}", model.Title, model.Description, model.StudentId, model.Id); + var element = _interestStorage.GetElement(new InterestSearchModel + { + Title = model.Title, + StudentId = model.StudentId + }); + if (element != null && element.Id != model.Id ) + { + throw new InvalidOperationException("Интерес с таким названием уже есть"); + } + } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/LessonLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/LessonLogic.cs new file mode 100644 index 0000000..3d198d7 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/LessonLogic.cs @@ -0,0 +1,118 @@ +using Microsoft.Extensions.Logging; +using SchoolAgainStudyContracts.BindingModel; +using SchoolAgainStudyContracts.BusinessLogicContracts; +using SchoolAgainStudyContracts.SearchModel; +using SchoolAgainStudyContracts.StorageContracts; +using SchoolAgainStudyContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.BusinessLogic +{ + public class LessonLogic : ILessonLogic + { + private readonly ILogger _logger; + private readonly ILessonStorage _lessonStorage; + public LessonLogic(ILogger logger, ILessonStorage lessonStorage) + { + _logger = logger; + _lessonStorage = lessonStorage; + } + public List? ReadList(LessonSearchModel? model) + { + _logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _lessonStorage.GetFullList() : _lessonStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public LessonViewModel? ReadElement(LessonSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Title:{Title}. Id:{ Id}", model.Title, model.Id); + var element = _lessonStorage.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(LessonBindingModel model) + { + CheckModel(model); + if (_lessonStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(LessonBindingModel model) + { + CheckModel(model); + if (_lessonStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(LessonBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_lessonStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(LessonBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Не задано название", nameof(model.Title)); + } + if (model.TeacherId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор учителя", nameof(model.TeacherId)); + } + if (model.ProductId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор изделия", nameof(model.ProductId)); + } + _logger.LogInformation("Lesson. Titel:{Title}.ProductId{ProductId}.TeacherId:{TeacherId}. Id: {Id}", model.Title, model.ProductId, model.TeacherId, model.Id); + var element = _lessonStorage.GetElement(new LessonSearchModel + { + Title = model.Title, + TeacherId = model.TeacherId + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Занятие с таким названием уже есть"); + } + } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/MaterialLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/MaterialLogic.cs new file mode 100644 index 0000000..6d4491b --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/MaterialLogic.cs @@ -0,0 +1,118 @@ +using Microsoft.Extensions.Logging; +using SchoolAgainStudyContracts.BindingModel; +using SchoolAgainStudyContracts.BusinessLogicContracts; +using SchoolAgainStudyContracts.SearchModel; +using SchoolAgainStudyContracts.StorageContracts; +using SchoolAgainStudyContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.BusinessLogic +{ + public class MaterialLogic : IMaterialLogic + { + private readonly ILogger _logger; + private readonly IMaterialStorage _materialStorage; + public MaterialLogic(ILogger logger, IMaterialStorage materialStorage) + { + _logger = logger; + _materialStorage = materialStorage; + } + public List? ReadList(MaterialSearchModel? model) + { + _logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _materialStorage.GetFullList() : _materialStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public MaterialViewModel? ReadElement(MaterialSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Title:{Title}. Id:{ Id}", model.Title, model.Id); + var element = _materialStorage.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(MaterialBindingModel model) + { + CheckModel(model); + if (_materialStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(MaterialBindingModel model) + { + CheckModel(model); + if (_materialStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(MaterialBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_materialStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(MaterialBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Не задано название", nameof(model.Title)); + } + if (string.IsNullOrEmpty(model.SphereUse)) + { + throw new ArgumentNullException("Не задана сфера использования", nameof(model.SphereUse)); + } + if (model.TeacherId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор учителя", nameof(model.TeacherId)); + } + _logger.LogInformation("Material. Titel:{Title}.SphereUse{SphereUse}.TeacherId:{TeacherId}. Id: {Id}", model.Title, model.SphereUse, model.TeacherId, model.Id); + var element = _materialStorage.GetElement(new MaterialSearchModel + { + Title = model.Title, + TeacherId = model.TeacherId + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Материалы с таким названием уже есть"); + } + } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ProductLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ProductLogic.cs new file mode 100644 index 0000000..48c1e75 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ProductLogic.cs @@ -0,0 +1,120 @@ +using Microsoft.Extensions.Logging; +using SchoolAgainStudyContracts.BindingModel; +using SchoolAgainStudyContracts.BusinessLogicContracts; +using SchoolAgainStudyContracts.SearchModel; +using SchoolAgainStudyContracts.StorageContracts; +using SchoolAgainStudyContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.BusinessLogic +{ + public class ProductLogic : IProductLogic + { + private readonly ILogger _logger; + private readonly IProductStorage _productStorage; + public ProductLogic(ILogger logger, IProductStorage productStorage) + { + _logger = logger; + _productStorage = productStorage; + } + public List? ReadList(ProductSearchModel? model) + { + _logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ProductViewModel? ReadElement(ProductSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Title:{Title}. Id:{ Id}", model.Title, model.Id); + var element = _productStorage.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(ProductBindingModel model) + { + CheckModel(model); + if (_productStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ProductBindingModel model) + { + CheckModel(model); + if (_productStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ProductBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_productStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ProductBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Не задано название", nameof(model.Title)); + } + if (string.IsNullOrEmpty(model.Description)) + { + throw new ArgumentNullException("Не задано описание", nameof(model.Description)); + } + if (model.StudentId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор школьника", nameof(model.StudentId)); + } + + + _logger.LogInformation("Product. Titel:{Title}.Description{Description}.StudentId:{StudentId}. Id: {Id}", model.Title, model.Description, model.StudentId, model.Id); + var element = _productStorage.GetElement(new ProductSearchModel + { + Title = model.Title, + StudentId = model.StudentId + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/StudentLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/StudentLogic.cs new file mode 100644 index 0000000..8953547 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/StudentLogic.cs @@ -0,0 +1,125 @@ +using Microsoft.Extensions.Logging; +using SchoolAgainStudyContracts.BindingModel; +using SchoolAgainStudyContracts.BusinessLogicContracts; +using SchoolAgainStudyContracts.SearchModel; +using SchoolAgainStudyContracts.StorageContracts; +using SchoolAgainStudyContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.Новая_папка +{ + public class StudentLogic : IStudentLogic + { + private readonly ILogger _logger; + private readonly IStudentStorage _studentStorage; + public StudentLogic(ILogger logger, IStudentStorage studentStorage) + { + _logger = logger; + _studentStorage = studentStorage; + } + public List? ReadList(StudentSearchModel? model) + { + _logger.LogInformation("ReadList. Login:{Login}.Id:{ Id}", model?.Login, model?.Id); + var list = model == null ? _studentStorage.GetFullList() : _studentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public StudentViewModel? ReadElement(StudentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Login:{Login}. Id:{ Id}", model.Login, model.Id); + var element = _studentStorage.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(StudentBindingModel model) + { + CheckModel(model); + if (_studentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(StudentBindingModel model) + { + CheckModel(model); + if (_studentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(StudentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_studentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(StudentBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Не задан логин", nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Не задан пароль", nameof(model.Password)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Не задана почта", nameof(model.Email)); + } + if (model.Class <= 0 || model.Class > 11) + { + throw new ArgumentNullException("Не правильно задан класс", nameof(model.Class)); + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Не задано ФИО", nameof(model.Name)); + } + _logger.LogInformation("Student. Name:{Name}.Class:{ Class}. Email{Email}.Login{Login} .Password{Password} Id: {Id}", model.Name, model.Class,model.Email,model.Login,model.Password, model.Id); + var element = _studentStorage.GetElement(new StudentSearchModel + { + Login = model.Login + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Школьник с таким логином уже есть"); + } + } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/TaskLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/TaskLogic.cs new file mode 100644 index 0000000..6cdd12e --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/TaskLogic.cs @@ -0,0 +1,115 @@ +using Microsoft.Extensions.Logging; +using SchoolAgainStudyContracts.BindingModel; +using SchoolAgainStudyContracts.BusinessLogicContracts; +using SchoolAgainStudyContracts.SearchModel; +using SchoolAgainStudyContracts.StorageContracts; +using SchoolAgainStudyContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.BusinessLogic +{ + public class TaskLogic : ITaskLogic + { + private readonly ILogger _logger; + private readonly ITaskStorage _taskStorage; + public TaskLogic(ILogger logger, ITaskStorage taskStorage) + { + _logger = logger; + _taskStorage = taskStorage; + } + public List? ReadList(TaskSearchModel? model) + { + _logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _taskStorage.GetFullList() : _taskStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public TaskViewModel? ReadElement(TaskSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Title:{Title}. Id:{ Id}", model.Title, model.Id); + var element = _taskStorage.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(TaskBindingModel model) + { + CheckModel(model); + if (_taskStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(TaskBindingModel model) + { + CheckModel(model); + if (_taskStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(TaskBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_taskStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(TaskBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Не задано название", nameof(model.Title)); + } + if (model.TeacherId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор учителя", nameof(model.TeacherId)); + } + + _logger.LogInformation("Task. Titel:{Title}.TeacherId:{TeacherId}. Id: {Id}", model.Title, model.TeacherId, model.Id); + var element = _taskStorage.GetElement(new TaskSearchModel + { + Title = model.Title, + TeacherId = model.TeacherId + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Задание с таким названием уже есть"); + } + } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/TeacherLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/TeacherLogic.cs new file mode 100644 index 0000000..e53159a --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/TeacherLogic.cs @@ -0,0 +1,126 @@ +using Microsoft.Extensions.Logging; +using SchoolAgainStudyBusinessLogic.Новая_папка; +using SchoolAgainStudyContracts.BindingModel; +using SchoolAgainStudyContracts.BusinessLogicContracts; +using SchoolAgainStudyContracts.SearchModel; +using SchoolAgainStudyContracts.StorageContracts; +using SchoolAgainStudyContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.BusinessLogic +{ + public class TeacherLogic : ITeacherLogic + { + private readonly ILogger _logger; + private readonly ITeacherStorage _teacherStorage; + public TeacherLogic(ILogger logger, ITeacherStorage teacherStorage) + { + _logger = logger; + _teacherStorage = teacherStorage; + } + public List? ReadList(TeacherSearchModel? model) + { + _logger.LogInformation("ReadList. Login:{Login}.Id:{ Id}", model?.Login, model?.Id); + var list = model == null ? _teacherStorage.GetFullList() : _teacherStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public TeacherViewModel? ReadElement(TeacherSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Login:{Login}. Id:{ Id}", model.Login, model.Id); + var element = _teacherStorage.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(TeacherBindingModel model) + { + CheckModel(model); + if (_teacherStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(TeacherBindingModel model) + { + CheckModel(model); + if (_teacherStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(TeacherBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_teacherStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(TeacherBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Не задан логин", nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Не задан пароль", nameof(model.Password)); + } + if (string.IsNullOrEmpty(model.Post)) + { + throw new ArgumentNullException("Не задана должность", nameof(model.Post)); + } + if (string.IsNullOrEmpty(model.Phone)) + { + throw new ArgumentNullException("Не задан телефон", nameof(model.Phone)); + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Не задано ФИО", nameof(model.Name)); + } + _logger.LogInformation("Teacher. Name:{Name}.Phone:{ Phone}. Post{Post}.Login{Login} .Password{Password} Id: {Id}", model.Name, model.Phone, model.Post, model.Login, model.Password, model.Id); + var element = _teacherStorage.GetElement(new TeacherSearchModel + { + Login = model.Login + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Учитель с таким логином уже есть"); + } + } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj new file mode 100644 index 0000000..f7f6cde --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj @@ -0,0 +1,26 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + + + + diff --git a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/DiyStorage.cs b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/DiyStorage.cs index 13b10ac..2f16f7c 100644 --- a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/DiyStorage.cs +++ b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/DiyStorage.cs @@ -20,7 +20,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return context.Diys .Include(x => x.Interests) .ThenInclude(x => x.Interest) - .Include(x => x.Task) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -39,7 +38,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return context.Diys .Include(x => x.Interests) .ThenInclude(x => x.Interest) - .Include(x => x.Task) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo && x.StudentId == model.StudentId) .ToList() .Select(x => x.GetViewModel) @@ -49,7 +47,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return context.Diys .Include(x => x.Interests) .ThenInclude(x => x.Interest) - .Include(x => x.Task) .Where(x => x.StudentId == model.StudentId ) .ToList() .Select(x => x.GetViewModel) @@ -60,7 +57,7 @@ namespace SchoolAgainStudyDataBaseImplements.Implements public DiyViewModel? GetElement(DiySearchModel model) { - if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) + if ((string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) || !model.StudentId.HasValue) { return null; } @@ -68,9 +65,8 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return context.Diys .Include(x => x.Interests) .ThenInclude(x => x.Interest) - .Include(x => x.Task) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || - (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || + (model.Id.HasValue && x.Id == model.Id)) && x.StudentId==model.StudentId) ?.GetViewModel; } diff --git a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/InterestStorage.cs b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/InterestStorage.cs index a801569..dd00d84 100644 --- a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/InterestStorage.cs +++ b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/InterestStorage.cs @@ -37,14 +37,14 @@ namespace SchoolAgainStudyDataBaseImplements.Implements public InterestViewModel? GetElement(InterestSearchModel model) { - if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) + if ((string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) || !model.StudentId.HasValue) { return null; } using var context = new SchoolDataBase(); return context.Interests - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || - (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || + (model.Id.HasValue && x.Id == model.Id)) && x.StudentId==model.StudentId) ?.GetViewModel; } diff --git a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/LessonStorage.cs b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/LessonStorage.cs index 0a9d00f..e6abc37 100644 --- a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/LessonStorage.cs +++ b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/LessonStorage.cs @@ -20,7 +20,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return context.Lessons .Include(x => x.Materials) .ThenInclude(x => x.Material) - .Include(x => x.Product) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -38,7 +37,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return context.Lessons .Include(x => x.Materials) .ThenInclude(x => x.Material) - .Include(x => x.Product) .Where(x => x.DateEvent >= model.DateFrom && x.DateEvent <= model.DateTo && x.TeacherId == model.TeacherId) .ToList() .Select(x => x.GetViewModel) @@ -47,7 +45,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return context.Lessons .Include(x => x.Materials) .ThenInclude(x => x.Material) - .Include(x => x.Product) .Where(x => x.TeacherId == model.TeacherId) .ToList() .Select(x => x.GetViewModel) @@ -56,7 +53,7 @@ namespace SchoolAgainStudyDataBaseImplements.Implements public LessonViewModel? GetElement(LessonSearchModel model) { - if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) + if ((string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) || !model.TeacherId.HasValue) { return null; } @@ -64,9 +61,8 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return context.Lessons .Include(x => x.Materials) .ThenInclude(x => x.Material) - .Include(x => x.Product) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || - (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || + (model.Id.HasValue && x.Id == model.Id)) && x.TeacherId == model.TeacherId) ?.GetViewModel; } diff --git a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/MaterialStorage.cs b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/MaterialStorage.cs index 8c09b9e..35ac440 100644 --- a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/MaterialStorage.cs +++ b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/MaterialStorage.cs @@ -36,14 +36,14 @@ namespace SchoolAgainStudyDataBaseImplements.Implements public MaterialViewModel? GetElement(MaterialSearchModel model) { - if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) + if ((string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) || !model.TeacherId.HasValue) { return null; } using var context = new SchoolDataBase(); return context.Materials - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || - (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || + (model.Id.HasValue && x.Id == model.Id)) && x.TeacherId == model.TeacherId) ?.GetViewModel; } diff --git a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/ProductStorage.cs b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/ProductStorage.cs index 693c12a..57de281 100644 --- a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/ProductStorage.cs +++ b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/ProductStorage.cs @@ -33,7 +33,7 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return new(); } using var context = new SchoolDataBase(); - if (model.StudentId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) + if (model.StudentId.HasValue && model.DateFrom.HasValue && model.DateTo != null) { return context.Products .Include(x => x.Interests) @@ -55,7 +55,7 @@ namespace SchoolAgainStudyDataBaseImplements.Implements public ProductViewModel? GetElement(ProductSearchModel model) { - if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) + if ((string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) || !model.StudentId.HasValue) { return null; } @@ -63,8 +63,8 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return context.Products .Include(x => x.Interests) .ThenInclude(x => x.Interest) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || - (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || + (model.Id.HasValue && x.Id == model.Id)) && x.StudentId == model.StudentId) ?.GetViewModel; } diff --git a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/TaskStorage.cs b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/TaskStorage.cs index 52d9f4d..0e05806 100644 --- a/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/TaskStorage.cs +++ b/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Implements/TaskStorage.cs @@ -54,7 +54,7 @@ namespace SchoolAgainStudyDataBaseImplements.Implements public TaskViewModel? GetElement(TaskSearchModel model) { - if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) + if ((string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) || !model.TeacherId.HasValue) { return null; } @@ -62,8 +62,8 @@ namespace SchoolAgainStudyDataBaseImplements.Implements return context.Tasks .Include(x => x.Materials) .ThenInclude(x => x.Material) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || - (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) || + (model.Id.HasValue && x.Id == model.Id)) && x.TeacherId == model.TeacherId) ?.GetViewModel; }