Compare commits
12 Commits
e2c272c024
...
6abd26ea3c
Author | SHA1 | Date | |
---|---|---|---|
|
6abd26ea3c | ||
|
f29365f88c | ||
|
80257228e0 | ||
|
d36d38e353 | ||
|
4379b3a531 | ||
|
c863490d68 | ||
|
a15ead57dd | ||
|
59e6a1418f | ||
|
b4e77f7c87 | ||
|
e3ec7c8acd | ||
|
5264595708 | ||
|
dadcc5b61a |
@ -13,8 +13,6 @@ namespace UniversityDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new UniversityDatabase();
|
||||
return context.Statements
|
||||
.Include(x => x.StatementStudents)
|
||||
.ThenInclude(x => x.Student)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -22,8 +20,6 @@ namespace UniversityDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new UniversityDatabase();
|
||||
return context.Statements
|
||||
.Include(x => x.StatementStudents)
|
||||
.ThenInclude(x => x.Student)
|
||||
.Where(x => (
|
||||
(!model.Id.HasValue || x.Id == model.Id)
|
||||
)
|
||||
@ -39,8 +35,6 @@ namespace UniversityDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new UniversityDatabase();
|
||||
return context.Statements
|
||||
.Include(x => x.StatementStudents)
|
||||
.ThenInclude(x => x.Student)
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public StatementViewModel? Insert(StatementBindingModel model)
|
||||
|
@ -15,6 +15,8 @@ namespace UniversityDatabaseImplement.Implements
|
||||
return context.Students
|
||||
.Include(x => x.StudentExaminationResults)
|
||||
.ThenInclude(x => x.ExaminationResult)
|
||||
.Include(x => x.StatementStudents)
|
||||
.ThenInclude(x => x.Statement)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -24,6 +26,8 @@ namespace UniversityDatabaseImplement.Implements
|
||||
return context.Students
|
||||
.Include(x => x.StudentExaminationResults)
|
||||
.ThenInclude(x => x.ExaminationResult)
|
||||
.Include(x => x.StatementStudents)
|
||||
.ThenInclude(x => x.Statement)
|
||||
.Where(x => (
|
||||
(!model.Id.HasValue || x.Id == model.Id) &&
|
||||
(string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name))
|
||||
@ -42,6 +46,8 @@ namespace UniversityDatabaseImplement.Implements
|
||||
return context.Students
|
||||
.Include(x => x.StudentExaminationResults)
|
||||
.ThenInclude(x => x.ExaminationResult)
|
||||
.Include(x => x.StatementStudents)
|
||||
.ThenInclude(x => x.Statement)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name== model.Name) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
@ -17,20 +17,6 @@ namespace UniversityDatabaseImplement.Models
|
||||
public virtual List<StatementStudent> StatementStudents { get; set; } = new();
|
||||
[ForeignKey("StatementId")]
|
||||
public virtual List<ExaminationResult> ExaminationResults { get; set; } = new();
|
||||
private Dictionary<int, IStudentModel>? _students = null;
|
||||
public Dictionary<int, IStudentModel> Students
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_students == null)
|
||||
{
|
||||
_students = StatementStudents.ToDictionary(
|
||||
x => x.Student.Id, x => x.Student as IStudentModel);
|
||||
}
|
||||
|
||||
return _students;
|
||||
}
|
||||
}
|
||||
public static Statement Create(StatementBindingModel model)
|
||||
{
|
||||
return new Statement
|
||||
@ -54,7 +40,6 @@ namespace UniversityDatabaseImplement.Models
|
||||
Id = Id,
|
||||
Date = Date,
|
||||
HoursCount = HoursCount,
|
||||
Students = Students
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,22 @@ namespace UniversityDatabaseImplement.Models
|
||||
return _results;
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<int, IStatementModel>? _statements;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IStatementModel> Statements
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_statements == null)
|
||||
{
|
||||
_statements = StatementStudents.ToDictionary(
|
||||
x => x.Statement.Id, x => x.Statement as IStatementModel);
|
||||
}
|
||||
|
||||
return _statements;
|
||||
}
|
||||
}
|
||||
public static Student Create(StudentBindingModel model)
|
||||
{
|
||||
return new Student
|
||||
@ -54,7 +70,8 @@ namespace UniversityDatabaseImplement.Models
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
RecordCardNumber = RecordCardNumber,
|
||||
Results = Results
|
||||
Results = Results,
|
||||
Statements = Statements
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,102 +0,0 @@
|
||||
using UniversityContracts.BindingModels;
|
||||
using UniversityContracts.BuisnessLogicContracts;
|
||||
using UniversityContracts.SearchModels;
|
||||
using UniversityContracts.StoragesContracts;
|
||||
using UniversityContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace UniversityBuisnessLogic
|
||||
{
|
||||
public class ActivityLogic : IActivityLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IActivityStorage _activityStorage;
|
||||
|
||||
public ActivityLogic(ILogger<ActivityLogic> logger, IActivityStorage activityStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_activityStorage = activityStorage;
|
||||
}
|
||||
public bool Create(ActivityBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_activityStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ActivityBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_activityStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ActivityViewModel? ReadElement(ActivitySearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||
var element = _activityStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ActivityViewModel>? ReadList(ActivitySearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||
var list = model == null ? _activityStorage.GetFullList() : _activityStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(ActivityBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_activityStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ActivityBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Number <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Номер занятия должен быть больше 0", nameof(model.Number));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Activity. Number:{ComponentName}. Id: {Id}", model.Number, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
using UniversityContracts.BindingModels;
|
||||
using UniversityContracts.BuisnessLogicContracts;
|
||||
using UniversityContracts.SearchModels;
|
||||
using UniversityContracts.StoragesContracts;
|
||||
using UniversityContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace UniversityBuisnessLogic.BuisnessLogic
|
||||
{
|
||||
public class ReportLogic : IReportLogic
|
||||
{
|
||||
ILogger _logger;
|
||||
IDisciplineStorage _disciplineStorage;
|
||||
|
||||
public ReportLogic(ILogger<ReportLogic> logger, IDisciplineStorage disciplineStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_disciplineStorage = disciplineStorage;
|
||||
}
|
||||
|
||||
public List<ReportStudentDisciplineViewModel> GetStudentDiscipline(ReportBindingModel model)
|
||||
{
|
||||
if (model == null || model.Students == null) return new();
|
||||
|
||||
var disciplines = _disciplineStorage.GetFullList();
|
||||
List<ReportStudentDisciplineViewModel> result = new();
|
||||
|
||||
foreach(var student in model.Students)
|
||||
{
|
||||
var record = new ReportStudentDisciplineViewModel
|
||||
{
|
||||
StudentName = student.Name,
|
||||
};
|
||||
|
||||
foreach(var discipline in disciplines)
|
||||
{
|
||||
if(student.Statements.ContainsKey(discipline.Id))
|
||||
{
|
||||
record.Disciplines.Add(discipline.Name);
|
||||
}
|
||||
}
|
||||
|
||||
result.Add(record);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
using UniversityContracts.BindingModels;
|
||||
using UniversityContracts.BuisnessLogicContracts;
|
||||
using UniversityContracts.SearchModels;
|
||||
using UniversityContracts.StoragesContracts;
|
||||
using UniversityContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace UniversityBuisnessLogic
|
||||
{
|
||||
public class DisciplineLogic : IDisciplineLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IDisciplineStorage _disciplineStorage;
|
||||
|
||||
public DisciplineLogic(ILogger<DisciplineLogic> logger, IDisciplineStorage disciplineStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_disciplineStorage = disciplineStorage;
|
||||
}
|
||||
|
||||
public bool Create(DisciplineBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_disciplineStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(DisciplineBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_disciplineStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public DisciplineViewModel? ReadElement(DisciplineSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. DisciplineName:{Name}. Id:{Id}", model.Name, model.Id);
|
||||
var element = _disciplineStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<DisciplineViewModel>? ReadList(DisciplineSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. DisciplineName: {Name}. Id:{Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _disciplineStorage.GetFullList() : _disciplineStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(DisciplineBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_disciplineStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(DisciplineBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия дисциплины", nameof(model.Name));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Department))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия кафедры", nameof(model.Name));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Discipline. Name:{Name}. Department:{Department}. Id: {Id}", model.Name, model.Department, model.Id);
|
||||
|
||||
var element = _disciplineStorage.GetElement(new DisciplineSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Дисциплина с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
using UniversityContracts.BindingModels;
|
||||
using UniversityContracts.BuisnessLogicContracts;
|
||||
using UniversityContracts.SearchModels;
|
||||
using UniversityContracts.StoragesContracts;
|
||||
using UniversityContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace UniversityBuisnessLogic
|
||||
{
|
||||
public class ExaminationResultLogic : IExaminationResultLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IExaminationResultStorage _examinationResultStorage;
|
||||
|
||||
public ExaminationResultLogic(ILogger<ExaminationResultLogic> logger, IExaminationResultStorage examinationResultStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_examinationResultStorage = examinationResultStorage;
|
||||
}
|
||||
|
||||
public bool Create(ExaminationResultBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_examinationResultStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ExaminationResultBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_examinationResultStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ExaminationResultViewModel? ReadElement(ExaminationResultSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||
var element = _examinationResultStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ExaminationResultViewModel>? ReadList(ExaminationResultSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||
var list = model == null ? _examinationResultStorage.GetFullList() : _examinationResultStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(ExaminationResultBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_examinationResultStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ExaminationResultBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ExaminationForm))
|
||||
{
|
||||
throw new ArgumentNullException("Нет формы испытания", nameof(model.ExaminationForm));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ExaminationResult. ExaminationForm: {ExaminationForm}. Id: {Id}", model.ExaminationForm, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
using UniversityContracts.BindingModels;
|
||||
using UniversityContracts.BuisnessLogicContracts;
|
||||
using UniversityContracts.SearchModels;
|
||||
using UniversityContracts.StoragesContracts;
|
||||
using UniversityContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace UniversityBuisnessLogic
|
||||
{
|
||||
public class ReportTypeLogic : IReportTypeLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IReportTypeStorage _reportTypeStorage;
|
||||
|
||||
public ReportTypeLogic(ILogger<ReportTypeLogic> logger, IReportTypeStorage reportTypeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_reportTypeStorage = reportTypeStorage;
|
||||
}
|
||||
|
||||
public bool Create(ReportTypeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_reportTypeStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ReportTypeBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_reportTypeStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ReportTypeViewModel? ReadElement(ReportTypeSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ReportTypeName: {Name}. Id:{Id}", model.Name, model.Id);
|
||||
var element = _reportTypeStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ReportTypeViewModel>? ReadList(ReportTypeSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ReportTypeName: {Name}. Id:{Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _reportTypeStorage.GetFullList() : _reportTypeStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(ReportTypeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_reportTypeStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ReportTypeBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия типа отчета", nameof(model.Name));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReportType. ReportName:{Name}. Id: { Id}", model.Name, model.Id);
|
||||
var element = _reportTypeStorage.GetElement(new ReportTypeSearchModel
|
||||
{
|
||||
Name = model.Name,
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Тип отчета с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
using UniversityContracts.BindingModels;
|
||||
using UniversityContracts.BuisnessLogicContracts;
|
||||
using UniversityContracts.SearchModels;
|
||||
using UniversityContracts.StoragesContracts;
|
||||
using UniversityContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace UniversityBuisnessLogicf
|
||||
{
|
||||
public class StatementLogic : IStatementLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStatementStorage _statementStorage;
|
||||
|
||||
public StatementLogic(ILogger<StatementLogic> logger, IStatementStorage statementStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_statementStorage = statementStorage;
|
||||
}
|
||||
public bool Create(StatementBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_statementStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(StatementBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_statementStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public StatementViewModel? ReadElement(StatementSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||
var element = _statementStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
f
|
||||
public List<StatementViewModel>? ReadList(StatementSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||
var list = model == null ? _statementStorage.GetFullList() : _statementStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(StatementBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_statementStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(StatementBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.HoursCount <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество часов в ведомости должно быть больше 0", nameof(model.HoursCount));
|
||||
}
|
||||
_logger.LogInformation("Statement. HoursCount:{HoursCount}. Id: { Id}", model.HoursCount, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
using UniversityContracts.BindingModels;
|
||||
using UniversityContracts.BuisnessLogicContracts;
|
||||
using UniversityContracts.SearchModels;
|
||||
using UniversityContracts.StoragesContracts;
|
||||
using UniversityContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace UniversityBuisnessLogic
|
||||
{
|
||||
public class StudentLogic : IStudentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStudentStorage _studentStorage;
|
||||
|
||||
public StudentLogic(ILogger<StudentLogic> logger, IStudentStorage studentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_studentStorage = studentStorage;
|
||||
}
|
||||
public bool Create(StudentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_studentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert 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;
|
||||
}
|
||||
|
||||
public StudentViewModel? ReadElement(StudentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. StudentName: {Name}. Id:{Id}", model.Name, 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 List<StudentViewModel>? ReadList(StudentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. StudentName: {Name}. Id:{Id}", model?.Name, 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 bool Update(StudentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_studentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update 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.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет имени студента", nameof(model.Name));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Student. Name:{Name}. Id: { Id}", model.Name, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
using UniversityContracts.BindingModels;
|
||||
using UniversityContracts.BuisnessLogicContracts;
|
||||
using UniversityContracts.SearchModels;
|
||||
using UniversityContracts.StoragesContracts;
|
||||
using UniversityContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace UniversityBuisnessLogic
|
||||
{
|
||||
public class UserLogic : IUserLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUserStorage _userStorage;
|
||||
|
||||
public UserLogic(ILogger<UserLogic> logger, IUserStorage userStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_userStorage = userStorage;
|
||||
}
|
||||
|
||||
public bool Create(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_userStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_userStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public UserViewModel? ReadElement(UserSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||
var element = _userStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||
var list = model == null ? _userStorage.GetFullList() : _userStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_userStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(UserBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет имени пользователя", nameof(model.Name));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Surname))
|
||||
{
|
||||
throw new ArgumentNullException("Нет фамилии пользователя", nameof(model.Name));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина", nameof(model.Name));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет фамилии пароля", nameof(model.Name));
|
||||
}
|
||||
else if (model.Password.Length < 6)
|
||||
{
|
||||
throw new ArgumentNullException("В пароле должно быть не менее 6 символов", nameof(model.Name));
|
||||
}
|
||||
|
||||
_logger.LogInformation("User. Name:{Name}. Surname:{Surname}. Login: {Login} " +
|
||||
"Password: {Password}. Id: {Id}", model.Name, model.Surname, model.Login, model.Password, model.Id);
|
||||
|
||||
var element = _userStorage.GetElement(new UserSearchModel
|
||||
{
|
||||
Login = model.Login,
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Пользователь с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,5 +7,6 @@ namespace UniversityContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = String.Empty;
|
||||
public string Department { get; set; } = String.Empty;
|
||||
public int StatementId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
using UniversityContracts.ViewModels;
|
||||
|
||||
namespace UniversityContracts.BindingModels
|
||||
{
|
||||
public class ReportBindingModel
|
||||
{
|
||||
public string? FileName { get; set; } = string.Empty;
|
||||
public DateTime? From { get; set; }
|
||||
public DateTime? To { get; set; }
|
||||
public List<StudentViewModel> Students { get; set; } = new();
|
||||
}
|
||||
}
|
@ -7,6 +7,5 @@ namespace UniversityContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public DateTime Date { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
public int HoursCount { get; set; }
|
||||
public Dictionary<int, IStudentModel> Students { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ namespace UniversityContracts.BindingModels
|
||||
public string Name { get; set; } = String.Empty;
|
||||
public string RecordCardNumber { get; set; } = String.Empty;
|
||||
public Dictionary<int, IExaminationResultModel> Results { get; set; } = new();
|
||||
public Dictionary<int, IStatementModel> Statements { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
using UniversityContracts.BindingModels;
|
||||
using UniversityContracts.ViewModels;
|
||||
|
||||
namespace UniversityContracts.BuisnessLogicContracts
|
||||
{
|
||||
public interface IReportLogic
|
||||
{
|
||||
List<ReportStudentDisciplineViewModel> GetStudentDiscipline(ReportBindingModel model);
|
||||
}
|
||||
}
|
@ -7,5 +7,6 @@ namespace UniversityContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = String.Empty;
|
||||
public string Department { get; set; } = String.Empty;
|
||||
public int StatementId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
namespace UniversityContracts.ViewModels
|
||||
{
|
||||
public class ReportStudentDisciplineViewModel
|
||||
{
|
||||
public string StudentName { get; set; } = string.Empty;
|
||||
public List<string> Disciplines { get; set; } = new();
|
||||
}
|
||||
}
|
@ -7,6 +7,5 @@ namespace UniversityContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
public DateTime Date { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
public int HoursCount { get; set; }
|
||||
public Dictionary<int, IStudentModel> Students { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ namespace UniversityContracts.ViewModels
|
||||
public string Name { get; set; } = String.Empty;
|
||||
public string RecordCardNumber { get; set; } = String.Empty;
|
||||
public Dictionary<int, IExaminationResultModel> Results { get; set; } = new();
|
||||
public Dictionary<int, IStatementModel> Statements { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -4,5 +4,6 @@
|
||||
{
|
||||
String Name { get; }
|
||||
String Department { get; }
|
||||
int StatementId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,5 @@
|
||||
{
|
||||
DateTime Date { get; }
|
||||
int HoursCount { get; }
|
||||
Dictionary<int, IStudentModel> Students { get; }
|
||||
}
|
||||
}
|
||||
|
@ -5,5 +5,6 @@
|
||||
String Name { get; }
|
||||
String RecordCardNumber { get; }
|
||||
Dictionary<int, IExaminationResultModel> Results { get; }
|
||||
Dictionary<int, IStatementModel> Statements { get; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user