Добавление классов бизнес логики для сущностей
This commit is contained in:
parent
80813a1753
commit
047c48fa86
@ -5,11 +5,13 @@ VisualStudioVersion = 17.5.33414.496
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolAgainStudy", "SchoolAgainStudy\SchoolAgainStudy.csproj", "{4D41BF0A-F462-45D6-9488-C11CB7711E34}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolAgainStudy", "SchoolAgainStudy\SchoolAgainStudy.csproj", "{4D41BF0A-F462-45D6-9488-C11CB7711E34}"
|
||||||
EndProject
|
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
|
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
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{7B3598B3-8AE0-4353-B967-0D9141F2798F}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -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<DiyLogic> logger, IDiyStorage diyStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_diyStorage = diyStorage;
|
||||||
|
}
|
||||||
|
public List<DiyViewModel>? 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("Поделка с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<InterestLogic> logger, IInterestStorage interestStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_interestStorage = interestStorage;
|
||||||
|
}
|
||||||
|
public List<InterestViewModel>? 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("Интерес с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<LessonLogic> logger, ILessonStorage lessonStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_lessonStorage = lessonStorage;
|
||||||
|
}
|
||||||
|
public List<LessonViewModel>? 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("Занятие с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<MaterialLogic> logger, IMaterialStorage materialStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_materialStorage = materialStorage;
|
||||||
|
}
|
||||||
|
public List<MaterialViewModel>? 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("Материалы с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<ProductLogic> logger, IProductStorage productStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_productStorage = productStorage;
|
||||||
|
}
|
||||||
|
public List<ProductViewModel>? 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("Изделие с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<StudentLogic> logger, IStudentStorage studentStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_studentStorage = studentStorage;
|
||||||
|
}
|
||||||
|
public List<StudentViewModel>? 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("Школьник с таким логином уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<TaskLogic> logger, ITaskStorage taskStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_taskStorage = taskStorage;
|
||||||
|
}
|
||||||
|
public List<TaskViewModel>? 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("Задание с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<TeacherLogic> logger, ITeacherStorage teacherStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_teacherStorage = teacherStorage;
|
||||||
|
}
|
||||||
|
public List<TeacherViewModel>? 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("Учитель с таким логином уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||||
|
<PackageReference Include="System.Text.Encoding" Version="4.3.0" />
|
||||||
|
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
|
||||||
|
<PackageReference Include="System.Text.Encoding.Extensions" Version="4.3.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="BusinessLogic\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\SchoolAgainStudyDataBaseImplements\SchoolAgainStudyDataBaseImplements.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -20,7 +20,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return context.Diys
|
return context.Diys
|
||||||
.Include(x => x.Interests)
|
.Include(x => x.Interests)
|
||||||
.ThenInclude(x => x.Interest)
|
.ThenInclude(x => x.Interest)
|
||||||
.Include(x => x.Task)
|
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -39,7 +38,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return context.Diys
|
return context.Diys
|
||||||
.Include(x => x.Interests)
|
.Include(x => x.Interests)
|
||||||
.ThenInclude(x => x.Interest)
|
.ThenInclude(x => x.Interest)
|
||||||
.Include(x => x.Task)
|
|
||||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo && x.StudentId == model.StudentId)
|
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo && x.StudentId == model.StudentId)
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
@ -49,7 +47,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return context.Diys
|
return context.Diys
|
||||||
.Include(x => x.Interests)
|
.Include(x => x.Interests)
|
||||||
.ThenInclude(x => x.Interest)
|
.ThenInclude(x => x.Interest)
|
||||||
.Include(x => x.Task)
|
|
||||||
.Where(x => x.StudentId == model.StudentId )
|
.Where(x => x.StudentId == model.StudentId )
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
@ -60,7 +57,7 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
|
|
||||||
public DiyViewModel? GetElement(DiySearchModel model)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
@ -68,9 +65,8 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return context.Diys
|
return context.Diys
|
||||||
.Include(x => x.Interests)
|
.Include(x => x.Interests)
|
||||||
.ThenInclude(x => x.Interest)
|
.ThenInclude(x => x.Interest)
|
||||||
.Include(x => x.Task)
|
.FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
(model.Id.HasValue && x.Id == model.Id)) && x.StudentId==model.StudentId)
|
||||||
(model.Id.HasValue && x.Id == model.Id))
|
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,14 +37,14 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
|
|
||||||
public InterestViewModel? GetElement(InterestSearchModel model)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new SchoolDataBase();
|
using var context = new SchoolDataBase();
|
||||||
return context.Interests
|
return context.Interests
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
.FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
||||||
(model.Id.HasValue && x.Id == model.Id))
|
(model.Id.HasValue && x.Id == model.Id)) && x.StudentId==model.StudentId)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return context.Lessons
|
return context.Lessons
|
||||||
.Include(x => x.Materials)
|
.Include(x => x.Materials)
|
||||||
.ThenInclude(x => x.Material)
|
.ThenInclude(x => x.Material)
|
||||||
.Include(x => x.Product)
|
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -38,7 +37,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return context.Lessons
|
return context.Lessons
|
||||||
.Include(x => x.Materials)
|
.Include(x => x.Materials)
|
||||||
.ThenInclude(x => x.Material)
|
.ThenInclude(x => x.Material)
|
||||||
.Include(x => x.Product)
|
|
||||||
.Where(x => x.DateEvent >= model.DateFrom && x.DateEvent <= model.DateTo && x.TeacherId == model.TeacherId)
|
.Where(x => x.DateEvent >= model.DateFrom && x.DateEvent <= model.DateTo && x.TeacherId == model.TeacherId)
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
@ -47,7 +45,6 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return context.Lessons
|
return context.Lessons
|
||||||
.Include(x => x.Materials)
|
.Include(x => x.Materials)
|
||||||
.ThenInclude(x => x.Material)
|
.ThenInclude(x => x.Material)
|
||||||
.Include(x => x.Product)
|
|
||||||
.Where(x => x.TeacherId == model.TeacherId)
|
.Where(x => x.TeacherId == model.TeacherId)
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
@ -56,7 +53,7 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
|
|
||||||
public LessonViewModel? GetElement(LessonSearchModel model)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
@ -64,9 +61,8 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return context.Lessons
|
return context.Lessons
|
||||||
.Include(x => x.Materials)
|
.Include(x => x.Materials)
|
||||||
.ThenInclude(x => x.Material)
|
.ThenInclude(x => x.Material)
|
||||||
.Include(x => x.Product)
|
.FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
(model.Id.HasValue && x.Id == model.Id)) && x.TeacherId == model.TeacherId)
|
||||||
(model.Id.HasValue && x.Id == model.Id))
|
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,14 +36,14 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
|
|
||||||
public MaterialViewModel? GetElement(MaterialSearchModel model)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new SchoolDataBase();
|
using var context = new SchoolDataBase();
|
||||||
return context.Materials
|
return context.Materials
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
.FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
||||||
(model.Id.HasValue && x.Id == model.Id))
|
(model.Id.HasValue && x.Id == model.Id)) && x.TeacherId == model.TeacherId)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new SchoolDataBase();
|
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
|
return context.Products
|
||||||
.Include(x => x.Interests)
|
.Include(x => x.Interests)
|
||||||
@ -55,7 +55,7 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
|
|
||||||
public ProductViewModel? GetElement(ProductSearchModel model)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
@ -63,8 +63,8 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return context.Products
|
return context.Products
|
||||||
.Include(x => x.Interests)
|
.Include(x => x.Interests)
|
||||||
.ThenInclude(x => x.Interest)
|
.ThenInclude(x => x.Interest)
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
.FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
||||||
(model.Id.HasValue && x.Id == model.Id))
|
(model.Id.HasValue && x.Id == model.Id)) && x.StudentId == model.StudentId)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
|
|
||||||
public TaskViewModel? GetElement(TaskSearchModel model)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
@ -62,8 +62,8 @@ namespace SchoolAgainStudyDataBaseImplements.Implements
|
|||||||
return context.Tasks
|
return context.Tasks
|
||||||
.Include(x => x.Materials)
|
.Include(x => x.Materials)
|
||||||
.ThenInclude(x => x.Material)
|
.ThenInclude(x => x.Material)
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
.FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
|
||||||
(model.Id.HasValue && x.Id == model.Id))
|
(model.Id.HasValue && x.Id == model.Id)) && x.TeacherId == model.TeacherId)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user