Compare commits
20 Commits
Refactorin
...
Controller
| Author | SHA1 | Date | |
|---|---|---|---|
| ba9543df1b | |||
| e9090577d6 | |||
| 15074cc3d2 | |||
| f6c9cf3044 | |||
| 59749a4a67 | |||
| 6f32e2c251 | |||
| e8f925972c | |||
| a9790a9d88 | |||
| 7e108ee216 | |||
| a20bfbb3e2 | |||
| 60029d7e1b | |||
| da84992d30 | |||
| 2f4efc2dba | |||
| 430319f50f | |||
| 39af7fd785 | |||
| 0dc5b4880a | |||
| ba16aa6f10 | |||
| e5b9d581ca | |||
| 19c217dd68 | |||
| 845f96acb4 |
@@ -1,31 +1,36 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using UniversityAllExpelled_Models.BusinessLogicContracts;
|
using UniversityAllExpelled_Models.BusinessLogicContracts;
|
||||||
using UniversityAllExpelled_Models.DataModels;
|
using UniversityAllExpelled_Models.DataModels;
|
||||||
using UniversityAllExpelled_Models.Extensions;
|
using UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
using UniversityAllExpelled_Models.Exceptions;
|
using UniversityAllExpelled_Models.Exceptions;
|
||||||
|
using UniversityAllExpelled_Models.Extensions;
|
||||||
using UniversityAllExpelled_Models.StorageContracts;
|
using UniversityAllExpelled_Models.StorageContracts;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace UniversityAllExpelled_BusinessLogic.Implementations;
|
namespace UniversityAllExpelled_BusinessLogic.Implementations;
|
||||||
|
|
||||||
internal class EducationBusinessLogicContract(IEducationStorageContract educationStorageContract, ILogger<EducationBusinessLogicContract> logger)
|
internal class EducationBusinessLogicContract(
|
||||||
|
IEducationStorageContract educationStorageContract,
|
||||||
|
IEducationLessonsStorageContract educationLessonsStorageContract,
|
||||||
|
ILessonStorageContract lessonStorageContract,
|
||||||
|
ILogger<EducationBusinessLogicContract> logger)
|
||||||
: IEducationBusinessLogicContract
|
: IEducationBusinessLogicContract
|
||||||
{
|
{
|
||||||
private readonly IEducationStorageContract _educationStorageContract = educationStorageContract;
|
private readonly IEducationStorageContract _educationStorageContract = educationStorageContract;
|
||||||
|
private readonly IEducationLessonsStorageContract _educationLessonsStorageContract = educationLessonsStorageContract;
|
||||||
|
private readonly ILessonStorageContract _lessonStorageContract = lessonStorageContract;
|
||||||
private readonly ILogger _logger = logger;
|
private readonly ILogger _logger = logger;
|
||||||
|
|
||||||
public List<EducationDataModel> GetAllEducations()
|
public List<EducationDataModel> GetAllEducations()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllEducations");
|
_logger.LogInformation("GetAllEducations");
|
||||||
return _educationStorageContract.GetList() ?? throw new NullListException();
|
return _educationStorageContract.GetList() ?? throw new NullListException("GetAllEducations");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationDataModel> GetAllEducationsByActive(bool isActive)
|
public List<EducationDataModel> GetAllEducationsByActive(bool isActive)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllEducationsByActive with isActive = {isActive}", isActive);
|
_logger.LogInformation("GetAllEducationsByActive with isActive = {isActive}", isActive);
|
||||||
return _educationStorageContract.GetListByActive(isActive) ?? throw new NullListException();
|
return _educationStorageContract.GetListByActive(isActive) ?? throw new NullListException("GetAllEducationsByActive");
|
||||||
}
|
}
|
||||||
|
|
||||||
public EducationDataModel? GetEducationById(string educationId)
|
public EducationDataModel? GetEducationById(string educationId)
|
||||||
@@ -33,14 +38,10 @@ internal class EducationBusinessLogicContract(IEducationStorageContract educatio
|
|||||||
_logger.LogInformation("GetEducationById: {educationId}", educationId);
|
_logger.LogInformation("GetEducationById: {educationId}", educationId);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(educationId))
|
if (string.IsNullOrEmpty(educationId))
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(educationId));
|
throw new ArgumentNullException(nameof(educationId));
|
||||||
}
|
|
||||||
|
|
||||||
if (!Guid.TryParse(educationId, out _))
|
if (!Guid.TryParse(educationId, out _))
|
||||||
{
|
|
||||||
throw new ValidationException("Education ID must be in valid GUID format");
|
throw new ValidationException("Education ID must be in valid GUID format");
|
||||||
}
|
|
||||||
|
|
||||||
return _educationStorageContract.GetElementById(educationId);
|
return _educationStorageContract.GetElementById(educationId);
|
||||||
}
|
}
|
||||||
@@ -58,11 +59,9 @@ internal class EducationBusinessLogicContract(IEducationStorageContract educatio
|
|||||||
_logger.LogInformation("GetAllEducationsByPeriod from {startDate} to {endDate}", startDate, endDate);
|
_logger.LogInformation("GetAllEducationsByPeriod from {startDate} to {endDate}", startDate, endDate);
|
||||||
|
|
||||||
if (startDate > endDate)
|
if (startDate > endDate)
|
||||||
{
|
|
||||||
throw new IncorrectDatesException(startDate, endDate);
|
throw new IncorrectDatesException(startDate, endDate);
|
||||||
}
|
|
||||||
|
|
||||||
return _educationStorageContract.GetListByDateRange(startDate, endDate) ?? throw new NullListException();
|
return _educationStorageContract.GetListByDateRange(startDate, endDate) ?? throw new NullListException("GetAllEducationsByPeriod");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationDataModel> GetAllEducationsByTeacher(string teacherId)
|
public List<EducationDataModel> GetAllEducationsByTeacher(string teacherId)
|
||||||
@@ -70,16 +69,12 @@ internal class EducationBusinessLogicContract(IEducationStorageContract educatio
|
|||||||
_logger.LogInformation("GetAllEducationsByTeacher: {teacherId}", teacherId);
|
_logger.LogInformation("GetAllEducationsByTeacher: {teacherId}", teacherId);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(teacherId))
|
if (string.IsNullOrEmpty(teacherId))
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(teacherId));
|
throw new ArgumentNullException(nameof(teacherId));
|
||||||
}
|
|
||||||
|
|
||||||
if (!Guid.TryParse(teacherId, out _))
|
if (!Guid.TryParse(teacherId, out _))
|
||||||
{
|
|
||||||
throw new ValidationException("Teacher ID must be in valid GUID format");
|
throw new ValidationException("Teacher ID must be in valid GUID format");
|
||||||
}
|
|
||||||
|
|
||||||
return _educationStorageContract.GetListByTeacherId(teacherId) ?? throw new NullListException();
|
return _educationStorageContract.GetListByTeacherId(teacherId) ?? throw new NullListException("GetAllEducationsByTeacher");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationDataModel> GetAllEducationsByTeacherByActive(string teacherId, bool isActive)
|
public List<EducationDataModel> GetAllEducationsByTeacherByActive(string teacherId, bool isActive)
|
||||||
@@ -121,9 +116,7 @@ internal class EducationBusinessLogicContract(IEducationStorageContract educatio
|
|||||||
|
|
||||||
var existingEducation = _educationStorageContract.GetElementById(educationDataModel.Id);
|
var existingEducation = _educationStorageContract.GetElementById(educationDataModel.Id);
|
||||||
if (existingEducation != null)
|
if (existingEducation != null)
|
||||||
{
|
|
||||||
throw new ElementExistsException("Id", educationDataModel.Id);
|
throw new ElementExistsException("Id", educationDataModel.Id);
|
||||||
}
|
|
||||||
|
|
||||||
_educationStorageContract.AddElement(educationDataModel);
|
_educationStorageContract.AddElement(educationDataModel);
|
||||||
}
|
}
|
||||||
@@ -136,9 +129,7 @@ internal class EducationBusinessLogicContract(IEducationStorageContract educatio
|
|||||||
|
|
||||||
var existingEducation = _educationStorageContract.GetElementById(educationDataModel.Id);
|
var existingEducation = _educationStorageContract.GetElementById(educationDataModel.Id);
|
||||||
if (existingEducation == null)
|
if (existingEducation == null)
|
||||||
{
|
|
||||||
throw new ElementNotFoundException(educationDataModel.Id);
|
throw new ElementNotFoundException(educationDataModel.Id);
|
||||||
}
|
|
||||||
|
|
||||||
_educationStorageContract.UpdElement(educationDataModel);
|
_educationStorageContract.UpdElement(educationDataModel);
|
||||||
}
|
}
|
||||||
@@ -160,4 +151,26 @@ internal class EducationBusinessLogicContract(IEducationStorageContract educatio
|
|||||||
education.Active = false;
|
education.Active = false;
|
||||||
_educationStorageContract.UpdElement(education);
|
_educationStorageContract.UpdElement(education);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double CalculateTotalPriceByEducation(string educationId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Calculating total lesson price for education: {educationId}", educationId);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(educationId))
|
||||||
|
throw new ArgumentNullException(nameof(educationId));
|
||||||
|
|
||||||
|
if (!Guid.TryParse(educationId, out _))
|
||||||
|
throw new ValidationException("Education ID must be in valid GUID format");
|
||||||
|
|
||||||
|
var lessonIds = _educationLessonsStorageContract
|
||||||
|
.GetListByEducationId(educationId)
|
||||||
|
.Select(el => el.LessonId)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var lessons = _lessonStorageContract
|
||||||
|
.GetList()
|
||||||
|
.Where(l => lessonIds.Contains(l.Id));
|
||||||
|
|
||||||
|
return lessons.Sum(l => l.Price);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ internal class EducationLessonsBusinessLogicContract(
|
|||||||
public List<EducationLessonsDataModel> GetAllEducationLessons()
|
public List<EducationLessonsDataModel> GetAllEducationLessons()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting all education-lessons connections");
|
_logger.LogInformation("Getting all education-lessons connections");
|
||||||
return _storage.GetList() ?? throw new NullListException();
|
return _storage.GetList() ?? throw new NullListException("GetAllEducationLessons");
|
||||||
}
|
}
|
||||||
|
|
||||||
public EducationLessonsDataModel? GetEducationLesson(string educationId, string lessonId)
|
public EducationLessonsDataModel? GetEducationLesson(string educationId, string lessonId)
|
||||||
@@ -34,20 +34,20 @@ internal class EducationLessonsBusinessLogicContract(
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Getting all lessons for education: {educationId}", educationId);
|
_logger.LogInformation("Getting all lessons for education: {educationId}", educationId);
|
||||||
ValidateId(educationId, "Education ID");
|
ValidateId(educationId, "Education ID");
|
||||||
return _storage.GetListByEducationId(educationId) ?? throw new NullListException();
|
return _storage.GetListByEducationId(educationId) ?? throw new NullListException("GetLessonsByEducation");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> GetLessonIdsByEducation(string educationId)
|
public List<string> GetLessonIdsByEducation(string educationId)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting lesson IDs for education: {educationId}", educationId);
|
_logger.LogInformation("Getting lesson IDs for education: {educationId}", educationId);
|
||||||
return GetLessonsByEducation(educationId).Select(x => x.LessonsId).ToList();
|
return GetLessonsByEducation(educationId).Select(x => x.LessonId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationLessonsDataModel> GetEducationsByLesson(string lessonId)
|
public List<EducationLessonsDataModel> GetEducationsByLesson(string lessonId)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting all educations for lesson: {lessonId}", lessonId);
|
_logger.LogInformation("Getting all educations for lesson: {lessonId}", lessonId);
|
||||||
ValidateId(lessonId, "Lesson ID");
|
ValidateId(lessonId, "Lesson ID");
|
||||||
return _storage.GetListByLessonId(lessonId) ?? throw new NullListException();
|
return _storage.GetListByLessonId(lessonId) ?? throw new NullListException("GetEducationsByLesson");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> GetEducationIdsByLesson(string lessonId)
|
public List<string> GetEducationIdsByLesson(string lessonId)
|
||||||
@@ -64,10 +64,10 @@ internal class EducationLessonsBusinessLogicContract(
|
|||||||
ArgumentNullException.ThrowIfNull(educationLesson);
|
ArgumentNullException.ThrowIfNull(educationLesson);
|
||||||
educationLesson.Validate();
|
educationLesson.Validate();
|
||||||
|
|
||||||
if (_storage.GetElementByIds(educationLesson.EducationId, educationLesson.LessonsId) != null)
|
if (_storage.GetElementByIds(educationLesson.EducationId, educationLesson.LessonId) != null)
|
||||||
{
|
{
|
||||||
throw new ElementExistsException("Education-Lesson connection",
|
throw new ElementExistsException("Education-Lesson connection",
|
||||||
$"{educationLesson.EducationId}-{educationLesson.LessonsId}");
|
$"{educationLesson.EducationId}-{educationLesson.LessonId}");
|
||||||
}
|
}
|
||||||
|
|
||||||
_storage.AddElement(educationLesson);
|
_storage.AddElement(educationLesson);
|
||||||
|
|||||||
@@ -1,166 +1,173 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using UniversityAllExpelled_Models.BusinessLogicContracts;
|
using UniversityAllExpelled_Models.BusinessLogicContracts;
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels;
|
||||||
using UniversityAllExpelled_Models.Exceptions;
|
using UniversityAllExpelled_Models.Exceptions;
|
||||||
using UniversityAllExpelled_Models.Extensions;
|
|
||||||
using UniversityAllExpelled_Models.StorageContracts;
|
using UniversityAllExpelled_Models.StorageContracts;
|
||||||
using System.Data;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace UniversityAllExpelled_BusinessLogic.Implementations;
|
namespace UniversityAllExpelled_BusinessLogic.Implementations;
|
||||||
|
|
||||||
internal class LessonBusinessLogicContract(ILessonStorageContract lessonStorageContract, ILogger<LessonBusinessLogicContract> logger) : ILessonBusinessLogicContract
|
public class LessonBusinessLogicContract(ILessonStorageContract lessonStorage, ILogger<LessonBusinessLogicContract> logger) : ILessonBusinessLogicContract
|
||||||
{
|
{
|
||||||
private readonly ILessonStorageContract _lessonStorageContract = lessonStorageContract;
|
private readonly ILessonStorageContract _lessonStorage = lessonStorage;
|
||||||
private readonly ILogger<LessonBusinessLogicContract> _logger;
|
private readonly ILogger<LessonBusinessLogicContract> _logger = logger;
|
||||||
|
|
||||||
public List<LessonDataModel> GetAllLesson()
|
public List<LessonDataModel> GetAllLessons()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllLesson");
|
return _lessonStorage.GetList();
|
||||||
var lessons = _lessonStorageContract.GetList();
|
|
||||||
return lessons ?? throw new DataException("Failed to retrieve lessons list");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LessonDataModel> GetAllLessonByActive(bool isActive)
|
public List<LessonDataModel> GetLessonsByStatus(bool isActive)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllLessonByActive with isActive = {isActive}", isActive);
|
return _lessonStorage.GetListByIsActive(isActive);
|
||||||
var lessons = _lessonStorageContract.GetListByActive(isActive);
|
}
|
||||||
return lessons ?? throw new DataException($"Failed to retrieve {(isActive ? "active" : "inactive")} lessons list");
|
|
||||||
|
public List<LessonDataModel> GetLessonsByPeriod(DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
if (startDate > endDate)
|
||||||
|
throw new IncorrectDatesException(startDate, endDate);
|
||||||
|
|
||||||
|
return [.. _lessonStorage.GetList().Where(l => l.StartDate >= startDate && l.EndDate <= endDate)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public LessonDataModel? GetLessonByName(string lessonName)
|
public LessonDataModel? GetLessonByName(string lessonName)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetLessonByName: {lessonName}", lessonName);
|
return _lessonStorage.GetListByLessonName(lessonName).FirstOrDefault();
|
||||||
|
|
||||||
if (lessonName.IsEmpty())
|
|
||||||
throw new ArgumentNullException(nameof(lessonName));
|
|
||||||
|
|
||||||
var lessons = _lessonStorageContract.GetListByNameLesson(lessonName);
|
|
||||||
return lessons?.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LessonDataModel? GetLessonByNameByActive(string lessonName, bool isActive)
|
public LessonDataModel? GetLessonByNameAndStatus(string lessonName, bool isActive)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetLessonByNameByActive: {lessonName} with isActive = {isActive}", lessonName, isActive);
|
return _lessonStorage.GetListByLessonName(lessonName)
|
||||||
|
.FirstOrDefault(l => l.IsActive == isActive);
|
||||||
if (lessonName.IsEmpty())
|
|
||||||
throw new ArgumentNullException(nameof(lessonName));
|
|
||||||
|
|
||||||
var lessons = _lessonStorageContract.GetListByNameLesson(lessonName);
|
|
||||||
return lessons?.FirstOrDefault(l => l.IsActive == isActive);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LessonDataModel> GetAllLessonByPeriod(DateTime startDate, DateTime endDate)
|
public List<LessonDataModel> GetLessonsByStudentAndPeriod(string studentId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllLessonByPeriod from {startDate} to {endDate}", startDate, endDate);
|
|
||||||
|
|
||||||
if (startDate > endDate)
|
if (startDate > endDate)
|
||||||
throw new ValidationException("Start date cannot be later than end date");
|
throw new IncorrectDatesException(startDate, endDate);
|
||||||
|
|
||||||
var lessons = _lessonStorageContract.GetList();
|
return [.. _lessonStorage.GetListByStudentId(studentId).Where(l => l.StartDate >= startDate && l.EndDate <= endDate)];
|
||||||
return lessons?
|
|
||||||
.Where(l => l.StartDate.Date >= startDate.Date && l.EndDate.Date <= endDate.Date)
|
|
||||||
.ToList() ?? throw new DataException("Failed to retrieve lessons list");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LessonDataModel> GetAllLessonByPeriodByStudent(string studentId, DateTime startDate, DateTime endDate)
|
public List<LessonDataModel> GetLessonsByStudentAndPeriodAndStatus(string studentId, DateTime startDate, DateTime endDate, bool isActive)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllLessonByPeriodByStudent: {studentId} from {startDate} to {endDate}", studentId, startDate, endDate);
|
return [.. GetLessonsByStudentAndPeriod(studentId, startDate, endDate).Where(l => l.IsActive == isActive)];
|
||||||
|
|
||||||
if (studentId.IsEmpty())
|
|
||||||
throw new ArgumentNullException(nameof(studentId));
|
|
||||||
|
|
||||||
if (startDate > endDate)
|
|
||||||
throw new ValidationException("Start date cannot be later than end date");
|
|
||||||
|
|
||||||
var lessons = _lessonStorageContract.GetListByStudentId(studentId);
|
|
||||||
return lessons?
|
|
||||||
.Where(l => l.StartDate.Date >= startDate.Date && l.EndDate.Date <= endDate.Date)
|
|
||||||
.ToList() ?? throw new DataException("Failed to retrieve lessons list for the student");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LessonDataModel> GetAllLessonByPeriodByStudentByActive(string studentId, DateTime startDate, DateTime endDate, bool isActive)
|
public LessonDataModel? GetLessonByNameAndStudentAndStatus(string lessonName, string studentId, bool isActive)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllLessonByPeriodByStudentByActive: {studentId} from {startDate} to {endDate} with isActive = {isActive}", studentId, startDate, endDate, isActive);
|
return _lessonStorage.GetListByStudentId(studentId)
|
||||||
|
.FirstOrDefault(l => l.Name == lessonName && l.IsActive == isActive);
|
||||||
if (studentId.IsEmpty())
|
|
||||||
throw new ArgumentNullException(nameof(studentId));
|
|
||||||
|
|
||||||
if (startDate > endDate)
|
|
||||||
throw new ValidationException("Start date cannot be later than end date");
|
|
||||||
|
|
||||||
var lessons = _lessonStorageContract.GetListByStudentId(studentId);
|
|
||||||
return lessons?
|
|
||||||
.Where(l => l.StartDate.Date >= startDate.Date && l.EndDate.Date <= endDate.Date && l.IsActive == isActive)
|
|
||||||
.ToList() ?? throw new DataException("Failed to retrieve lessons list for the student");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LessonDataModel? GetLessonByNameByStudentByActive(string lessonName, string studentId, bool isActive)
|
public void AddLesson(LessonDataModel model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetLessonByNameByStudentByActive: {lessonName}, {studentId} with isActive = {isActive}", lessonName, studentId, isActive);
|
try
|
||||||
|
{
|
||||||
if (lessonName.IsEmpty())
|
model.Validate();
|
||||||
throw new ArgumentNullException(nameof(lessonName));
|
_lessonStorage.AddElement(model);
|
||||||
|
_logger.LogInformation("Added lesson: {Name}", model.Name);
|
||||||
if (studentId.IsEmpty())
|
}
|
||||||
throw new ArgumentNullException(nameof(studentId));
|
catch (ValidationException ve)
|
||||||
|
{
|
||||||
var lessons = _lessonStorageContract.GetListByStudentId(studentId);
|
_logger.LogWarning("Validation failed in AddLesson: {Message}", ve.Message);
|
||||||
return lessons?
|
throw;
|
||||||
.FirstOrDefault(l => l.Name.Contains(lessonName) && l.IsActive == isActive);
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Unexpected error in AddLesson");
|
||||||
|
throw new StorageException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateLesson(LessonDataModel lessonDataModel)
|
public void UpdateLesson(LessonDataModel model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("CreateLesson: {json}", JsonSerializer.Serialize(lessonDataModel));
|
try
|
||||||
ArgumentNullException.ThrowIfNull(lessonDataModel);
|
{
|
||||||
lessonDataModel.Validate();
|
model.Validate();
|
||||||
|
|
||||||
_lessonStorageContract.AddElement(lessonDataModel);
|
var existing = _lessonStorage.GetElementById(model.Id) ?? throw new ElementNotFoundException(model.Id);
|
||||||
|
_lessonStorage.UpdElement(model);
|
||||||
|
_logger.LogInformation("Updated lesson: {Id}", model.Id);
|
||||||
}
|
}
|
||||||
|
catch (ValidationException ve)
|
||||||
public void UpdateLesson(LessonDataModel lessonDataModel)
|
|
||||||
{
|
{
|
||||||
_logger.LogInformation("UpdateLesson: {json}", JsonSerializer.Serialize(lessonDataModel));
|
_logger.LogWarning("Validation failed in UpdateLesson: {Message}", ve.Message);
|
||||||
ArgumentNullException.ThrowIfNull(lessonDataModel);
|
throw;
|
||||||
lessonDataModel.Validate();
|
}
|
||||||
|
catch (ElementNotFoundException enf)
|
||||||
var existingLesson = _lessonStorageContract.GetElementById(lessonDataModel.Id);
|
{
|
||||||
if (existingLesson == null)
|
_logger.LogWarning("Lesson not found: {Id}", model.Id);
|
||||||
throw new ElementNotFoundException($"Lesson with ID '{lessonDataModel.Id}' not found");
|
throw;
|
||||||
|
}
|
||||||
_lessonStorageContract.UpdElement(lessonDataModel);
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Unexpected error in UpdateLesson");
|
||||||
|
throw new StorageException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RestoreLesson(string id)
|
public void RestoreLesson(string id)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("RestoreLesson with Id: {id}", id);
|
try
|
||||||
|
{
|
||||||
|
var lesson = _lessonStorage.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
||||||
|
if (lesson.IsActive)
|
||||||
|
return;
|
||||||
|
|
||||||
if (id.IsEmpty())
|
lesson.IsActive = true;
|
||||||
throw new ArgumentNullException(nameof(id));
|
_lessonStorage.UpdElement(lesson);
|
||||||
|
_logger.LogInformation("Restored lesson: {Id}", id);
|
||||||
if (!id.IsGuid())
|
}
|
||||||
throw new ValidationException("Id is not a valid GUID");
|
catch (ElementNotFoundException enf)
|
||||||
|
{
|
||||||
var lesson = _lessonStorageContract.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
_logger.LogWarning("Lesson not found during restore: {Id}", id);
|
||||||
var updatedLesson = new LessonDataModel(
|
throw;
|
||||||
lesson.Id, lesson.Name, lesson.Price, lesson.StartDate, lesson.EndDate,
|
}
|
||||||
lesson.StudentId, lesson.SalaryId, true);
|
catch (Exception ex)
|
||||||
|
{
|
||||||
_lessonStorageContract.UpdElement(updatedLesson);
|
_logger.LogError(ex, "Unexpected error in RestoreLesson");
|
||||||
|
throw new StorageException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteLesson(string id)
|
public void DeleteLesson(string id)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("DeleteLesson with Id: {id}", id);
|
try
|
||||||
|
{
|
||||||
|
var lesson = _lessonStorage.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
||||||
|
lesson.IsActive = false;
|
||||||
|
_lessonStorage.UpdElement(lesson);
|
||||||
|
_logger.LogWarning("Marked lesson as inactive: {Id}", id);
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException enf)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Lesson not found for deletion: {Id}", id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Unexpected error in DeleteLesson");
|
||||||
|
throw new StorageException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (id.IsEmpty())
|
public List<LessonDataModel> GetLessonsByEducationId(string educationId)
|
||||||
throw new ArgumentNullException(nameof(id));
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
if (!id.IsGuid())
|
public List<LessonDataModel> GetLessonsByEducationAndPeriod(string educationId, DateTime startDate, DateTime endDate)
|
||||||
throw new ValidationException("Id is not a valid GUID");
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
var lesson = _lessonStorageContract.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
public List<LessonDataModel> GetLessonsByEducationAndDate(string educationId, DateTime date)
|
||||||
_lessonStorageContract.DelElement(lesson);
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<LessonDataModel> GetLessonsByEducationAndTeacher(string educationId, string teacherId)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,261 +2,187 @@
|
|||||||
using UniversityAllExpelled_Models.BusinessLogicContracts;
|
using UniversityAllExpelled_Models.BusinessLogicContracts;
|
||||||
using UniversityAllExpelled_Models.DataModels.Client;
|
using UniversityAllExpelled_Models.DataModels.Client;
|
||||||
using UniversityAllExpelled_Models.Exceptions;
|
using UniversityAllExpelled_Models.Exceptions;
|
||||||
using UniversityAllExpelled_Models.Extensions;
|
|
||||||
using UniversityAllExpelled_Models.StorageContracts;
|
using UniversityAllExpelled_Models.StorageContracts;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace UniversityAllExpelled_BusinessLogic.Implementations;
|
namespace UniversityAllExpelled_BusinessLogic.Implementations;
|
||||||
|
|
||||||
internal class PaymentBusinessLogicContract : IPaymentBusinessLogicContract
|
public class PaymentBusinessLogicContract(IPaymentStorageContract paymentStorage, ILogger<PaymentBusinessLogicContract> logger, IEducationStorageContract educationStorage, ILessonStorageContract lessonStorage) : IPaymentBusinessLogicContract
|
||||||
{
|
{
|
||||||
private readonly IPaymentStorageContract _paymentStorage;
|
private readonly IPaymentStorageContract _paymentStorage = paymentStorage;
|
||||||
private readonly ILogger<PaymentBusinessLogicContract> _logger;
|
private readonly ILogger<PaymentBusinessLogicContract> _logger = logger;
|
||||||
|
private readonly IEducationStorageContract _educationStorage = educationStorage;
|
||||||
|
private readonly ILessonStorageContract _lessonStorage = lessonStorage;
|
||||||
|
|
||||||
public PaymentBusinessLogicContract(
|
public List<PaymentDataModel> GetAllPayments()
|
||||||
IPaymentStorageContract paymentStorage,
|
|
||||||
ILogger<PaymentBusinessLogicContract> logger)
|
|
||||||
{
|
{
|
||||||
_paymentStorage = paymentStorage ?? throw new ArgumentNullException(nameof(paymentStorage));
|
return _paymentStorage.GetList();
|
||||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaymentDataModel> GetAllPayment()
|
public PaymentDataModel? GetPaymentById(string id)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting all payments");
|
return _paymentStorage.GetElementById(id);
|
||||||
try
|
|
||||||
{
|
|
||||||
return _paymentStorage.GetList() ?? throw new DataException("Failed to retrieve payments list");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while getting all payments");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaymentDataModel> GetAllPaymentByPaidOfState(bool paidOf)
|
public List<PaymentDataModel> GetPaymentsByStatus(bool isPaid)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting payments by paid state: {PaidOf}", paidOf);
|
return _paymentStorage.GetListByIsPaid(isPaid);
|
||||||
try
|
|
||||||
{
|
|
||||||
return _paymentStorage.GetListByPaidOf(paidOf)
|
|
||||||
?? throw new DataException($"Failed to retrieve payments with PaidOf={paidOf}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while getting payments by paid state");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaymentDataModel> GetAllPaymentByPeriod(DateTime startDate, DateTime endDate)
|
public List<PaymentDataModel> GetPaymentsByPeriod(DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting payments by period from {StartDate} to {EndDate}", startDate, endDate);
|
|
||||||
|
|
||||||
if (startDate > endDate)
|
if (startDate > endDate)
|
||||||
throw new ValidationException("Start date cannot be greater than end date");
|
throw new IncorrectDatesException(startDate, endDate);
|
||||||
|
|
||||||
try
|
return [.. (IEnumerable<PaymentDataModel>)_paymentStorage.GetList()
|
||||||
{
|
.Where(p => p.DateOfPayment >= startDate && p.DateOfPayment <= endDate)];
|
||||||
var allPayments = _paymentStorage.GetList()
|
|
||||||
?? throw new DataException("Failed to retrieve payments list");
|
|
||||||
|
|
||||||
// Фильтрация по дате создания (если в модели нет даты, можно добавить поле CreatedDate)
|
|
||||||
return allPayments.Where(p => p.DateOfpayment >= startDate && p.DateOfpayment <= endDate)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while getting payments by period");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaymentDataModel> GetAllPaymentByPeriodByPaidOfState(DateTime startDate, DateTime endDate, bool paidOf)
|
|
||||||
{
|
|
||||||
_logger.LogInformation(
|
|
||||||
"Getting payments by period from {StartDate} to {EndDate} with PaidOf={PaidOf}",
|
|
||||||
startDate, endDate, paidOf);
|
|
||||||
|
|
||||||
|
|
||||||
|
public List<PaymentDataModel> GetPaymentsByPeriodAndStatus(DateTime startDate, DateTime endDate, bool isPaid)
|
||||||
|
{
|
||||||
|
return [.. (IEnumerable<PaymentDataModel>)GetPaymentsByPeriod(startDate, endDate)
|
||||||
|
.Where(p => p.IsPaid == isPaid)];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<PaymentDataModel> GetPaymentsByStudentId(string studentId)
|
||||||
|
{
|
||||||
|
return _paymentStorage.GetListByStudentId(studentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PaymentDataModel> GetPaymentsByStudentAndPeriod(string studentId, DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
if (startDate > endDate)
|
if (startDate > endDate)
|
||||||
throw new ValidationException("Start date cannot be greater than end date");
|
throw new IncorrectDatesException(startDate, endDate);
|
||||||
|
|
||||||
|
return [.. (IEnumerable<PaymentDataModel>)_paymentStorage.GetListByStudentId(studentId)
|
||||||
|
.Where(p => p.DateOfPayment >= startDate && p.DateOfPayment <= endDate)];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<PaymentDataModel> GetPaymentsByStudentAndStatus(string studentId, bool isPaid)
|
||||||
|
{
|
||||||
|
return [.. _paymentStorage.GetListByStudentId(studentId).Where(p => p.IsPaid == isPaid)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PaymentDataModel> GetPaymentsByStudentAndPeriodAndStatus(string studentId, DateTime startDate, DateTime endDate, bool isPaid)
|
||||||
|
{
|
||||||
|
return [.. GetPaymentsByStudentAndPeriod(studentId, startDate, endDate).Where(p => p.IsPaid == isPaid)];
|
||||||
|
}
|
||||||
|
public double CalculatePaidAmountByEducation(string educationId)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var payments = _paymentStorage.GetListByPaidOf(paidOf)
|
return _paymentStorage.GetList()
|
||||||
?? throw new DataException($"Failed to retrieve payments with PaidOf={paidOf}");
|
.Where(p => p.EducationId == educationId && p.IsPaid)
|
||||||
|
.Sum(p => p.PaidAmount);
|
||||||
// Фильтрация по дате создания
|
|
||||||
return payments.Where(p => p.DateOfpayment >= startDate && p.DateOfpayment <= endDate)
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error while getting payments by period and paid state");
|
_logger.LogError(ex, "Failed to calculate paid amount for EducationId = {Id}", educationId);
|
||||||
throw;
|
throw new StorageException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaymentDataModel> GetAllPaymentByStudetnByPeriod(string studentId, DateTime startDate, DateTime endDate)
|
|
||||||
|
public double CalculateDebtByEducation(string educationId)
|
||||||
{
|
{
|
||||||
_logger.LogInformation(
|
|
||||||
"Getting payments for student {StudentId} by period from {StartDate} to {EndDate}",
|
|
||||||
studentId, startDate, endDate);
|
|
||||||
|
|
||||||
ValidateStudentId(studentId);
|
|
||||||
if (startDate > endDate)
|
|
||||||
throw new ValidationException("Start date cannot be greater than end date");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var payments = _paymentStorage.GetListByStudentId(studentId)
|
var paidAmount = CalculatePaidAmountByEducation(educationId);
|
||||||
?? throw new ElementNotFoundException($"Payments for student {studentId} not found");
|
|
||||||
|
|
||||||
// Фильтрация по дате создания
|
var education = _educationStorage.GetElementById(educationId)
|
||||||
return payments.Where(p => p.DateOfpayment >= startDate && p.DateOfpayment <= endDate)
|
?? throw new ElementNotFoundException(educationId);
|
||||||
.ToList();
|
|
||||||
|
var lessonIds = education.EducationLessons?.Select(el => el.LessonId) ?? [];
|
||||||
|
|
||||||
|
var totalCost = lessonIds
|
||||||
|
.Select(id => _lessonStorage.GetElementById(id)?.Price ?? 0)
|
||||||
|
.Sum();
|
||||||
|
|
||||||
|
var debt = totalCost - paidAmount;
|
||||||
|
_logger.LogInformation("Calculated debt for EducationId = {Id}: Total = {Total}, Paid = {Paid}, Debt = {Debt}",
|
||||||
|
educationId, totalCost, paidAmount, debt);
|
||||||
|
|
||||||
|
return debt;
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error while getting student payments by period");
|
_logger.LogError(ex, "Failed to calculate debt for EducationId = {Id}", educationId);
|
||||||
throw;
|
throw new StorageException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaymentDataModel> GetAllPaymentByStudetnByPaidOfState(string studentId, bool paidOf)
|
|
||||||
|
public void AddPayment(PaymentDataModel model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation(
|
|
||||||
"Getting payments for student {StudentId} with PaidOf={PaidOf}",
|
|
||||||
studentId, paidOf);
|
|
||||||
|
|
||||||
ValidateStudentId(studentId);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var allPayments = _paymentStorage.GetListByStudentId(studentId)
|
model.Validate();
|
||||||
?? throw new ElementNotFoundException($"Payments for student {studentId} not found");
|
_paymentStorage.AddElement(model);
|
||||||
|
_logger.LogInformation("Added payment: {Id}", model.Id);
|
||||||
return allPayments.Where(p => p.PaidOf == paidOf).ToList();
|
}
|
||||||
|
catch (ValidationException ve)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Validation failed in AddPayment: {Message}", ve.Message);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error while getting student payments by paid state");
|
_logger.LogError(ex, "Unexpected error in AddPayment");
|
||||||
throw;
|
throw new StorageException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaymentDataModel> GetAllPaymentByStudetnByPeriodByPaidOfState(
|
public void UpdatePayment(PaymentDataModel model)
|
||||||
string studentId, DateTime startDate, DateTime endDate, bool paidOf)
|
|
||||||
{
|
{
|
||||||
_logger.LogInformation(
|
|
||||||
"Getting payments for student {StudentId} by period from {StartDate} to {EndDate} with PaidOf={PaidOf}",
|
|
||||||
studentId, startDate, endDate, paidOf);
|
|
||||||
|
|
||||||
ValidateStudentId(studentId);
|
|
||||||
if (startDate > endDate)
|
|
||||||
throw new ValidationException("Start date cannot be greater than end date");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var payments = _paymentStorage.GetListByStudentId(studentId)
|
model.Validate();
|
||||||
?? throw new ElementNotFoundException($"Payments for student {studentId} not found");
|
|
||||||
|
|
||||||
return payments
|
var existing = _paymentStorage.GetElementById(model.Id) ?? throw new ElementNotFoundException(model.Id);
|
||||||
.Where(p => p.PaidOf == paidOf)
|
_paymentStorage.UpdElement(model);
|
||||||
.Where(p => p.DateOfpayment >= startDate && p.DateOfpayment <= endDate)
|
_logger.LogInformation("Updated payment: {Id}", model.Id);
|
||||||
.ToList();
|
}
|
||||||
|
catch (ValidationException ve)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Validation failed in UpdatePayment: {Message}", ve.Message);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException enf)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Payment not found: {Id}", model.Id);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error while getting student payments by period and paid state");
|
_logger.LogError(ex, "Unexpected error in UpdatePayment");
|
||||||
throw;
|
throw new StorageException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaymentDataModel? GetPaymentByData(string data)
|
public void DeletePayment(string id)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting payment by data: {Data}", data);
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(data))
|
|
||||||
throw new ArgumentNullException(nameof(data));
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PaymentDataModel? payment = null;
|
var existing = _paymentStorage.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
||||||
|
_paymentStorage.DelElement(existing);
|
||||||
if (data.IsGuid())
|
_logger.LogWarning("Deleted payment: {Id}", id);
|
||||||
payment = _paymentStorage.GetElementById(data);
|
|
||||||
|
|
||||||
if (payment == null && data.IsGuid())
|
|
||||||
{
|
|
||||||
var studentPayments = _paymentStorage.GetListByStudentId(data);
|
|
||||||
payment = studentPayments?.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
catch (ElementNotFoundException enf)
|
||||||
return payment ?? throw new ElementNotFoundException($"Payment with data '{data}' not found");
|
{
|
||||||
|
_logger.LogWarning("Payment not found for deletion: {Id}", id);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error while getting payment by data");
|
_logger.LogError(ex, "Unexpected error in DeletePayment");
|
||||||
throw;
|
throw new StorageException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertPayment(PaymentDataModel paymentDataModel)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Inserting payment: {PaymentData}",
|
|
||||||
JsonSerializer.Serialize(paymentDataModel));
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(paymentDataModel);
|
|
||||||
paymentDataModel.Validate();
|
|
||||||
|
|
||||||
// Дополнительная проверка студента
|
|
||||||
if (_paymentStorage.GetListByStudentId(paymentDataModel.StudentsId) == null)
|
|
||||||
throw new ElementNotFoundException($"Student with ID {paymentDataModel.StudentsId} not found");
|
|
||||||
|
|
||||||
_paymentStorage.AddElement(paymentDataModel);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while inserting payment");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CanselPayment(string id)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Canceling payment with ID: {Id}", id);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(id))
|
|
||||||
throw new ArgumentNullException(nameof(id));
|
|
||||||
|
|
||||||
if (!id.IsGuid())
|
|
||||||
throw new ValidationException("Id must be a valid GUID");
|
|
||||||
|
|
||||||
var payment = _paymentStorage.GetElementById(id)
|
|
||||||
?? throw new ElementNotFoundException($"Payment with ID {id} not found");
|
|
||||||
|
|
||||||
_paymentStorage.DelElement(payment);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while canceling payment");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ValidateStudentId(string studentId)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(studentId))
|
|
||||||
throw new ArgumentNullException(nameof(studentId));
|
|
||||||
|
|
||||||
if (!studentId.IsGuid())
|
|
||||||
throw new ValidationException("StudentId must be a valid GUID");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ internal class SalaryBusinessLogicContract(
|
|||||||
public List<SalaryDataModel> GetAllSalaries()
|
public List<SalaryDataModel> GetAllSalaries()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting all salaries");
|
_logger.LogInformation("Getting all salaries");
|
||||||
return _storage.GetList() ?? throw new NullListException();
|
return _storage.GetList() ?? throw new NullListException("GetAllSalaries");
|
||||||
}
|
}
|
||||||
|
|
||||||
public SalaryDataModel? GetSalaryById(string salaryId)
|
public SalaryDataModel? GetSalaryById(string salaryId)
|
||||||
@@ -32,13 +32,13 @@ internal class SalaryBusinessLogicContract(
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Getting salaries for teacher: {teacherId}", teacherId);
|
_logger.LogInformation("Getting salaries for teacher: {teacherId}", teacherId);
|
||||||
ValidateId(teacherId, "Teacher ID");
|
ValidateId(teacherId, "Teacher ID");
|
||||||
return _storage.GetListByTeacherId(teacherId) ?? throw new NullListException();
|
return _storage.GetListByTeacherId(teacherId) ?? throw new NullListException("GetSalariesByTeacher");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetSalariesByDate(DateTime date)
|
public List<SalaryDataModel> GetSalariesByDate(DateTime date)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting salaries for date: {date}", date.ToShortDateString());
|
_logger.LogInformation("Getting salaries for date: {date}", date.ToShortDateString());
|
||||||
return _storage.GetListByDate(date) ?? throw new NullListException();
|
return _storage.GetListByDate(date) ?? throw new NullListException("GetSalariesByDate");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetSalariesByDateAndTeacher(DateTime date, string teacherId)
|
public List<SalaryDataModel> GetSalariesByDateAndTeacher(DateTime date, string teacherId)
|
||||||
@@ -46,7 +46,7 @@ internal class SalaryBusinessLogicContract(
|
|||||||
_logger.LogInformation("Getting salaries for date {date} and teacher {teacherId}",
|
_logger.LogInformation("Getting salaries for date {date} and teacher {teacherId}",
|
||||||
date.ToShortDateString(), teacherId);
|
date.ToShortDateString(), teacherId);
|
||||||
ValidateId(teacherId, "Teacher ID");
|
ValidateId(teacherId, "Teacher ID");
|
||||||
return _storage.GetListByDateAndTeacherId(date, teacherId) ?? throw new NullListException();
|
return _storage.GetListByDateAndTeacherId(date, teacherId) ?? throw new NullListException("GetSalariesByDateAndTeacher");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetSalariesByDateRange(DateTime startDate, DateTime endDate)
|
public List<SalaryDataModel> GetSalariesByDateRange(DateTime startDate, DateTime endDate)
|
||||||
@@ -57,7 +57,7 @@ internal class SalaryBusinessLogicContract(
|
|||||||
if (startDate > endDate)
|
if (startDate > endDate)
|
||||||
throw new IncorrectDatesException(startDate, endDate);
|
throw new IncorrectDatesException(startDate, endDate);
|
||||||
|
|
||||||
return _storage.GetListByDateRange(startDate, endDate) ?? throw new NullListException();
|
return _storage.GetListByDateRange(startDate, endDate) ?? throw new NullListException("GetSalariesByDateRange");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetSalariesByDateRangeAndTeacher(DateTime startDate, DateTime endDate, string teacherId)
|
public List<SalaryDataModel> GetSalariesByDateRangeAndTeacher(DateTime startDate, DateTime endDate, string teacherId)
|
||||||
@@ -70,14 +70,14 @@ internal class SalaryBusinessLogicContract(
|
|||||||
if (startDate > endDate)
|
if (startDate > endDate)
|
||||||
throw new IncorrectDatesException(startDate, endDate);
|
throw new IncorrectDatesException(startDate, endDate);
|
||||||
|
|
||||||
return _storage.GetListByDateRangeAndTeacherId(startDate, endDate, teacherId) ?? throw new NullListException();
|
return _storage.GetListByDateRangeAndTeacherId(startDate, endDate, teacherId) ?? throw new NullListException("GetSalariesByDateRangeAndTeacher");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetSalariesAboveAmount(double amount)
|
public List<SalaryDataModel> GetSalariesAboveAmount(double amount)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting salaries above amount: {amount}", amount);
|
_logger.LogInformation("Getting salaries above amount: {amount}", amount);
|
||||||
ValidateAmount(amount);
|
ValidateAmount(amount);
|
||||||
return _storage.GetListByAmountRange(amount, double.MaxValue) ?? throw new NullListException();
|
return _storage.GetListByAmountRange(amount, double.MaxValue) ?? throw new NullListException("GetSalariesAboveAmount");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetSalariesAboveAmountForTeacher(double amount, string teacherId)
|
public List<SalaryDataModel> GetSalariesAboveAmountForTeacher(double amount, string teacherId)
|
||||||
@@ -85,14 +85,14 @@ internal class SalaryBusinessLogicContract(
|
|||||||
_logger.LogInformation("Getting salaries above amount {amount} for teacher {teacherId}", amount, teacherId);
|
_logger.LogInformation("Getting salaries above amount {amount} for teacher {teacherId}", amount, teacherId);
|
||||||
ValidateAmount(amount);
|
ValidateAmount(amount);
|
||||||
ValidateId(teacherId, "Teacher ID");
|
ValidateId(teacherId, "Teacher ID");
|
||||||
return _storage.GetListByAmountRangeAndTeacherId(amount, double.MaxValue, teacherId) ?? throw new NullListException();
|
return _storage.GetListByAmountRangeAndTeacherId(amount, double.MaxValue, teacherId) ?? throw new NullListException("GetSalariesAboveAmountForTeacher");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetSalariesBelowAmount(double amount)
|
public List<SalaryDataModel> GetSalariesBelowAmount(double amount)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting salaries below amount: {amount}", amount);
|
_logger.LogInformation("Getting salaries below amount: {amount}", amount);
|
||||||
ValidateAmount(amount);
|
ValidateAmount(amount);
|
||||||
return _storage.GetListByAmountRange(0, amount) ?? throw new NullListException();
|
return _storage.GetListByAmountRange(0, amount) ?? throw new NullListException("GetSalariesBelowAmount");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetSalariesBelowAmountForTeacher(double amount, string teacherId)
|
public List<SalaryDataModel> GetSalariesBelowAmountForTeacher(double amount, string teacherId)
|
||||||
@@ -100,14 +100,14 @@ internal class SalaryBusinessLogicContract(
|
|||||||
_logger.LogInformation("Getting salaries below amount {amount} for teacher {teacherId}", amount, teacherId);
|
_logger.LogInformation("Getting salaries below amount {amount} for teacher {teacherId}", amount, teacherId);
|
||||||
ValidateAmount(amount);
|
ValidateAmount(amount);
|
||||||
ValidateId(teacherId, "Teacher ID");
|
ValidateId(teacherId, "Teacher ID");
|
||||||
return _storage.GetListByAmountRangeAndTeacherId(0, amount, teacherId) ?? throw new NullListException();
|
return _storage.GetListByAmountRangeAndTeacherId(0, amount, teacherId) ?? throw new NullListException("GetSalariesBelowAmountForTeacher");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetSalariesInAmountRange(double minAmount, double maxAmount)
|
public List<SalaryDataModel> GetSalariesInAmountRange(double minAmount, double maxAmount)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting salaries in range {minAmount}-{maxAmount}", minAmount, maxAmount);
|
_logger.LogInformation("Getting salaries in range {minAmount}-{maxAmount}", minAmount, maxAmount);
|
||||||
ValidateAmountRange(minAmount, maxAmount);
|
ValidateAmountRange(minAmount, maxAmount);
|
||||||
return _storage.GetListByAmountRange(minAmount, maxAmount) ?? throw new NullListException();
|
return _storage.GetListByAmountRange(minAmount, maxAmount) ?? throw new NullListException("GetSalariesInAmountRange");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalaryDataModel> GetSalariesInAmountRangeForTeacher(double minAmount, double maxAmount, string teacherId)
|
public List<SalaryDataModel> GetSalariesInAmountRangeForTeacher(double minAmount, double maxAmount, string teacherId)
|
||||||
@@ -116,7 +116,7 @@ internal class SalaryBusinessLogicContract(
|
|||||||
minAmount, maxAmount, teacherId);
|
minAmount, maxAmount, teacherId);
|
||||||
ValidateAmountRange(minAmount, maxAmount);
|
ValidateAmountRange(minAmount, maxAmount);
|
||||||
ValidateId(teacherId, "Teacher ID");
|
ValidateId(teacherId, "Teacher ID");
|
||||||
return _storage.GetListByAmountRangeAndTeacherId(minAmount, maxAmount, teacherId) ?? throw new NullListException();
|
return _storage.GetListByAmountRangeAndTeacherId(minAmount, maxAmount, teacherId) ?? throw new NullListException("GetSalariesInAmountRangeForTeacher");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateSalary(SalaryDataModel salaryDataModel)
|
public void CreateSalary(SalaryDataModel salaryDataModel)
|
||||||
|
|||||||
@@ -1,319 +1,90 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using UniversityAllExpelled_Models.BusinessLogicContracts;
|
using UniversityAllExpelled_Models.BusinessLogicContracts;
|
||||||
using UniversityAllExpelled_Models.DataModels;
|
|
||||||
using UniversityAllExpelled_Models.DataModels.Client;
|
using UniversityAllExpelled_Models.DataModels.Client;
|
||||||
using UniversityAllExpelled_Models.Enums;
|
|
||||||
using UniversityAllExpelled_Models.Exceptions;
|
using UniversityAllExpelled_Models.Exceptions;
|
||||||
using UniversityAllExpelled_Models.Extensions;
|
|
||||||
using UniversityAllExpelled_Models.StorageContracts;
|
using UniversityAllExpelled_Models.StorageContracts;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace UniversityAllExpelled_BusinessLogic.Implementations;
|
namespace UniversityAllExpelled_BusinessLogic.Implementations;
|
||||||
|
|
||||||
internal class StudentBusinessLogicContract : IStudentBusinessLogicContract
|
public class StudentBusinessLogicContract(IStudentStorageContract studentStorage, ILogger<StudentBusinessLogicContract> logger) : IStudentBusinessLogicContract
|
||||||
{
|
{
|
||||||
private readonly IStudentStorageContract _studentStorage;
|
private readonly IStudentStorageContract _studentStorage = studentStorage;
|
||||||
private readonly IUserStorageContract _userStorage;
|
private readonly ILogger<StudentBusinessLogicContract> _logger = logger;
|
||||||
private readonly ILogger<StudentBusinessLogicContract> _logger;
|
|
||||||
|
|
||||||
public StudentBusinessLogicContract(
|
public List<StudentDataModel> GetAllStudents()
|
||||||
IStudentStorageContract studentStorage,
|
|
||||||
IUserStorageContract userStorage,
|
|
||||||
ILogger<StudentBusinessLogicContract> logger)
|
|
||||||
{
|
{
|
||||||
_studentStorage = studentStorage ?? throw new ArgumentNullException(nameof(studentStorage));
|
return _studentStorage.GetList();
|
||||||
_userStorage = userStorage ?? throw new ArgumentNullException(nameof(userStorage));
|
|
||||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StudentDataModel> GetAllStudents(SystemRoleType role = SystemRoleType.student, bool IsDeleted = false)
|
public StudentDataModel? GetStudentById(string id)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting all students with role: {Role}, IsDeleted: {IsDeleted}", role, IsDeleted);
|
return _studentStorage.GetElementById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StudentDataModel? GetStudentByUserId(string userId)
|
||||||
|
{
|
||||||
|
return _studentStorage.GetElementByUserId(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<StudentDataModel> GetListByCourse(int course)
|
||||||
|
{
|
||||||
|
return _studentStorage.GetListByCourse(course) ?? throw new NullListException( course.ToString()) ;// mistake
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddStudent(StudentDataModel model)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var students = _studentStorage.GetList() ?? throw new DataException("Failed to retrieve students list");
|
model.Validate();
|
||||||
|
|
||||||
var result = new List<StudentDataModel>();
|
var exists = _studentStorage.GetElementByUserId(model.UserId);
|
||||||
|
if (exists != null)
|
||||||
|
throw new ElementExistsException("UserId", model.UserId);
|
||||||
|
|
||||||
foreach (var student in students)
|
_studentStorage.AddElement(model);
|
||||||
{
|
_logger.LogInformation("Added student with UserId = {UserId}", model.UserId);
|
||||||
var user = _userStorage.GetElementById(student.UserId);
|
|
||||||
if (user != null && user.Role == role && user.IsDeleted == IsDeleted)
|
|
||||||
{
|
|
||||||
result.Add(student);
|
|
||||||
}
|
}
|
||||||
|
catch (ValidationException ve)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Validation failed in AddStudent: {Message}", ve.Message);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
catch (ElementExistsException ee)
|
||||||
return result;
|
{
|
||||||
|
_logger.LogWarning("Student already exists for UserId = {UserId}", model.UserId);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error while getting all students");
|
_logger.LogError(ex, "Unexpected error in AddStudent");
|
||||||
throw;
|
throw new StorageException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StudentDataModel> GetAllStudentsByBirthDate(DateTime startDate, DateTime endDate,
|
public void UpdateStudent(StudentDataModel model)
|
||||||
SystemRoleType role = SystemRoleType.student, bool IsDeleted = false)
|
|
||||||
{
|
{
|
||||||
_logger.LogInformation(
|
|
||||||
"Getting students by birth date from {StartDate} to {EndDate}, role: {Role}, IsDeleted: {IsDeleted}",
|
|
||||||
startDate, endDate, role, IsDeleted);
|
|
||||||
|
|
||||||
if (startDate > endDate)
|
|
||||||
throw new ValidationException("Start date cannot be greater than end date");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var students = _studentStorage.GetList() ?? throw new DataException("Failed to retrieve students list");
|
model.Validate();
|
||||||
|
|
||||||
var result = new List<StudentDataModel>();
|
var existing = _studentStorage.GetElementById(model.Id) ?? throw new ElementNotFoundException(model.Id);
|
||||||
|
_studentStorage.UpdateElement(model);
|
||||||
foreach (var student in students)
|
_logger.LogInformation("Updated student with Id = {Id}", model.Id);
|
||||||
{
|
|
||||||
var user = _userStorage.GetElementById(student.UserId);
|
|
||||||
if (user != null &&
|
|
||||||
user.Role == role &&
|
|
||||||
user.IsDeleted == IsDeleted &&
|
|
||||||
user.BirthDate >= startDate &&
|
|
||||||
user.BirthDate <= endDate)
|
|
||||||
{
|
|
||||||
result.Add(student);
|
|
||||||
}
|
}
|
||||||
|
catch (ValidationException ve)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Validation failed in UpdateStudent: {Message}", ve.Message);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
catch (ElementNotFoundException enf)
|
||||||
return result;
|
{
|
||||||
|
_logger.LogWarning("Student not found: {Id}", model.Id);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error while getting students by birth date");
|
_logger.LogError(ex, "Unexpected error in UpdateStudent");
|
||||||
throw;
|
throw new StorageException(ex);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<StudentDataModel> GetAllStudentsByFaculty(FacultyType faculty,
|
|
||||||
SystemRoleType role = SystemRoleType.student, bool IsDeleted = false)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Getting students by faculty: {Faculty}, role: {Role}, IsDeleted: {IsDeleted}",
|
|
||||||
faculty, role, IsDeleted);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var students = _studentStorage.GetListByFaculty(faculty.ToString())
|
|
||||||
?? throw new DataException($"Failed to retrieve students for faculty {faculty}");
|
|
||||||
|
|
||||||
var result = new List<StudentDataModel>();
|
|
||||||
|
|
||||||
foreach (var student in students)
|
|
||||||
{
|
|
||||||
var user = _userStorage.GetElementById(student.UserId);
|
|
||||||
if (user != null && user.Role == role && user.IsDeleted == IsDeleted)
|
|
||||||
{
|
|
||||||
result.Add(student);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while getting students by faculty");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<StudentDataModel> GetAllStudentsByGroopType(GroopType groop,
|
|
||||||
SystemRoleType role = SystemRoleType.student, bool IsDeleted = false)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Getting students by group: {Groop}, role: {Role}, IsDeleted: {IsDeleted}",
|
|
||||||
groop, role, IsDeleted);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var students = _studentStorage.GetListByGroop(groop.ToString())
|
|
||||||
?? throw new DataException($"Failed to retrieve students for group {groop}");
|
|
||||||
|
|
||||||
var result = new List<StudentDataModel>();
|
|
||||||
|
|
||||||
foreach (var student in students)
|
|
||||||
{
|
|
||||||
var user = _userStorage.GetElementById(student.UserId);
|
|
||||||
if (user != null && user.Role == role && user.IsDeleted == IsDeleted)
|
|
||||||
{
|
|
||||||
result.Add(student);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while getting students by group");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<StudentDataModel> GetAllStudentsByCource(int course,
|
|
||||||
SystemRoleType role = SystemRoleType.student, bool IsDeleted = false)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Getting students by course: {Course}, role: {Role}, IsDeleted: {IsDeleted}",
|
|
||||||
course, role, IsDeleted);
|
|
||||||
|
|
||||||
if (course < 1 || course > 6)
|
|
||||||
throw new ValidationException("Course must be between 1 and 6");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var students = _studentStorage.GetListByCource(course)
|
|
||||||
?? throw new DataException($"Failed to retrieve students for course {course}");
|
|
||||||
|
|
||||||
var result = new List<StudentDataModel>();
|
|
||||||
|
|
||||||
foreach (var student in students)
|
|
||||||
{
|
|
||||||
var user = _userStorage.GetElementById(student.UserId);
|
|
||||||
if (user != null && user.Role == role && user.IsDeleted == IsDeleted)
|
|
||||||
{
|
|
||||||
result.Add(student);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while getting students by course");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public StudentDataModel? GetStudentByData(string data,
|
|
||||||
SystemRoleType role = SystemRoleType.student, bool IsDeleted = false)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Getting student by data: {Data}, role: {Role}, IsDeleted: {IsDeleted}",
|
|
||||||
data, role, IsDeleted);
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(data))
|
|
||||||
throw new ArgumentNullException(nameof(data));
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
StudentDataModel? student = null;
|
|
||||||
|
|
||||||
// Try by student ID
|
|
||||||
if (data.IsGuid())
|
|
||||||
student = _studentStorage.GetElementById(data);
|
|
||||||
|
|
||||||
// Try by user ID
|
|
||||||
if (student == null && data.IsGuid())
|
|
||||||
student = _studentStorage.GetElementByUserId(data);
|
|
||||||
|
|
||||||
// Try by user data
|
|
||||||
if (student == null)
|
|
||||||
{
|
|
||||||
var user = _userStorage.GetElementById(data) ??
|
|
||||||
_userStorage.GetElementByPhoneNomber(data) ??
|
|
||||||
_userStorage.GetListByLogin(data);
|
|
||||||
if (user != null)
|
|
||||||
student = _studentStorage.GetElementByUserId(user.Id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (student != null)
|
|
||||||
{
|
|
||||||
var user = _userStorage.GetElementById(student.UserId);
|
|
||||||
if (user != null && user.Role == role && user.IsDeleted == IsDeleted)
|
|
||||||
return student;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while getting student by data");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InsertStudent(StudentDataModel studentDataModel)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Inserting new student: {StudentData}",
|
|
||||||
JsonSerializer.Serialize(studentDataModel));
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(studentDataModel);
|
|
||||||
studentDataModel.Validate();
|
|
||||||
|
|
||||||
var user = _userStorage.GetElementById(studentDataModel.UserId)
|
|
||||||
?? throw new ElementNotFoundException($"User with ID {studentDataModel.UserId} not found");
|
|
||||||
|
|
||||||
if (user.Role != SystemRoleType.student)
|
|
||||||
throw new ValidationException("User must have student role");
|
|
||||||
|
|
||||||
if (_studentStorage.GetElementByUserId(studentDataModel.UserId) != null)
|
|
||||||
throw new DuplicateException($"Student for user {studentDataModel.UserId} already exists");
|
|
||||||
|
|
||||||
_studentStorage.AddElement(studentDataModel);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while inserting student");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateStudent(StudentDataModel studentDataModel)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Updating student: {StudentData}",
|
|
||||||
JsonSerializer.Serialize(studentDataModel));
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(studentDataModel);
|
|
||||||
studentDataModel.Validate();
|
|
||||||
|
|
||||||
var existingStudent = _studentStorage.GetElementById(studentDataModel.Id)
|
|
||||||
?? throw new ElementNotFoundException($"Student with ID {studentDataModel.Id} not found");
|
|
||||||
|
|
||||||
if (existingStudent.UserId != studentDataModel.UserId)
|
|
||||||
throw new ValidationException("Cannot change UserId for existing student");
|
|
||||||
|
|
||||||
_studentStorage.UpdElement(studentDataModel);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while updating student");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RestoreStudent(string id)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Restoring student with ID: {Id}", id);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(id))
|
|
||||||
throw new ArgumentNullException(nameof(id));
|
|
||||||
|
|
||||||
if (!id.IsGuid())
|
|
||||||
throw new ValidationException("Id must be a valid GUID");
|
|
||||||
|
|
||||||
var student = _studentStorage.GetElementById(id)
|
|
||||||
?? throw new ElementNotFoundException($"Student with ID {id} not found");
|
|
||||||
|
|
||||||
var user = _userStorage.GetElementById(student.UserId)
|
|
||||||
?? throw new ElementNotFoundException($"User with ID {student.UserId} not found");
|
|
||||||
|
|
||||||
user.IsDeleted = false;
|
|
||||||
_userStorage.UpdElement(user);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while restoring student");
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ internal class TeacherBusinessLogicContract(
|
|||||||
public List<TeacherDataModel> GetAllTeachers()
|
public List<TeacherDataModel> GetAllTeachers()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting all teachers");
|
_logger.LogInformation("Getting all teachers");
|
||||||
return _storage.GetList() ?? throw new NullListException();
|
return _storage.GetList() ?? throw new NullListException("Teacher list is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
public TeacherDataModel? GetTeacherById(string teacherId)
|
public TeacherDataModel? GetTeacherById(string teacherId)
|
||||||
@@ -72,45 +72,16 @@ internal class TeacherBusinessLogicContract(
|
|||||||
return _storage.GetElementByUserId(userId);
|
return _storage.GetElementByUserId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TeacherDataModel> GetTeachersByPosition(TeacherPositionType position)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Getting teachers by position: {position}", position);
|
|
||||||
if (position == TeacherPositionType.None)
|
|
||||||
throw new ValidationException("Position must be specified");
|
|
||||||
|
|
||||||
return _storage.GetListByPosition(position) ?? throw new NullListException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TeacherDataModel> GetTeachersByPositions(IEnumerable<TeacherPositionType> positions)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Getting teachers by multiple positions");
|
|
||||||
ArgumentNullException.ThrowIfNull(positions);
|
|
||||||
|
|
||||||
var result = new List<TeacherDataModel>();
|
|
||||||
|
|
||||||
foreach (var position in positions)
|
|
||||||
{
|
|
||||||
if (position != TeacherPositionType.None)
|
|
||||||
{
|
|
||||||
var teachers = _storage.GetListByPosition(position);
|
|
||||||
if (teachers != null)
|
|
||||||
result.AddRange(teachers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TeacherDataModel> GetTeachersHiredAfterDate(DateTime date)
|
public List<TeacherDataModel> GetTeachersHiredAfterDate(DateTime date)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting teachers hired after: {date}", date.ToShortDateString());
|
_logger.LogInformation("Getting teachers hired after: {date}", date.ToShortDateString());
|
||||||
return _storage.GetListByHireDateRange(date.AddDays(1), DateTime.MaxValue) ?? throw new NullListException();
|
return _storage.GetListByHireDateRange(date.AddDays(1), DateTime.MaxValue) ?? throw new NullListException("Teacher list is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TeacherDataModel> GetTeachersHiredBeforeDate(DateTime date)
|
public List<TeacherDataModel> GetTeachersHiredBeforeDate(DateTime date)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting teachers hired before: {date}", date.ToShortDateString());
|
_logger.LogInformation("Getting teachers hired before: {date}", date.ToShortDateString());
|
||||||
return _storage.GetListByHireDateRange(DateTime.MinValue, date.AddDays(-1)) ?? throw new NullListException();
|
return _storage.GetListByHireDateRange(DateTime.MinValue, date.AddDays(-1)) ?? throw new NullListException("Teacher list is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TeacherDataModel> GetTeachersHiredBetweenDates(DateTime startDate, DateTime endDate)
|
public List<TeacherDataModel> GetTeachersHiredBetweenDates(DateTime startDate, DateTime endDate)
|
||||||
@@ -121,22 +92,7 @@ internal class TeacherBusinessLogicContract(
|
|||||||
if (startDate > endDate)
|
if (startDate > endDate)
|
||||||
throw new IncorrectDatesException(startDate, endDate);
|
throw new IncorrectDatesException(startDate, endDate);
|
||||||
|
|
||||||
return _storage.GetListByHireDateRange(startDate, endDate) ?? throw new NullListException();
|
return _storage.GetListByHireDateRange(startDate, endDate) ?? throw new NullListException("Teacher list is null");
|
||||||
}
|
|
||||||
|
|
||||||
public List<TeacherDataModel> GetTeachersByPositionAndHireDate(TeacherPositionType position, DateTime startDate, DateTime endDate)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Getting teachers by position {position} hired between {startDate} and {endDate}",
|
|
||||||
position, startDate.ToShortDateString(), endDate.ToShortDateString());
|
|
||||||
|
|
||||||
if (position == TeacherPositionType.None)
|
|
||||||
throw new ValidationException("Position must be specified");
|
|
||||||
|
|
||||||
if (startDate > endDate)
|
|
||||||
throw new IncorrectDatesException(startDate, endDate);
|
|
||||||
|
|
||||||
var teachers = _storage.GetListByPosition(position) ?? throw new NullListException();
|
|
||||||
return teachers.Where(t => t.DateHiring >= startDate && t.DateHiring <= endDate).ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetTeacherCount()
|
public int GetTeacherCount()
|
||||||
@@ -145,25 +101,6 @@ internal class TeacherBusinessLogicContract(
|
|||||||
return _storage.GetList()?.Count ?? 0;
|
return _storage.GetList()?.Count ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetTeacherCountByPosition(TeacherPositionType position)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Getting teacher count by position: {position}", position);
|
|
||||||
if (position == TeacherPositionType.None)
|
|
||||||
throw new ValidationException("Position must be specified");
|
|
||||||
|
|
||||||
return _storage.GetListByPosition(position)?.Count ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dictionary<TeacherPositionType, int> GetTeacherPositionDistribution()
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Getting teacher position distribution");
|
|
||||||
var teachers = _storage.GetList() ?? throw new NullListException();
|
|
||||||
|
|
||||||
return teachers
|
|
||||||
.GroupBy(t => t.Position)
|
|
||||||
.ToDictionary(g => g.Key, g => g.Count());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ValidateId(string id, string paramName)
|
private void ValidateId(string id, string paramName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(id))
|
if (string.IsNullOrWhiteSpace(id))
|
||||||
|
|||||||
@@ -1,153 +1,200 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using UniversityAllExpelled_Models.BusinessLogicContracts;
|
using UniversityAllExpelled_Models.BusinessLogicContracts;
|
||||||
using UniversityAllExpelled_Models.DataModels;
|
using UniversityAllExpelled_Models.DataModels;
|
||||||
using UniversityAllExpelled_Models.Extensions;
|
using UniversityAllExpelled_Models.Enums;
|
||||||
using UniversityAllExpelled_Models.Exceptions;
|
using UniversityAllExpelled_Models.Exceptions;
|
||||||
|
using UniversityAllExpelled_Models.Extensions;
|
||||||
using UniversityAllExpelled_Models.StorageContracts;
|
using UniversityAllExpelled_Models.StorageContracts;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace UniversityAllExpelled_BusinessLogic.Implementations;
|
namespace UniversityAllExpelled_BusinessLogic.Implementations;
|
||||||
|
|
||||||
internal class UserBusinessLogicContract(IUserStorageContract userStorageContract, ILogger<UserBusinessLogicContract> logger) : IUserBusinessLogicContract
|
public class UserBusinessLogicContract(IUserStorageContract userStorage, ILogger<UserBusinessLogicContract> logger) : IUserBusinessLogicContract
|
||||||
{
|
{
|
||||||
private readonly IUserStorageContract _userStorageContract = userStorageContract;
|
private readonly IUserStorageContract _userStorage = userStorage;
|
||||||
private readonly ILogger<UserBusinessLogicContract> _logger;
|
private readonly ILogger<UserBusinessLogicContract> _logger = logger;
|
||||||
|
|
||||||
public List<UserDataModel> GetAllUsers()
|
public List<UserDataModel> GetAllUsers()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllUsers");
|
return _userStorage.GetList();
|
||||||
var users = _userStorageContract.GetList();
|
|
||||||
return users ?? throw new DataException("Failed to retrieve users list");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserDataModel> GetAllActiveUsers(bool IsDeleted = false)
|
public List<UserDataModel> GetAllActiveUsers(bool isDeleted = false)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllActiveUsers with IsDeleted = {IsDeleted}", IsDeleted);
|
return _userStorage.GetListByIsDeleted(isDeleted);
|
||||||
var users = _userStorageContract.GetListByIsDeleted(IsDeleted);
|
|
||||||
return users ?? throw new DataException($"Failed to retrieve {(IsDeleted ? "deleted" : "active")} users list");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserDataModel> GetAllUserByBirthDate(DateTime fromDate, DateTime toDate, bool IsDeleted = false)
|
public List<UserDataModel> GetAllUsersByBirthDate(DateTime fromDate, DateTime toDate, bool isDeleted = false)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllUserByBirthDate from {fromDate} to {toDate} with IsDeleted = {IsDeleted}",
|
var users = _userStorage.GetListByIsDeleted(isDeleted);
|
||||||
fromDate, toDate, IsDeleted);
|
return [.. users.Where(u => u.BirthDate.Date >= fromDate.Date && u.BirthDate.Date <= toDate.Date)];
|
||||||
|
|
||||||
if (fromDate > toDate)
|
|
||||||
{
|
|
||||||
throw new ValidationException("FromDate cannot be greater than ToDate");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var allUsers = _userStorageContract.GetList() ?? throw new DataException("Failed to retrieve users list");
|
public UserDataModel? GetUserByLogin(string login)
|
||||||
|
|
||||||
return allUsers
|
|
||||||
.Where(u => u.BirthDate >= fromDate &&
|
|
||||||
u.BirthDate <= toDate &&
|
|
||||||
u.IsDeleted == IsDeleted)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserDataModel GetUserByData(string data)
|
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetUserByData: {data}", data);
|
return _userStorage.GetElementByLogin(login);
|
||||||
|
|
||||||
if (data.IsEmpty())
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try by ID
|
|
||||||
if (data.IsGuid())
|
|
||||||
{
|
|
||||||
var userById = _userStorageContract.GetElementById(data);
|
|
||||||
if (userById != null) return userById;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try by phone number
|
|
||||||
if (Regex.IsMatch(data, @"^(\+7|8)(-?\d{3}-?\d{3}-?\d{2}-?\d{2}|-?\d{10})$"))
|
|
||||||
{
|
|
||||||
var userByPhone = _userStorageContract.GetElementByPhoneNomber(data);
|
|
||||||
if (userByPhone != null) return userByPhone;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try by login
|
|
||||||
var userByLogin = _userStorageContract.GetListByLogin(data);
|
|
||||||
if (userByLogin != null) return userByLogin;
|
|
||||||
|
|
||||||
var usersByFio = _userStorageContract.GetListByFIO(data);
|
|
||||||
if (usersByFio != null && usersByFio.Count > 0) return usersByFio[0];
|
|
||||||
|
|
||||||
throw new ElementNotFoundException($"User with data '{data}' not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertUser(UserDataModel userDataModel)
|
public void InsertUser(UserDataModel userDataModel)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("InsertUser: {json}", JsonSerializer.Serialize(userDataModel));
|
try
|
||||||
ArgumentNullException.ThrowIfNull(userDataModel);
|
{
|
||||||
userDataModel.Validate();
|
userDataModel.Validate();
|
||||||
|
|
||||||
// Check if login already exists
|
var existing = _userStorage.GetElementByLogin(userDataModel.Login);
|
||||||
var existingUser = _userStorageContract.GetListByLogin(userDataModel.Login);
|
if (existing != null)
|
||||||
if (existingUser != null)
|
throw new ElementExistsException("Login", userDataModel.Login);
|
||||||
{
|
|
||||||
throw new DuplicateException($"User with login '{userDataModel.Login}' already exists");
|
|
||||||
}
|
|
||||||
|
|
||||||
_userStorageContract.AddElement(userDataModel);
|
_userStorage.AddElement(userDataModel);
|
||||||
|
_logger.LogInformation("Inserted new user: {Login}", userDataModel.Login);
|
||||||
|
}
|
||||||
|
catch (ValidationException ve)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Validation failed for InsertUser: {Message}", ve.Message);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ee)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Attempt to insert duplicate user: {Login}", userDataModel.Login);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Unexpected error in InsertUser");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateUser(UserDataModel userDataModel)
|
public void UpdateUser(UserDataModel userDataModel)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("UpdateUser: {json}", JsonSerializer.Serialize(userDataModel));
|
try
|
||||||
ArgumentNullException.ThrowIfNull(userDataModel);
|
{
|
||||||
userDataModel.Validate();
|
userDataModel.Validate();
|
||||||
|
|
||||||
// Verify user exists
|
var existing = _userStorage.GetElementById(userDataModel.Id) ?? throw new ElementNotFoundException(userDataModel.Id);
|
||||||
var existingUser = _userStorageContract.GetElementById(userDataModel.Id);
|
if (existing.IsDeleted)
|
||||||
if (existingUser == null)
|
throw new ElementDeletedException(userDataModel.Id);
|
||||||
{
|
|
||||||
throw new ElementNotFoundException($"User with ID '{userDataModel.Id}' not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
_userStorageContract.UpdElement(userDataModel);
|
_userStorage.UpdElement(userDataModel);
|
||||||
|
_logger.LogInformation("Updated user: {Id}", userDataModel.Id);
|
||||||
|
}
|
||||||
|
catch (ValidationException ve)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Validation failed in UpdateUser: {Message}", ve.Message);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException enf)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("User not found during update: {Id}", userDataModel.Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (ElementDeletedException ed)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Attempt to update deleted user: {Id}", userDataModel.Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Unexpected error in UpdateUser");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RestoreUser(string id)
|
public void RestoreUser(string id)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("RestoreUser with Id: {id}", id);
|
try
|
||||||
|
|
||||||
if (id.IsEmpty())
|
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(id));
|
var user = _userStorage.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
||||||
}
|
if (!user.IsDeleted)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!id.IsGuid())
|
_userStorage.Restore(id);
|
||||||
|
_logger.LogInformation("User restored: {Id}", id);
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException enf)
|
||||||
{
|
{
|
||||||
throw new ValidationException("Id is not a valid GUID");
|
_logger.LogWarning("Attempt to restore non-existent user: {Id}", id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Unexpected error in RestoreUser");
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = _userStorageContract.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
|
||||||
user.IsDeleted = false;
|
|
||||||
_userStorageContract.UpdElement(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteUser(string id)
|
public void DeleteUser(string id)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("DeleteUser with Id: {id}", id);
|
try
|
||||||
|
|
||||||
if (id.IsEmpty())
|
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(id));
|
var user = _userStorage.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
||||||
|
if (user.IsDeleted)
|
||||||
|
throw new ElementDeletedException(id);
|
||||||
|
|
||||||
|
_userStorage.MarkAsDeleted(id);
|
||||||
|
_logger.LogWarning("User marked as deleted: {Id}", id);
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException enf)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Attempt to delete non-existent user: {Id}", id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (ElementDeletedException ed)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("User already deleted: {Id}", id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Unexpected error in DeleteUser");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!id.IsGuid())
|
public UserDataModel Register(string login, string password, string email, string phone, string fio, DateTime birthDate, string role)
|
||||||
{
|
{
|
||||||
throw new ValidationException("Id is not a valid GUID");
|
try
|
||||||
|
{
|
||||||
|
if (login.IsEmpty() || password.IsEmpty() || email.IsEmpty() || phone.IsEmpty() || fio.IsEmpty())
|
||||||
|
throw new ValidationException("Registration fields must not be empty.");
|
||||||
|
|
||||||
|
if (!Enum.TryParse<SystemRoleType>(role, true, out var parsedRole) || parsedRole == SystemRoleType.None)
|
||||||
|
throw new ValidationException("Invalid role value.");
|
||||||
|
|
||||||
|
var user = new UserDataModel(Guid.NewGuid().ToString(), login, password, parsedRole, fio, birthDate, phone, email, false);
|
||||||
|
InsertUser(user);
|
||||||
|
_logger.LogInformation("User registered: {Login}", login);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
catch (ValidationException ve)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Validation failed in Register: {Message}", ve.Message);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Unexpected error in Register");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = _userStorageContract.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
public UserDataModel? Authorize(string login, string password)
|
||||||
user.IsDeleted = true;
|
{
|
||||||
_userStorageContract.UpdElement(user);
|
try
|
||||||
|
{
|
||||||
|
var user = _userStorage.GetElementByLogin(login);
|
||||||
|
if (user == null || user.Password != password || user.IsDeleted)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Authorization failed for login: {Login}", login);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Authorization successful for user: {Login}", login);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Unexpected error in Authorize");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using UniversityAllExpelled_Database.Models;
|
using UniversityAllExpelled_Database.Models;
|
||||||
|
|
||||||
public interface IUniversityDbContext
|
namespace UniversityAllExpelled_DataBase
|
||||||
{
|
{
|
||||||
|
public interface IUniversityDbContext
|
||||||
|
{
|
||||||
DbSet<User> Users { get; }
|
DbSet<User> Users { get; }
|
||||||
DbSet<Student> Students { get; }
|
DbSet<Student> Students { get; }
|
||||||
DbSet<Teacher> Teachers { get; }
|
DbSet<Teacher> Teachers { get; }
|
||||||
@@ -13,4 +15,5 @@ public interface IUniversityDbContext
|
|||||||
DbSet<EducationLessons> EducationLessons { get; }
|
DbSet<EducationLessons> EducationLessons { get; }
|
||||||
|
|
||||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
|
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,112 +1,91 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using UniversityAllExpelled_DataBase;
|
||||||
using System;
|
using UniversityAllExpelled_Database.Models;
|
||||||
using System.Collections.Generic;
|
using UniversityAllExpelled_Models.DataModels.Client;
|
||||||
using System.Linq;
|
using UniversityAllExpelled_Models.Exceptions;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UniversityAllExpelled_DataBase.Models;
|
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
|
||||||
using UniversityAllExpelled_Models.StorageContracts;
|
using UniversityAllExpelled_Models.StorageContracts;
|
||||||
|
using UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_DataBase.Implementations;
|
namespace UniversityAllExpelled_Database.Implementations;
|
||||||
|
|
||||||
internal class EducationLessonsStorageContract : IEducationLessonsStorageContract
|
internal class EducationLessonsStorageContract : IEducationLessonsStorageContract
|
||||||
{
|
{
|
||||||
private readonly UniversityAllExpelledDbContext _dbContext;
|
private readonly UniversityAllExpelledDbContext _dbContext;
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
public EducationLessonsStorageContract(UniversityAllExpelledDbContext dbContext, IMapper mapper)
|
public EducationLessonsStorageContract(UniversityAllExpelledDbContext dbContext)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_mapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddElement(EducationLessonsDataModel educationLessonsDataModel)
|
var config = new MapperConfiguration(cfg =>
|
||||||
{
|
{
|
||||||
if (educationLessonsDataModel == null)
|
cfg.CreateMap<EducationLessons, EducationLessonsDataModel>().ReverseMap();
|
||||||
throw new ArgumentNullException(nameof(educationLessonsDataModel));
|
});
|
||||||
|
|
||||||
educationLessonsDataModel.Validate();
|
_mapper = new Mapper(config);
|
||||||
|
|
||||||
var educationLessonsEntity = _mapper.Map<EducationLessons>(educationLessonsDataModel);
|
|
||||||
_dbContext.EducationLessons.Add(educationLessonsEntity);
|
|
||||||
_dbContext.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EducationLessonsDataModel? GetElement(string educationId, string lessonsId)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(educationId) || string.IsNullOrWhiteSpace(lessonsId))
|
|
||||||
throw new ArgumentException("Education ID and Lessons ID cannot be null or empty");
|
|
||||||
|
|
||||||
var entity = _dbContext.EducationLessons
|
|
||||||
.AsNoTracking()
|
|
||||||
.FirstOrDefault(el => el.EducationId == educationId && el.LessonsId == lessonsId);
|
|
||||||
|
|
||||||
return entity != null ? _mapper.Map<EducationLessonsDataModel>(entity) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationLessonsDataModel> GetList()
|
public List<EducationLessonsDataModel> GetList()
|
||||||
{
|
{
|
||||||
return _dbContext.EducationLessons
|
return [.. _dbContext.EducationLessons
|
||||||
.AsNoTracking()
|
.Select(el => _mapper.Map<EducationLessonsDataModel>(el))];
|
||||||
.Select(el => _mapper.Map<EducationLessonsDataModel>(el))
|
}
|
||||||
.ToList();
|
|
||||||
|
public EducationLessonsDataModel? GetElementByIds(string educationId, string lessonId)
|
||||||
|
{
|
||||||
|
var entity = _dbContext.EducationLessons
|
||||||
|
.FirstOrDefault(x => x.EducationId == educationId && x.LessonId == lessonId);
|
||||||
|
|
||||||
|
return entity != null ? _mapper.Map<EducationLessonsDataModel>(entity) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationLessonsDataModel> GetListByEducationId(string educationId)
|
public List<EducationLessonsDataModel> GetListByEducationId(string educationId)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(educationId))
|
return [.. _dbContext.EducationLessons
|
||||||
return new List<EducationLessonsDataModel>();
|
|
||||||
|
|
||||||
return _dbContext.EducationLessons
|
|
||||||
.AsNoTracking()
|
|
||||||
.Where(el => el.EducationId == educationId)
|
.Where(el => el.EducationId == educationId)
|
||||||
.Select(el => _mapper.Map<EducationLessonsDataModel>(el))
|
.Select(el => _mapper.Map<EducationLessonsDataModel>(el))];
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationLessonsDataModel> GetListByLessonsId(string lessonsId)
|
public List<EducationLessonsDataModel> GetListByLessonId(string lessonId)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(lessonsId))
|
return [.. _dbContext.EducationLessons
|
||||||
return new List<EducationLessonsDataModel>();
|
.Where(el => el.LessonId == lessonId)
|
||||||
|
.Select(el => _mapper.Map<EducationLessonsDataModel>(el))];
|
||||||
return _dbContext.EducationLessons
|
|
||||||
.AsNoTracking()
|
|
||||||
.Where(el => el.LessonsId == lessonsId)
|
|
||||||
.Select(el => _mapper.Map<EducationLessonsDataModel>(el))
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdElement(EducationLessonsDataModel educationLessonDataModel)
|
public void AddElement(EducationLessonsDataModel model)
|
||||||
{
|
{
|
||||||
if (educationLessonDataModel == null)
|
model.Validate();
|
||||||
throw new ArgumentNullException(nameof(educationLessonDataModel));
|
var entity = _mapper.Map<EducationLessons>(model);
|
||||||
|
_dbContext.EducationLessons.Add(entity);
|
||||||
educationLessonDataModel.Validate();
|
|
||||||
|
|
||||||
var existingEntity = _dbContext.EducationLessons
|
|
||||||
.FirstOrDefault(el => el.EducationId == educationLessonDataModel.EducationId &&
|
|
||||||
el.LessonsId == educationLessonDataModel.LessonsId);
|
|
||||||
|
|
||||||
if (existingEntity == null)
|
|
||||||
throw new KeyNotFoundException("Education-Lesson connection not found");
|
|
||||||
|
|
||||||
_mapper.Map(educationLessonDataModel, existingEntity);
|
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DelElement(EducationLessonsDataModel educationLessonDataModel)
|
public void UpdElement(EducationLessonsDataModel model)
|
||||||
{
|
{
|
||||||
if (educationLessonDataModel == null)
|
|
||||||
throw new ArgumentNullException(nameof(educationLessonDataModel));
|
|
||||||
|
|
||||||
var entity = _dbContext.EducationLessons
|
var entity = _dbContext.EducationLessons
|
||||||
.FirstOrDefault(el => el.EducationId == educationLessonDataModel.EducationId &&
|
.FirstOrDefault(x => x.EducationId == model.EducationId && x.LessonId == model.LessonId)
|
||||||
el.LessonsId == educationLessonDataModel.LessonsId);
|
?? throw new ElementNotFoundException($"{model.EducationId}+{model.LessonId}");
|
||||||
|
|
||||||
if (entity == null)
|
_mapper.Map(model, entity);
|
||||||
throw new KeyNotFoundException("Education-Lesson connection not found");
|
_dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelElement(EducationLessonsDataModel model)
|
||||||
|
{
|
||||||
|
var entity = _dbContext.EducationLessons
|
||||||
|
.FirstOrDefault(x => x.EducationId == model.EducationId && x.LessonId == model.LessonId)
|
||||||
|
?? throw new ElementNotFoundException($"{model.EducationId}+{model.LessonId}");
|
||||||
|
|
||||||
|
_dbContext.EducationLessons.Remove(entity);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteElement(string educationId, string lessonId)
|
||||||
|
{
|
||||||
|
var entity = _dbContext.EducationLessons
|
||||||
|
.FirstOrDefault(el => el.EducationId == educationId && el.LessonId == lessonId)
|
||||||
|
?? throw new ElementNotFoundException($"{educationId}+{lessonId}");
|
||||||
|
|
||||||
_dbContext.EducationLessons.Remove(entity);
|
_dbContext.EducationLessons.Remove(entity);
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
@@ -114,51 +93,17 @@ internal class EducationLessonsStorageContract : IEducationLessonsStorageContrac
|
|||||||
|
|
||||||
public void DelElementsByEducationId(string educationId)
|
public void DelElementsByEducationId(string educationId)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(educationId))
|
var elements = _dbContext.EducationLessons
|
||||||
throw new ArgumentException("Education ID cannot be null or empty", nameof(educationId));
|
.Where(el => el.EducationId == educationId);
|
||||||
|
_dbContext.EducationLessons.RemoveRange(elements);
|
||||||
var entities = _dbContext.EducationLessons
|
|
||||||
.Where(el => el.EducationId == educationId)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
_dbContext.EducationLessons.RemoveRange(entities);
|
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DelElementsByLessonId(string lessonId)
|
public void DelElementsByLessonId(string lessonId)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(lessonId))
|
var elements = _dbContext.EducationLessons
|
||||||
throw new ArgumentException("Lesson ID cannot be null or empty", nameof(lessonId));
|
.Where(el => el.LessonId == lessonId);
|
||||||
|
_dbContext.EducationLessons.RemoveRange(elements);
|
||||||
var entities = _dbContext.EducationLessons
|
|
||||||
.Where(el => el.LessonsId == lessonId)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
_dbContext.EducationLessons.RemoveRange(entities);
|
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EducationLessonsDataModel? GetElementByIds(string educationId, string lessonId)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(educationId) || string.IsNullOrWhiteSpace(lessonId))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var entity = _dbContext.EducationLessons
|
|
||||||
.AsNoTracking()
|
|
||||||
.FirstOrDefault(el => el.EducationId == educationId && el.LessonsId == lessonId);
|
|
||||||
|
|
||||||
return entity != null ? _mapper.Map<EducationLessonsDataModel>(entity) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EducationLessonsDataModel> GetListByLessonId(string lessonId)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(lessonId))
|
|
||||||
return new List<EducationLessonsDataModel>();
|
|
||||||
|
|
||||||
return _dbContext.EducationLessons
|
|
||||||
.AsNoTracking()
|
|
||||||
.Where(el => el.LessonsId == lessonId)
|
|
||||||
.Select(el => _mapper.Map<EducationLessonsDataModel>(el))
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,159 +1,143 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using UniversityAllExpelled_DataBase;
|
||||||
using System.Collections.Generic;
|
using UniversityAllExpelled_Database.Models;
|
||||||
using System.Linq;
|
|
||||||
using UniversityAllExpelled_DataBase.Models;
|
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
|
using UniversityAllExpelled_Models.Exceptions;
|
||||||
using UniversityAllExpelled_Models.StorageContracts;
|
using UniversityAllExpelled_Models.StorageContracts;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_DataBase.Implementations;
|
namespace UniversityAllExpelled_Database.Implementations;
|
||||||
|
|
||||||
internal class EducationStorageContract : IEducationStorageContract
|
internal class EducationStorageContract : IEducationStorageContract
|
||||||
{
|
{
|
||||||
private readonly UniversityAllExpelledDbContext _dbContext;
|
private readonly UniversityAllExpelledDbContext _dbContext;
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
public EducationStorageContract(UniversityAllExpelledDbContext dbContext, IMapper mapper)
|
public EducationStorageContract(UniversityAllExpelledDbContext dbContext)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_mapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddElement(EducationDataModel educationDataModel)
|
var config = new MapperConfiguration(cfg =>
|
||||||
{
|
{
|
||||||
if (educationDataModel == null)
|
cfg.CreateMap<Education, EducationDataModel>().ReverseMap();
|
||||||
throw new ArgumentNullException(nameof(educationDataModel));
|
});
|
||||||
|
|
||||||
educationDataModel.Validate();
|
_mapper = new Mapper(config);
|
||||||
|
|
||||||
var educationEntity = _mapper.Map<Education>(educationDataModel);
|
|
||||||
_dbContext.Educations.Add(educationEntity);
|
|
||||||
_dbContext.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EducationDataModel? GetElementById(string id)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(id) || !Guid.TryParse(id, out _))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var educationEntity = _dbContext.Educations
|
|
||||||
.AsNoTracking()
|
|
||||||
.FirstOrDefault(e => e.Id == id);
|
|
||||||
|
|
||||||
return educationEntity != null ? _mapper.Map<EducationDataModel>(educationEntity) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationDataModel> GetList()
|
public List<EducationDataModel> GetList()
|
||||||
{
|
{
|
||||||
return _dbContext.Educations
|
try
|
||||||
.AsNoTracking()
|
{
|
||||||
.Select(e => new EducationDataModel(
|
return [.. _dbContext.Educations
|
||||||
e.Id,
|
.Include(e => e.EducationLessons)
|
||||||
e.TeacherId,
|
.Select(e => _mapper.Map<EducationDataModel>(e))];
|
||||||
e.Amount,
|
}
|
||||||
e.StartDate,
|
catch (Exception ex)
|
||||||
e.EndDate,
|
{
|
||||||
e.Active))
|
throw new StorageException(ex);
|
||||||
.ToList();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public EducationDataModel? GetElementById(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entity = _dbContext.Educations
|
||||||
|
.Include(e => e.EducationLessons)
|
||||||
|
.FirstOrDefault(e => e.Id == id);
|
||||||
|
return entity != null ? _mapper.Map<EducationDataModel>(entity) : null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new StorageException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddElement(EducationDataModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model.Validate();
|
||||||
|
_dbContext.Educations.Add(_mapper.Map<Education>(model));
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new StorageException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdElement(EducationDataModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model.Validate();
|
||||||
|
var entity = _dbContext.Educations.FirstOrDefault(e => e.Id == model.Id)
|
||||||
|
?? throw new ElementNotFoundException(model.Id);
|
||||||
|
|
||||||
|
_mapper.Map(model, entity);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new StorageException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelElement(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entity = _dbContext.Educations.FirstOrDefault(e => e.Id == id)
|
||||||
|
?? throw new ElementNotFoundException(id);
|
||||||
|
|
||||||
|
_dbContext.Educations.Remove(entity);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new StorageException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationDataModel> GetListByTeacherId(string teacherId)
|
public List<EducationDataModel> GetListByTeacherId(string teacherId)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(teacherId) || !Guid.TryParse(teacherId, out _))
|
return [.. _dbContext.Educations
|
||||||
return new List<EducationDataModel>();
|
.Include(e => e.EducationLessons)
|
||||||
|
|
||||||
return _dbContext.Educations
|
|
||||||
.AsNoTracking()
|
|
||||||
.Where(e => e.TeacherId == teacherId)
|
.Where(e => e.TeacherId == teacherId)
|
||||||
.Select(e => new EducationDataModel(
|
.Select(e => _mapper.Map<EducationDataModel>(e))];
|
||||||
e.Id,
|
|
||||||
e.TeacherId,
|
|
||||||
e.Amount,
|
|
||||||
e.StartDate,
|
|
||||||
e.EndDate,
|
|
||||||
e.Active))
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationDataModel> GetListByActive(bool active)
|
public List<EducationDataModel> GetListByActive(bool active)
|
||||||
{
|
{
|
||||||
return _dbContext.Educations
|
return [.. _dbContext.Educations
|
||||||
.AsNoTracking()
|
.Include(e => e.EducationLessons)
|
||||||
.Where(e => e.Active == active)
|
.Where(e => e.Active == active)
|
||||||
.Select(e => new EducationDataModel(
|
.Select(e => _mapper.Map<EducationDataModel>(e))];
|
||||||
e.Id,
|
|
||||||
e.TeacherId,
|
|
||||||
e.Amount,
|
|
||||||
e.StartDate,
|
|
||||||
e.EndDate,
|
|
||||||
e.Active))
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationDataModel> GetListByDateRange(DateTime startDate, DateTime endDate)
|
public List<EducationDataModel> GetListByDateRange(DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
if (startDate > endDate)
|
return [.. _dbContext.Educations
|
||||||
return new List<EducationDataModel>();
|
.Include(e => e.EducationLessons)
|
||||||
|
|
||||||
return _dbContext.Educations
|
|
||||||
.AsNoTracking()
|
|
||||||
.Where(e => e.StartDate >= startDate && e.EndDate <= endDate)
|
.Where(e => e.StartDate >= startDate && e.EndDate <= endDate)
|
||||||
.Select(e => new EducationDataModel(
|
.Select(e => _mapper.Map<EducationDataModel>(e))];
|
||||||
e.Id,
|
|
||||||
e.TeacherId,
|
|
||||||
e.Amount,
|
|
||||||
e.StartDate,
|
|
||||||
e.EndDate,
|
|
||||||
e.Active))
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdElement(EducationDataModel educationDataModel)
|
|
||||||
{
|
|
||||||
if (educationDataModel == null)
|
|
||||||
throw new ArgumentNullException(nameof(educationDataModel));
|
|
||||||
|
|
||||||
educationDataModel.Validate();
|
|
||||||
|
|
||||||
var existingEducation = _dbContext.Educations.Find(educationDataModel.Id);
|
|
||||||
if (existingEducation == null)
|
|
||||||
throw new KeyNotFoundException($"Education record with id {educationDataModel.Id} not found");
|
|
||||||
|
|
||||||
existingEducation.TeacherId = educationDataModel.TeacherId;
|
|
||||||
existingEducation.Amount = educationDataModel.Amount;
|
|
||||||
existingEducation.StartDate = educationDataModel.StartDate;
|
|
||||||
existingEducation.EndDate = educationDataModel.EndDate;
|
|
||||||
existingEducation.Active = educationDataModel.Active;
|
|
||||||
|
|
||||||
_dbContext.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DelElement(EducationDataModel educationDataModel)
|
|
||||||
{
|
|
||||||
if (educationDataModel == null)
|
|
||||||
throw new ArgumentNullException(nameof(educationDataModel));
|
|
||||||
|
|
||||||
var educationEntity = _dbContext.Educations.Find(educationDataModel.Id);
|
|
||||||
if (educationEntity == null)
|
|
||||||
throw new KeyNotFoundException($"Education record with id {educationDataModel.Id} not found");
|
|
||||||
|
|
||||||
_dbContext.Educations.Remove(educationEntity);
|
|
||||||
_dbContext.SaveChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EducationDataModel> GetAllEducationByLessons()
|
public List<EducationDataModel> GetAllEducationByLessons()
|
||||||
{
|
{
|
||||||
var educationLessons = _dbContext.EducationLessons
|
return [.. _dbContext.Educations
|
||||||
.AsNoTracking()
|
.Include(e => e.EducationLessons)
|
||||||
.Include(el => el.Education)
|
.Where(e => e.EducationLessons.Any())
|
||||||
.ToList();
|
.Select(e => _mapper.Map<EducationDataModel>(e))];
|
||||||
|
|
||||||
var result = educationLessons
|
|
||||||
.Where(el => el.Education != null)
|
|
||||||
.Select(el => _mapper.Map<EducationDataModel>(el.Education))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using UniversityAllExpelled_Database.Models;
|
using UniversityAllExpelled_Database.Models;
|
||||||
using UniversityAllExpelled_DataBase;
|
using UniversityAllExpelled_DataBase;
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels;
|
||||||
using UniversityAllExpelled_Models.Exceptions;
|
using UniversityAllExpelled_Models.Exceptions;
|
||||||
using UniversityAllExpelled_Models.StorageContracts;
|
using UniversityAllExpelled_Models.StorageContracts;
|
||||||
|
|
||||||
@@ -13,6 +13,8 @@ internal class LessonStorageContract : ILessonStorageContract
|
|||||||
private readonly UniversityAllExpelledDbContext _dbContext;
|
private readonly UniversityAllExpelledDbContext _dbContext;
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
public LessonStorageContract(IMapper mapper) => _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
|
||||||
|
|
||||||
public LessonStorageContract(UniversityAllExpelledDbContext dbContext)
|
public LessonStorageContract(UniversityAllExpelledDbContext dbContext)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
@@ -31,6 +33,9 @@ internal class LessonStorageContract : ILessonStorageContract
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _dbContext.Lessons
|
return _dbContext.Lessons
|
||||||
|
.Include(l => l.EducationLessons)
|
||||||
|
.Include(l => l.Salary)
|
||||||
|
.ThenInclude(s => s.Teacher)
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Select(x => _mapper.Map<LessonDataModel>(x))
|
.Select(x => _mapper.Map<LessonDataModel>(x))
|
||||||
.ToList();
|
.ToList();
|
||||||
@@ -41,6 +46,7 @@ internal class LessonStorageContract : ILessonStorageContract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public LessonDataModel? GetElementById(string id)
|
public LessonDataModel? GetElementById(string id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -30,10 +30,9 @@ internal class PaymentStorageContract : IPaymentStorageContract
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _dbContext.Payments
|
return [.. _dbContext.Payments
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Select(x => _mapper.Map<PaymentDataModel>(x))
|
.Select(x => _mapper.Map<PaymentDataModel>(x))];
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -58,10 +57,9 @@ internal class PaymentStorageContract : IPaymentStorageContract
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _dbContext.Payments
|
return [.. _dbContext.Payments
|
||||||
.Where(x => x.StudentId == studentId)
|
.Where(x => x.StudentId == studentId)
|
||||||
.Select(x => _mapper.Map<PaymentDataModel>(x))
|
.Select(x => _mapper.Map<PaymentDataModel>(x))];
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -73,10 +71,9 @@ internal class PaymentStorageContract : IPaymentStorageContract
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _dbContext.Payments
|
return [.. _dbContext.Payments
|
||||||
.Where(x => x.IsPaid == isPaid)
|
.Where(x => x.IsPaid == isPaid)
|
||||||
.Select(x => _mapper.Map<PaymentDataModel>(x))
|
.Select(x => _mapper.Map<PaymentDataModel>(x))];
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -110,10 +107,7 @@ internal class PaymentStorageContract : IPaymentStorageContract
|
|||||||
{
|
{
|
||||||
model.Validate();
|
model.Validate();
|
||||||
|
|
||||||
var entity = _dbContext.Payments.FirstOrDefault(x => x.Id == model.Id);
|
var entity = _dbContext.Payments.FirstOrDefault(x => x.Id == model.Id) ?? throw new ElementNotFoundException(model.Id);
|
||||||
if (entity == null)
|
|
||||||
throw new ElementNotFoundException(model.Id);
|
|
||||||
|
|
||||||
_mapper.Map(model, entity);
|
_mapper.Map(model, entity);
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
@@ -135,10 +129,7 @@ internal class PaymentStorageContract : IPaymentStorageContract
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var entity = _dbContext.Payments.FirstOrDefault(x => x.Id == model.Id);
|
var entity = _dbContext.Payments.FirstOrDefault(x => x.Id == model.Id) ?? throw new ElementNotFoundException(model.Id);
|
||||||
if (entity == null)
|
|
||||||
throw new ElementNotFoundException(model.Id);
|
|
||||||
|
|
||||||
_dbContext.Payments.Remove(entity);
|
_dbContext.Payments.Remove(entity);
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UniversityAllExpelled_DataBase.Models;
|
using UniversityAllExpelled_Database;
|
||||||
|
using UniversityAllExpelled_Database.Models;
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
using UniversityAllExpelled_Models.StorageContracts;
|
using UniversityAllExpelled_Models.StorageContracts;
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,9 @@ internal class StudentStorageContract : IStudentStorageContract
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _dbContext.Students
|
return [.. _dbContext.Students
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Select(x => _mapper.Map<StudentDataModel>(x))
|
.Select(x => _mapper.Map<StudentDataModel>(x))];
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -75,10 +74,9 @@ internal class StudentStorageContract : IStudentStorageContract
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _dbContext.Students
|
return [.. _dbContext.Students
|
||||||
.Where(x => x.Course == course)
|
.Where(x => x.Course == course)
|
||||||
.Select(x => _mapper.Map<StudentDataModel>(x))
|
.Select(x => _mapper.Map<StudentDataModel>(x))];
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -114,16 +112,13 @@ internal class StudentStorageContract : IStudentStorageContract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdElement(StudentDataModel model)
|
public void UpdateElement(StudentDataModel model)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
model.Validate();
|
model.Validate();
|
||||||
|
|
||||||
var entity = GetEntityById(model.Id);
|
var entity = GetEntityById(model.Id) ?? throw new ElementNotFoundException(model.Id);
|
||||||
if (entity == null)
|
|
||||||
throw new ElementNotFoundException(model.Id);
|
|
||||||
|
|
||||||
_mapper.Map(model, entity);
|
_mapper.Map(model, entity);
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using UniversityAllExpelled_DataBase.Models;
|
using UniversityAllExpelled_Database;
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
using UniversityAllExpelled_Models.Enums;
|
|
||||||
using UniversityAllExpelled_Models.StorageContracts;
|
using UniversityAllExpelled_Models.StorageContracts;
|
||||||
|
using DB = UniversityAllExpelled_Database.Models;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_DataBase.Implementations;
|
namespace UniversityAllExpelled_DataBase.Implementations;
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ internal class TeacherStorageContract : ITeacherStorageContract
|
|||||||
|
|
||||||
teacherDataModel.Validate();
|
teacherDataModel.Validate();
|
||||||
|
|
||||||
var teacherEntity = _mapper.Map<Teacher>(teacherDataModel);
|
var teacherEntity = _mapper.Map<DB.Teacher>(teacherDataModel);
|
||||||
_dbContext.Teachers.Add(teacherEntity);
|
_dbContext.Teachers.Add(teacherEntity);
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
@@ -50,42 +50,6 @@ internal class TeacherStorageContract : ITeacherStorageContract
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TeacherDataModel> GetListByPosition(TeacherPositionType position)
|
|
||||||
{
|
|
||||||
if (position == TeacherPositionType.None)
|
|
||||||
return new List<TeacherDataModel>();
|
|
||||||
|
|
||||||
return _dbContext.Teachers
|
|
||||||
.AsNoTracking()
|
|
||||||
.Where(t => t.Position == position)
|
|
||||||
.Select(t => _mapper.Map<TeacherDataModel>(t))
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TeacherDataModel> GetListByDateHiring(DateTime dateHiring)
|
|
||||||
{
|
|
||||||
return _dbContext.Teachers
|
|
||||||
.AsNoTracking()
|
|
||||||
.Where(t => t.DateHiring.Date == dateHiring.Date)
|
|
||||||
.Select(t => _mapper.Map<TeacherDataModel>(t))
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdElement(TeacherDataModel teacherDataModel)
|
|
||||||
{
|
|
||||||
if (teacherDataModel == null)
|
|
||||||
throw new ArgumentNullException(nameof(teacherDataModel));
|
|
||||||
|
|
||||||
teacherDataModel.Validate();
|
|
||||||
|
|
||||||
var existingTeacher = _dbContext.Teachers.Find(teacherDataModel.Id);
|
|
||||||
if (existingTeacher == null)
|
|
||||||
throw new KeyNotFoundException($"Teacher with id {teacherDataModel.Id} not found");
|
|
||||||
|
|
||||||
_mapper.Map(teacherDataModel, existingTeacher);
|
|
||||||
_dbContext.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TeacherDataModel? GetElementByUserId(string userId)
|
public TeacherDataModel? GetElementByUserId(string userId)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(userId))
|
if (string.IsNullOrWhiteSpace(userId))
|
||||||
@@ -110,6 +74,21 @@ internal class TeacherStorageContract : ITeacherStorageContract
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdElement(TeacherDataModel teacherDataModel)
|
||||||
|
{
|
||||||
|
if (teacherDataModel == null)
|
||||||
|
throw new ArgumentNullException(nameof(teacherDataModel));
|
||||||
|
|
||||||
|
teacherDataModel.Validate();
|
||||||
|
|
||||||
|
var existingTeacher = _dbContext.Teachers.Find(teacherDataModel.Id);
|
||||||
|
if (existingTeacher == null)
|
||||||
|
throw new KeyNotFoundException($"Teacher with id {teacherDataModel.Id} not found");
|
||||||
|
|
||||||
|
_mapper.Map(teacherDataModel, existingTeacher);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
public void DelElement(TeacherDataModel teacherDataModel)
|
public void DelElement(TeacherDataModel teacherDataModel)
|
||||||
{
|
{
|
||||||
if (teacherDataModel == null)
|
if (teacherDataModel == null)
|
||||||
|
|||||||
@@ -1,38 +1,29 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using UniversityAllExpelled_Models.DataModels.Client;
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Database.Models;
|
namespace UniversityAllExpelled_Database.Models;
|
||||||
|
|
||||||
|
[Table("Educations")]
|
||||||
public class Education : EducationDataModel
|
public class Education : EducationDataModel
|
||||||
{
|
{
|
||||||
public Education(string id, string teacherId, float amount, DateTime startDate, DateTime endDate, bool active)
|
protected Education() : base(string.Empty, string.Empty, 0, DateTime.MinValue, DateTime.MinValue, false) { }
|
||||||
|
|
||||||
|
public Education(string id, string teacherId, string lessonId, float amount, DateTime startDate, DateTime endDate, bool active)
|
||||||
: base(id, teacherId, amount, startDate, endDate, active) { }
|
: base(id, teacherId, amount, startDate, endDate, active) { }
|
||||||
|
|
||||||
protected Education() : base(string.Empty, string.Empty, 0f, DateTime.MinValue, DateTime.MinValue, false) { }
|
|
||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
||||||
public override string Id { get; set; }
|
public override string Id { get; set; }
|
||||||
|
|
||||||
[Required]
|
[ForeignKey(nameof(Teacher))]
|
||||||
public override string TeacherId { get; set; }
|
public override string TeacherId { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
[Range(0.01, float.MaxValue)]
|
|
||||||
[Column(TypeName = "real")]
|
|
||||||
public override float Amount { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[Column(TypeName = "date")]
|
|
||||||
public override DateTime StartDate { get; set; }
|
public override DateTime StartDate { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
[Column(TypeName = "date")]
|
|
||||||
public override DateTime EndDate { get; set; }
|
public override DateTime EndDate { get; set; }
|
||||||
|
|
||||||
[Required]
|
public virtual Teacher Teacher { get; set; } = null!;
|
||||||
public override bool Active { get; set; }
|
public virtual List<EducationLessons> EducationLessons { get; set; } = new();
|
||||||
|
public virtual List<Payment> Payments { get; set; } = new();
|
||||||
public virtual Teacher? Teacher { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,15 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using UniversityAllExpelled_Models.DataModels.Client;
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Database.Models;
|
namespace UniversityAllExpelled_Database.Models;
|
||||||
|
|
||||||
public class EducationLessons : EducationLessonsDataModel
|
[Table("EducationLessons")]
|
||||||
|
public class EducationLessons(string educationId, string lessonId) : EducationLessonsDataModel(educationId, lessonId)
|
||||||
{
|
{
|
||||||
public EducationLessons(string educationId, string lessonsId)
|
public override string EducationId { get; set; } = educationId;
|
||||||
: base(educationId, lessonsId) { }
|
public override string LessonId { get; set; } = lessonId;
|
||||||
|
|
||||||
protected EducationLessons() : base(string.Empty, string.Empty) { }
|
public virtual Education Education { get; set; } = null!;
|
||||||
|
public virtual Lesson Lesson { get; set; } = null!;
|
||||||
[Key]
|
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public override string EducationId { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public override string LessonsId { get; set; }
|
|
||||||
|
|
||||||
public virtual Education? Education { get; set; }
|
|
||||||
public virtual Lesson? Lesson { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ public class Payment : PaymentDataModel
|
|||||||
[Key]
|
[Key]
|
||||||
public override string Id { get; set; }
|
public override string Id { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
[ForeignKey(nameof(Student))]
|
[ForeignKey(nameof(Student))]
|
||||||
public override string StudentId { get; set; }
|
public override string StudentId { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,12 @@ public class Salary : SalaryDataModel
|
|||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
public override string Id { get; set; }
|
public override string Id { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(Teacher))]
|
||||||
[Required]
|
[Required]
|
||||||
public override string TeacherId { get; set; }
|
public override string TeacherId { get; set; }
|
||||||
|
|
||||||
|
public virtual Teacher Teacher { get; set; } = null!;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[Range(0.01, double.MaxValue)]
|
[Range(0.01, double.MaxValue)]
|
||||||
[Column(TypeName = "numeric(18,2)")]
|
[Column(TypeName = "numeric(18,2)")]
|
||||||
@@ -28,5 +31,5 @@ public class Salary : SalaryDataModel
|
|||||||
public override DateTime Date { get; set; }
|
public override DateTime Date { get; set; }
|
||||||
|
|
||||||
[InverseProperty(nameof(Lesson.Salary))]
|
[InverseProperty(nameof(Lesson.Salary))]
|
||||||
public virtual Lesson? Lesson { get; set; }
|
public virtual List<Lesson>? Lessons { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ public class Student : StudentDataModel
|
|||||||
protected Student() : base(string.Empty, string.Empty, 1) { }
|
protected Student() : base(string.Empty, string.Empty, 1) { }
|
||||||
|
|
||||||
public Student(string id, string userId, int course)
|
public Student(string id, string userId, int course)
|
||||||
: base(id, userId, course)
|
: base(id, userId, course) { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
public override string Id { get; set; }
|
public override string Id { get; set; }
|
||||||
@@ -22,9 +20,7 @@ public class Student : StudentDataModel
|
|||||||
|
|
||||||
public override int Course { get; set; }
|
public override int Course { get; set; }
|
||||||
|
|
||||||
// Навигации
|
public virtual User User { get; set; } = null!;
|
||||||
public virtual User? User { get; set; }
|
|
||||||
|
|
||||||
[InverseProperty(nameof(Payment.Student))]
|
|
||||||
public virtual List<Payment> Payments { get; set; } = new();
|
public virtual List<Payment> Payments { get; set; } = new();
|
||||||
|
public virtual List<Lesson> Lessons { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using UniversityAllExpelled_Database.Models;
|
using UniversityAllExpelled_Database.Models;
|
||||||
|
using UniversityAllExpelled_DataBase;
|
||||||
using UniversityAllExpelled_Models.Infrastructure;
|
using UniversityAllExpelled_Models.Infrastructure;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Database;
|
namespace UniversityAllExpelled_Database;
|
||||||
|
|||||||
@@ -1,38 +1,29 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using UniversityAllExpelled_Models.DataModels.Client;
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Database.Models;
|
namespace UniversityAllExpelled_Database.Models;
|
||||||
|
|
||||||
|
[Table("Educations")]
|
||||||
public class Education : EducationDataModel
|
public class Education : EducationDataModel
|
||||||
{
|
{
|
||||||
public Education(string id, string teacherId, float amount, DateTime startDate, DateTime endDate, bool active)
|
protected Education() : base(string.Empty, string.Empty, 0, DateTime.MinValue, DateTime.MinValue, false) { }
|
||||||
|
|
||||||
|
public Education(string id, string teacherId, string lessonId, float amount, DateTime startDate, DateTime endDate, bool active)
|
||||||
: base(id, teacherId, amount, startDate, endDate, active) { }
|
: base(id, teacherId, amount, startDate, endDate, active) { }
|
||||||
|
|
||||||
protected Education() : base(string.Empty, string.Empty, 0f, DateTime.MinValue, DateTime.MinValue, false) { }
|
|
||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
||||||
public override string Id { get; set; }
|
public override string Id { get; set; }
|
||||||
|
|
||||||
[Required]
|
[ForeignKey(nameof(Teacher))]
|
||||||
public override string TeacherId { get; set; }
|
public override string TeacherId { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
[Range(0.01, float.MaxValue)]
|
|
||||||
[Column(TypeName = "real")]
|
|
||||||
public override float Amount { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[Column(TypeName = "date")]
|
|
||||||
public override DateTime StartDate { get; set; }
|
public override DateTime StartDate { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
[Column(TypeName = "date")]
|
|
||||||
public override DateTime EndDate { get; set; }
|
public override DateTime EndDate { get; set; }
|
||||||
|
|
||||||
[Required]
|
public virtual Teacher Teacher { get; set; } = null!;
|
||||||
public override bool Active { get; set; }
|
public virtual List<EducationLessons> EducationLessons { get; set; } = new();
|
||||||
|
public virtual List<Payment> Payments { get; set; } = new();
|
||||||
public virtual Teacher? Teacher { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,15 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using UniversityAllExpelled_Models.DataModels.Client;
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Database.Models;
|
namespace UniversityAllExpelled_Database.Models;
|
||||||
|
|
||||||
public class EducationLessons : EducationLessonsDataModel
|
[Table("EducationLessons")]
|
||||||
|
public class EducationLessons(string educationId, string lessonId) : EducationLessonsDataModel(educationId, lessonId)
|
||||||
{
|
{
|
||||||
public EducationLessons(string educationId, string lessonsId)
|
public override string EducationId { get; set; } = educationId;
|
||||||
: base(educationId, lessonsId) { }
|
public override string LessonId { get; set; } = lessonId;
|
||||||
|
|
||||||
protected EducationLessons() : base(string.Empty, string.Empty) { }
|
public virtual Education Education { get; set; } = null!;
|
||||||
|
public virtual Lesson Lesson { get; set; } = null!;
|
||||||
[Key]
|
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public override string EducationId { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public override string LessonsId { get; set; }
|
|
||||||
|
|
||||||
public virtual Education? Education { get; set; }
|
|
||||||
public virtual Lesson? Lesson { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,21 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Database.Models;
|
namespace UniversityAllExpelled_Database.Models;
|
||||||
|
|
||||||
[Table("Lessons")]
|
[Table("Lessons")]
|
||||||
public class Lesson : LessonDataModel
|
public class Lesson : LessonDataModel
|
||||||
{
|
{
|
||||||
protected Lesson() : base(string.Empty, string.Empty, 0, DateTime.MinValue, DateTime.MinValue, string.Empty, string.Empty, false) { }
|
protected Lesson() : base(string.Empty, string.Empty, 0, DateTime.MinValue, DateTime.MinValue, string.Empty, string.Empty, true) { }
|
||||||
|
|
||||||
public Lesson(string id, string name, double price, DateTime startDate, DateTime endDate, string studentId, string salaryId, bool isActive)
|
public Lesson(string id, string name, double price, DateTime startDate, DateTime endDate, string studentId, string salaryId, bool isActive)
|
||||||
: base(id, name, price, startDate, endDate, studentId, salaryId, isActive)
|
: base(id, name, price, startDate, endDate, studentId, salaryId, isActive) { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
public override string Id { get; set; }
|
public override string Id { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[MaxLength(100)]
|
|
||||||
public override string Name { get; set; }
|
public override string Name { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
@@ -30,7 +27,6 @@ public class Lesson : LessonDataModel
|
|||||||
[Required]
|
[Required]
|
||||||
public override DateTime EndDate { get; set; }
|
public override DateTime EndDate { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
[ForeignKey(nameof(Student))]
|
[ForeignKey(nameof(Student))]
|
||||||
public override string StudentId { get; set; }
|
public override string StudentId { get; set; }
|
||||||
|
|
||||||
@@ -39,7 +35,7 @@ public class Lesson : LessonDataModel
|
|||||||
|
|
||||||
public override bool IsActive { get; set; }
|
public override bool IsActive { get; set; }
|
||||||
|
|
||||||
// Навигации
|
|
||||||
public virtual Student Student { get; set; } = null!;
|
public virtual Student Student { get; set; } = null!;
|
||||||
public virtual Salary? Salary { get; set; }
|
public virtual Salary? Salary { get; set; }
|
||||||
|
public virtual List<EducationLessons> EducationLessons { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ public class Payment : PaymentDataModel
|
|||||||
[Key]
|
[Key]
|
||||||
public override string Id { get; set; }
|
public override string Id { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
[ForeignKey(nameof(Student))]
|
[ForeignKey(nameof(Student))]
|
||||||
public override string StudentId { get; set; }
|
public override string StudentId { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,12 @@ public class Salary : SalaryDataModel
|
|||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
public override string Id { get; set; }
|
public override string Id { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(Teacher))]
|
||||||
[Required]
|
[Required]
|
||||||
public override string TeacherId { get; set; }
|
public override string TeacherId { get; set; }
|
||||||
|
|
||||||
|
public virtual Teacher Teacher { get; set; } = null!;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[Range(0.01, double.MaxValue)]
|
[Range(0.01, double.MaxValue)]
|
||||||
[Column(TypeName = "numeric(18,2)")]
|
[Column(TypeName = "numeric(18,2)")]
|
||||||
@@ -28,5 +31,5 @@ public class Salary : SalaryDataModel
|
|||||||
public override DateTime Date { get; set; }
|
public override DateTime Date { get; set; }
|
||||||
|
|
||||||
[InverseProperty(nameof(Lesson.Salary))]
|
[InverseProperty(nameof(Lesson.Salary))]
|
||||||
public virtual Lesson? Lesson { get; set; }
|
public virtual List<Lesson>? Lessons { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ public class Student : StudentDataModel
|
|||||||
protected Student() : base(string.Empty, string.Empty, 1) { }
|
protected Student() : base(string.Empty, string.Empty, 1) { }
|
||||||
|
|
||||||
public Student(string id, string userId, int course)
|
public Student(string id, string userId, int course)
|
||||||
: base(id, userId, course)
|
: base(id, userId, course) { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
public override string Id { get; set; }
|
public override string Id { get; set; }
|
||||||
@@ -22,9 +20,7 @@ public class Student : StudentDataModel
|
|||||||
|
|
||||||
public override int Course { get; set; }
|
public override int Course { get; set; }
|
||||||
|
|
||||||
// Навигации
|
public virtual User User { get; set; } = null!;
|
||||||
public virtual User? User { get; set; }
|
|
||||||
|
|
||||||
[InverseProperty(nameof(Payment.Student))]
|
|
||||||
public virtual List<Payment> Payments { get; set; } = new();
|
public virtual List<Payment> Payments { get; set; } = new();
|
||||||
|
public virtual List<Lesson> Lessons { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ interface IEducationBusinessLogicContract
|
|||||||
List<EducationDataModel> GetAllEducationsByTeacherByActive(string teacherId, bool isActive);
|
List<EducationDataModel> GetAllEducationsByTeacherByActive(string teacherId, bool isActive);
|
||||||
List<EducationDataModel> GetAllEducationsByTeacherByPeriod(string teacherId, DateTime startDate, DateTime endDate);
|
List<EducationDataModel> GetAllEducationsByTeacherByPeriod(string teacherId, DateTime startDate, DateTime endDate);
|
||||||
List<EducationDataModel> GetAllEducationsByTeacherByPeriodByActive(string teacherId, DateTime startDate, DateTime endDate, bool isActive);
|
List<EducationDataModel> GetAllEducationsByTeacherByPeriodByActive(string teacherId, DateTime startDate, DateTime endDate, bool isActive);
|
||||||
|
double CalculateTotalPriceByEducation(string educationId);
|
||||||
|
|
||||||
void CreateEducation(EducationDataModel educationDataModel);
|
void CreateEducation(EducationDataModel educationDataModel);
|
||||||
void UpdateEducation(EducationDataModel educationDataModel);
|
void UpdateEducation(EducationDataModel educationDataModel);
|
||||||
|
|||||||
@@ -1,26 +1,27 @@
|
|||||||
|
using UniversityAllExpelled_Models.DataModels;
|
||||||
using UniversityAllExpelled_Models.DataModels;
|
|
||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Models.BusinessLogicContracts;
|
namespace UniversityAllExpelled_Models.BusinessLogicContracts;
|
||||||
|
|
||||||
interface ILessonBusinessLogicContract
|
public interface ILessonBusinessLogicContract
|
||||||
{
|
{
|
||||||
List<LessonDataModel> GetAllLesson();
|
List<LessonDataModel> GetAllLessons();
|
||||||
List<LessonDataModel> GetAllLessonByActive(bool isActive);
|
List<LessonDataModel> GetLessonsByStatus(bool isActive);
|
||||||
|
List<LessonDataModel> GetLessonsByPeriod(DateTime startDate, DateTime endDate);
|
||||||
|
|
||||||
LessonDataModel? GetLessonByName(string lessonName);
|
LessonDataModel? GetLessonByName(string lessonName);
|
||||||
LessonDataModel? GetLessonByNameByActive(string lessonName, bool isActive);
|
LessonDataModel? GetLessonByNameAndStatus(string lessonName, bool isActive);
|
||||||
|
|
||||||
List<LessonDataModel> GetAllLessonByPeriod(DateTime startDate, DateTime endDate);
|
List<LessonDataModel> GetLessonsByStudentAndPeriod(string studentId, DateTime startDate, DateTime endDate);
|
||||||
|
List<LessonDataModel> GetLessonsByStudentAndPeriodAndStatus(string studentId, DateTime startDate, DateTime endDate, bool isActive);
|
||||||
|
LessonDataModel? GetLessonByNameAndStudentAndStatus(string lessonName, string studentId, bool isActive);
|
||||||
|
|
||||||
//Client часть
|
List<LessonDataModel> GetLessonsByEducationId(string educationId);
|
||||||
List<LessonDataModel> GetAllLessonByPeriodByStudent(string studentId,DateTime startDate, DateTime endDate);
|
List<LessonDataModel> GetLessonsByEducationAndPeriod(string educationId, DateTime startDate, DateTime endDate);
|
||||||
List<LessonDataModel> GetAllLessonByPeriodByStudentByActive(string studentId, DateTime startDate, DateTime endDate, bool isActive);
|
List<LessonDataModel> GetLessonsByEducationAndDate(string educationId, DateTime date);
|
||||||
LessonDataModel? GetLessonByNameByStudentByActive(string lessonName,string studentId, bool isActive);
|
List<LessonDataModel> GetLessonsByEducationAndTeacher(string educationId, string teacherId);
|
||||||
|
|
||||||
|
void AddLesson(LessonDataModel lessonDataModel);
|
||||||
void CreateLesson(LessonDataModel lessonDataModel);
|
|
||||||
void UpdateLesson(LessonDataModel lessonDataModel);
|
void UpdateLesson(LessonDataModel lessonDataModel);
|
||||||
void RestoreLesson(string Id);
|
void RestoreLesson(string id);
|
||||||
void DeleteLesson(string id);
|
void DeleteLesson(string id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,25 @@
|
|||||||
|
using UniversityAllExpelled_Models.DataModels.Client;
|
||||||
|
|
||||||
using UniversityAllExpelled_Models.DataModels;
|
|
||||||
using UniversityAllExpelled_Models.DataModels.Client;
|
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Models.BusinessLogicContracts;
|
namespace UniversityAllExpelled_Models.BusinessLogicContracts;
|
||||||
|
|
||||||
interface IPaymentBusinessLogicContract
|
public interface IPaymentBusinessLogicContract
|
||||||
{
|
{
|
||||||
List<PaymentDataModel> GetAllPayment();
|
List<PaymentDataModel> GetAllPayments();
|
||||||
List<PaymentDataModel> GetAllPaymentByPaidOfState(bool paidOf);
|
PaymentDataModel? GetPaymentById(string id);
|
||||||
List<PaymentDataModel> GetAllPaymentByPeriod(DateTime startDate, DateTime endDate);
|
|
||||||
List<PaymentDataModel> GetAllPaymentByPeriodByPaidOfState(DateTime startDate, DateTime endDate, bool paidOf);
|
|
||||||
List<PaymentDataModel> GetAllPaymentByStudetnByPeriod(string studentId, DateTime startDate, DateTime endDate);
|
|
||||||
List<PaymentDataModel> GetAllPaymentByStudetnByPaidOfState(string studentId, bool paidOf);
|
|
||||||
List<PaymentDataModel> GetAllPaymentByStudetnByPeriodByPaidOfState(string studentId, DateTime startDate, DateTime endDate, bool paidOf);
|
|
||||||
|
|
||||||
PaymentDataModel? GetPaymentByData(string data);
|
List<PaymentDataModel> GetPaymentsByStatus(bool isPaid);
|
||||||
|
List<PaymentDataModel> GetPaymentsByPeriod(DateTime startDate, DateTime endDate);
|
||||||
|
List<PaymentDataModel> GetPaymentsByPeriodAndStatus(DateTime startDate, DateTime endDate, bool isPaid);
|
||||||
|
|
||||||
void InsertPayment(PaymentDataModel paymentDataModel);
|
List<PaymentDataModel> GetPaymentsByStudentId(string studentId);
|
||||||
void CanselPayment(string id);
|
List<PaymentDataModel> GetPaymentsByStudentAndPeriod(string studentId, DateTime startDate, DateTime endDate);
|
||||||
|
List<PaymentDataModel> GetPaymentsByStudentAndStatus(string studentId, bool isPaid);
|
||||||
|
List<PaymentDataModel> GetPaymentsByStudentAndPeriodAndStatus(string studentId, DateTime startDate, DateTime endDate, bool isPaid);
|
||||||
|
|
||||||
|
double CalculatePaidAmountByEducation(string educationId);
|
||||||
|
double CalculateDebtByEducation(string educationId);
|
||||||
|
|
||||||
|
void AddPayment(PaymentDataModel model);
|
||||||
|
void UpdatePayment(PaymentDataModel model);
|
||||||
|
void DeletePayment(string id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,14 @@
|
|||||||
using System.Data;
|
using UniversityAllExpelled_Models.DataModels.Client;
|
||||||
|
|
||||||
using UniversityAllExpelled_Models.DataModels.Client;
|
|
||||||
using UniversityAllExpelled_Models.Enums;
|
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Models.BusinessLogicContracts;
|
namespace UniversityAllExpelled_Models.BusinessLogicContracts;
|
||||||
|
|
||||||
interface IStudentBusinessLogicContract
|
public interface IStudentBusinessLogicContract
|
||||||
{
|
{
|
||||||
List<StudentDataModel> GetAllStudents(SystemRoleType role = SystemRoleType.student ,bool IsDeleted = false);
|
List<StudentDataModel> GetAllStudents();
|
||||||
List<StudentDataModel> GetAllStudentsByBirthDate(DateTime startDate, DateTime endDate,
|
StudentDataModel? GetStudentById(string id);
|
||||||
SystemRoleType role = SystemRoleType.student, bool IsDeleted = false);
|
StudentDataModel? GetStudentByUserId(string userId);
|
||||||
List<StudentDataModel> GetAllStudentsByFaculty( FacultyType faculty,SystemRoleType role = SystemRoleType.student, bool IsDeleted = false);
|
List<StudentDataModel> GetListByCourse(int course);
|
||||||
List<StudentDataModel> GetAllStudentsByGroopType(GroopType groop, SystemRoleType role = SystemRoleType.student, bool IsDeleted = false);
|
|
||||||
List<StudentDataModel> GetAllStudentsByCource(int Cource, SystemRoleType role = SystemRoleType.student, bool IsDeleted = false);
|
|
||||||
StudentDataModel? GetStudentByData(string data,SystemRoleType role = SystemRoleType.student, bool IsDeleted = false);
|
|
||||||
|
|
||||||
void InsertStudent(StudentDataModel studentDataModel);
|
void AddStudent(StudentDataModel model);
|
||||||
void UpdateStudent(StudentDataModel studentDataModel);
|
void UpdateStudent(StudentDataModel model);
|
||||||
void RestoreStudent(string Id);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,17 +12,9 @@ interface ITeacherBusinessLogicContract
|
|||||||
List<TeacherDataModel> GetAllTeachers();
|
List<TeacherDataModel> GetAllTeachers();
|
||||||
TeacherDataModel? GetTeacherById(string teacherId);
|
TeacherDataModel? GetTeacherById(string teacherId);
|
||||||
TeacherDataModel? GetTeacherByUserId(string userId);
|
TeacherDataModel? GetTeacherByUserId(string userId);
|
||||||
|
|
||||||
List<TeacherDataModel> GetTeachersByPosition(TeacherPositionType position);
|
|
||||||
List<TeacherDataModel> GetTeachersByPositions(IEnumerable<TeacherPositionType> positions);
|
|
||||||
|
|
||||||
List<TeacherDataModel> GetTeachersHiredAfterDate(DateTime date);
|
List<TeacherDataModel> GetTeachersHiredAfterDate(DateTime date);
|
||||||
List<TeacherDataModel> GetTeachersHiredBeforeDate(DateTime date);
|
List<TeacherDataModel> GetTeachersHiredBeforeDate(DateTime date);
|
||||||
List<TeacherDataModel> GetTeachersHiredBetweenDates(DateTime startDate, DateTime endDate);
|
List<TeacherDataModel> GetTeachersHiredBetweenDates(DateTime startDate, DateTime endDate);
|
||||||
|
|
||||||
List<TeacherDataModel> GetTeachersByPositionAndHireDate(TeacherPositionType position, DateTime startDate, DateTime endDate);
|
|
||||||
|
|
||||||
int GetTeacherCount();
|
int GetTeacherCount();
|
||||||
int GetTeacherCountByPosition(TeacherPositionType position);
|
|
||||||
Dictionary<TeacherPositionType, int> GetTeacherPositionDistribution();
|
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,21 @@
|
|||||||
|
using UniversityAllExpelled_Models.DataModels;
|
||||||
using UniversityAllExpelled_Models.DataModels;
|
|
||||||
|
|
||||||
|
namespace UniversityAllExpelled_Models.BusinessLogicContracts
|
||||||
namespace UniversityAllExpelled_Models.BusinessLogicContracts;
|
|
||||||
|
|
||||||
interface IUserBusinessLogicContract
|
|
||||||
{
|
{
|
||||||
|
public interface IUserBusinessLogicContract
|
||||||
|
{
|
||||||
List<UserDataModel> GetAllUsers();
|
List<UserDataModel> GetAllUsers();
|
||||||
List<UserDataModel> GetAllActiveUsers(bool IsDeleted = false);
|
List<UserDataModel> GetAllActiveUsers(bool isDeleted = false);
|
||||||
List<UserDataModel> GetAllUserByBirthDate(DateTime fromDate, DateTime toDate, bool IsDeleted = false);
|
List<UserDataModel> GetAllUsersByBirthDate(DateTime fromDate, DateTime toDate, bool isDeleted = false);
|
||||||
UserDataModel GetUserByData(string data);
|
UserDataModel? GetUserByLogin(string login);
|
||||||
|
|
||||||
void InsertUser(UserDataModel userDataModel);
|
void InsertUser(UserDataModel userDataModel);
|
||||||
void UpdateUser(UserDataModel userDataModel);
|
void UpdateUser(UserDataModel userDataModel);
|
||||||
void RestoreUser(string Id);
|
void RestoreUser(string id);
|
||||||
void DeleteUser(string id);
|
void DeleteUser(string id);
|
||||||
|
|
||||||
|
// Дополнительно
|
||||||
|
UserDataModel Register(string login, string password, string email, string phone, string fio, DateTime birthDate, string role);
|
||||||
|
UserDataModel? Authorize(string login, string password);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
using UniversityAllExpelled_Models.Extensions;
|
using UniversityAllExpelled_Models.Extensions;
|
||||||
using UniversityAllExpelled_Models.Infrastructure;
|
using UniversityAllExpelled_Models.Infrastructure;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Models.DataModels.Worker;
|
namespace UniversityAllExpelled_Models.DataModels;
|
||||||
|
|
||||||
public class LessonDataModel(string id, string name, double price, DateTime startDate, DateTime endDate, string studentId, string salaryId, bool isActive) : IValidation
|
public class LessonDataModel(string id, string name, double price, DateTime startDate, DateTime endDate, string studentId, string salaryId, bool isActive) : IValidation
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,24 +1,17 @@
|
|||||||
using UniversityAllExpelled_Models.Exceptions;
|
using UniversityAllExpelled_Models.Exceptions;
|
||||||
using UniversityAllExpelled_Models.Infrastructure;
|
using UniversityAllExpelled_Models.Infrastructure;
|
||||||
|
|
||||||
public class EducationDataModel : IValidation
|
namespace UniversityAllExpelled_Models.DataModels.Worker
|
||||||
{
|
{
|
||||||
public virtual string Id { get; set; }
|
public class EducationDataModel(string id, string teacherId, float amount, DateTime startDate, DateTime endDate, bool active) : IValidation
|
||||||
public virtual string TeacherId { get; set; }
|
|
||||||
public virtual float Amount { get; set; }
|
|
||||||
public virtual DateTime StartDate { get; set; }
|
|
||||||
public virtual DateTime EndDate { get; set; }
|
|
||||||
public virtual bool Active { get; set; }
|
|
||||||
|
|
||||||
public EducationDataModel(string id, string teacherId, float amount, DateTime startDate, DateTime endDate, bool active)
|
|
||||||
{
|
{
|
||||||
Id = id;
|
public virtual string Id { get; set; } = id;
|
||||||
TeacherId = teacherId;
|
public virtual string TeacherId { get; set; } = teacherId;
|
||||||
Amount = amount;
|
public virtual float Amount { get; set; } = amount;
|
||||||
StartDate = startDate;
|
public virtual DateTime StartDate { get; set; } = startDate;
|
||||||
EndDate = endDate;
|
public virtual DateTime EndDate { get; set; } = endDate;
|
||||||
Active = active;
|
public virtual bool Active { get; set; } = active;
|
||||||
}
|
public virtual List<EducationLessonsDataModel>? EducationLessons { get; set; }
|
||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
{
|
{
|
||||||
@@ -46,4 +39,5 @@ public class EducationDataModel : IValidation
|
|||||||
if (StartDate > EndDate)
|
if (StartDate > EndDate)
|
||||||
throw new ValidationException("Start date cannot be after end date");
|
throw new ValidationException("Start date cannot be after end date");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,10 @@ using UniversityAllExpelled_Models.Infrastructure;
|
|||||||
|
|
||||||
namespace UniversityAllExpelled_Models.DataModels.Worker;
|
namespace UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
|
|
||||||
public class EducationLessonsDataModel(string educationId, string lessonsId) : IValidation
|
public class EducationLessonsDataModel(string educationId, string lessonId) : IValidation
|
||||||
{
|
{
|
||||||
public virtual string EducationId { get; set; } = educationId;
|
public virtual string EducationId { get; set; } = educationId;
|
||||||
public virtual string LessonsId { get; set; } = lessonsId;
|
public virtual string LessonId { get; set; } = lessonId;
|
||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
{
|
{
|
||||||
@@ -17,10 +17,10 @@ public class EducationLessonsDataModel(string educationId, string lessonsId) : I
|
|||||||
if (!EducationId.IsGuid())
|
if (!EducationId.IsGuid())
|
||||||
throw new ValidationException("Education ID must be in valid GUID format");
|
throw new ValidationException("Education ID must be in valid GUID format");
|
||||||
|
|
||||||
if (LessonsId.IsEmpty())
|
if (LessonId.IsEmpty())
|
||||||
throw new ValidationException("Lesson ID cannot be empty");
|
throw new ValidationException("Lesson ID cannot be empty");
|
||||||
|
|
||||||
if (!LessonsId.IsGuid())
|
if (!LessonId.IsGuid())
|
||||||
throw new ValidationException("Lesson ID must be in valid GUID format");
|
throw new ValidationException("Lesson ID must be in valid GUID format");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ namespace UniversityAllExpelled_Models.StorageContracts
|
|||||||
public List<EducationDataModel> GetAllEducationByLessons();
|
public List<EducationDataModel> GetAllEducationByLessons();
|
||||||
void AddElement(EducationDataModel educationDataModel);
|
void AddElement(EducationDataModel educationDataModel);
|
||||||
void UpdElement(EducationDataModel educationDataModel);
|
void UpdElement(EducationDataModel educationDataModel);
|
||||||
void DelElement(EducationDataModel educationDataModel);
|
void DelElement(string id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels;
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Models.StorageContracts;
|
namespace UniversityAllExpelled_Models.StorageContracts;
|
||||||
|
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ public interface IStudentStorageContract
|
|||||||
StudentDataModel? GetElementByUserId(string userId);
|
StudentDataModel? GetElementByUserId(string userId);
|
||||||
List<StudentDataModel>? GetListByCourse(int course);
|
List<StudentDataModel>? GetListByCourse(int course);
|
||||||
void AddElement(StudentDataModel model);
|
void AddElement(StudentDataModel model);
|
||||||
void UpdElement(StudentDataModel model);
|
void UpdateElement(StudentDataModel model);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
using UniversityAllExpelled_Models.DataModels.Worker;
|
using UniversityAllExpelled_Models.DataModels.Worker;
|
||||||
using UniversityAllExpelled_Models.Enums;
|
|
||||||
|
|
||||||
namespace UniversityAllExpelled_Models.StorageContracts
|
namespace UniversityAllExpelled_Models.StorageContracts;
|
||||||
|
|
||||||
|
public interface ITeacherStorageContract
|
||||||
{
|
{
|
||||||
public interface ITeacherStorageContract
|
|
||||||
{
|
|
||||||
List<TeacherDataModel> GetList();
|
List<TeacherDataModel> GetList();
|
||||||
TeacherDataModel? GetElementById(string id);
|
TeacherDataModel? GetElementById(string id);
|
||||||
TeacherDataModel? GetElementByUserId(string userId);
|
TeacherDataModel? GetElementByUserId(string userId);
|
||||||
List<TeacherDataModel>? GetListByPosition(TeacherPositionType position);
|
List<TeacherDataModel> GetListByHireDateRange(DateTime startDate, DateTime endDate);
|
||||||
List<TeacherDataModel>? GetListByHireDateRange(DateTime startDate, DateTime endDate);
|
|
||||||
void AddElement(TeacherDataModel teacherDataModel);
|
void AddElement(TeacherDataModel teacherDataModel);
|
||||||
void UpdElement(TeacherDataModel teacherDataModel);
|
void UpdElement(TeacherDataModel teacherDataModel);
|
||||||
void DelElement(TeacherDataModel teacherDataModel);
|
void DelElement(TeacherDataModel teacherDataModel);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
public class EducationLessonsViewModel
|
namespace UniversityAllExpelled_Models.ViewModels
|
||||||
{
|
{
|
||||||
|
public class EducationLessonsViewModel
|
||||||
|
{
|
||||||
public string EducationId { get; set; } = default!;
|
public string EducationId { get; set; } = default!;
|
||||||
public string LessonsId { get; set; } = default!;
|
public string LessonId { get; set; } = default!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
public class EducationViewModel
|
namespace UniversityAllExpelled_Models.ViewModels
|
||||||
{
|
{
|
||||||
|
public class EducationViewModel
|
||||||
|
{
|
||||||
public string Id { get; set; } = default!;
|
public string Id { get; set; } = default!;
|
||||||
public string TeacherId { get; set; } = default!;
|
public string TeacherId { get; set; } = default!;
|
||||||
public float Amount { get; set; }
|
public float Amount { get; set; }
|
||||||
public DateTime StartDate { get; set; }
|
public DateTime StartDate { get; set; }
|
||||||
public DateTime EndDate { get; set; }
|
public DateTime EndDate { get; set; }
|
||||||
public bool Active { get; set; }
|
public bool Active { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
public class LessonViewModel
|
namespace UniversityAllExpelled_Models.ViewModels
|
||||||
{
|
{
|
||||||
|
public class LessonViewModel
|
||||||
|
{
|
||||||
public string Id { get; set; } = default!;
|
public string Id { get; set; } = default!;
|
||||||
public string Name { get; set; } = default!;
|
public string Name { get; set; } = default!;
|
||||||
public double Price { get; set; }
|
public double Price { get; set; }
|
||||||
@@ -8,4 +10,5 @@
|
|||||||
public string StudentId { get; set; } = default!;
|
public string StudentId { get; set; } = default!;
|
||||||
public string SalaryId { get; set; } = default!;
|
public string SalaryId { get; set; } = default!;
|
||||||
public bool IsActive { get; set; }
|
public bool IsActive { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
public class ReportViewModel
|
namespace UniversityAllExpelled_Models.ViewModels
|
||||||
{
|
{
|
||||||
|
public class ReportViewModel
|
||||||
|
{
|
||||||
public string EducationId { get; set; } = default!;
|
public string EducationId { get; set; } = default!;
|
||||||
public DateTime From { get; set; }
|
public DateTime From { get; set; }
|
||||||
public DateTime To { get; set; }
|
public DateTime To { get; set; }
|
||||||
public bool IncludeLessons { get; set; } = false;
|
public bool IncludeLessons { get; set; } = false;
|
||||||
public bool IncludeSalaries { get; set; } = false;
|
public bool IncludeSalaries { get; set; } = false;
|
||||||
public bool GenerateExcel { get; set; } = false;
|
public bool GenerateExcel { get; set; } = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
public class SalaryViewModel
|
namespace UniversityAllExpelled_Models.ViewModels
|
||||||
{
|
{
|
||||||
|
public class SalaryViewModel
|
||||||
|
{
|
||||||
public string Id { get; set; } = default!;
|
public string Id { get; set; } = default!;
|
||||||
public string TeacherId { get; set; } = default!;
|
public string TeacherId { get; set; } = default!;
|
||||||
public double Count { get; set; }
|
public double Count { get; set; }
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
public class TeacherViewModel
|
namespace UniversityAllExpelled_Models.ViewModels
|
||||||
{
|
{
|
||||||
|
public class TeacherViewModel
|
||||||
|
{
|
||||||
public string Id { get; set; } = default!;
|
public string Id { get; set; } = default!;
|
||||||
public string UserId { get; set; } = default!;
|
public string UserId { get; set; } = default!;
|
||||||
public DateTime DateHiring { get; set; }
|
public DateTime DateHiring { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,83 +2,10 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using UniversityAllExpelled_DataBase;
|
using UniversityAllExpelled_DataBase;
|
||||||
using UniversityAllExpelled_DataBase.Models;
|
|
||||||
using UniversityAllExpelled_Models.DTOs;
|
|
||||||
using UniversityAllExpelled_WebApi.Services;
|
|
||||||
|
|
||||||
namespace UniversityAllExpelled_WebApi.Controllers;
|
namespace UniversityAllExpelled_WebApi.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/user")]
|
[Route("api/user")]
|
||||||
public class UserController : ControllerBase
|
public class UserController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IUniversityDbContext _context;
|
|
||||||
private readonly ITokenService _tokenService;
|
|
||||||
|
|
||||||
public UserController(IUniversityDbContext context, ITokenService tokenService)
|
|
||||||
{
|
|
||||||
_context = context;
|
|
||||||
_tokenService = tokenService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Авторизация пользователя
|
|
||||||
/// </summary>
|
|
||||||
[HttpPost("login")]
|
|
||||||
public IActionResult Login([FromBody] LoginRequest request)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(request.Login) || string.IsNullOrWhiteSpace(request.Password))
|
|
||||||
return BadRequest(new { message = "Поля логина и пароля обязательны" });
|
|
||||||
|
|
||||||
var user = _context.Users
|
|
||||||
.FirstOrDefault(u => u.Login == request.Login && u.Password == request.Password && !u.IsDeleted);
|
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
return Unauthorized(new { message = "Неверный логин или пароль" });
|
|
||||||
|
|
||||||
var token = _tokenService.GenerateToken(user);
|
|
||||||
|
|
||||||
return Ok(new
|
|
||||||
{
|
|
||||||
access_token = token,
|
|
||||||
user = new
|
|
||||||
{
|
|
||||||
id = user.Id,
|
|
||||||
fio = user.FIO,
|
|
||||||
email = user.Email,
|
|
||||||
login = user.Login,
|
|
||||||
phoneNomber = user.PhoneNomber,
|
|
||||||
birthDate = user.BirthDate,
|
|
||||||
role = user.Role.ToString().ToLower()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получить профиль текущего пользователя
|
|
||||||
/// </summary>
|
|
||||||
[HttpGet("profile")]
|
|
||||||
[Authorize]
|
|
||||||
public IActionResult GetProfile()
|
|
||||||
{
|
|
||||||
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(userId))
|
|
||||||
return Unauthorized();
|
|
||||||
|
|
||||||
var user = _context.Users.FirstOrDefault(u => u.Id == userId);
|
|
||||||
if (user == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
return Ok(new
|
|
||||||
{
|
|
||||||
id = user.Id,
|
|
||||||
fio = user.FIO,
|
|
||||||
email = user.Email,
|
|
||||||
login = user.Login,
|
|
||||||
phoneNomber = user.PhoneNomber,
|
|
||||||
birthDate = user.BirthDate,
|
|
||||||
role = user.Role.ToString().ToLower()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
using System.IdentityModel.Tokens.Jwt;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Text;
|
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using System.Text;
|
||||||
using UniversityAllExpelled_BusinessLogic.Implementations;
|
using UniversityAllExpelled_BusinessLogic.Implementations;
|
||||||
|
using UniversityAllExpelled_Database;
|
||||||
using UniversityAllExpelled_Database.Implementations;
|
using UniversityAllExpelled_Database.Implementations;
|
||||||
using UniversityAllExpelled_DataBase;
|
using UniversityAllExpelled_DataBase;
|
||||||
using UniversityAllExpelled_DataBase.Implementations;
|
using UniversityAllExpelled_DataBase.Implementations;
|
||||||
@@ -71,7 +70,7 @@ var app = builder.Build();
|
|||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.UseDefaultFiles();
|
app.UseDefaultFiles();
|
||||||
app.UseStaticFiles(); // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> wwwroot
|
app.UseStaticFiles(); // wwwroot
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
<!-- createEduLes.html -->
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ru">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Создание урока</title>
|
|
||||||
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
|
||||||
<link href="/css/edu-create.css" rel="stylesheet">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="dashboard-layout">
|
|
||||||
<!-- Боковая панель -->
|
|
||||||
<aside class="sidebar">
|
|
||||||
<div class="logo-section">
|
|
||||||
<img src="/image/logo.png" alt="Логотип" class="main-logo">
|
|
||||||
</div>
|
|
||||||
<button class="back-button" onclick="location.href='/mainLK.html'">← Назад</button>
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<!-- Основной контент -->
|
|
||||||
<main class="form-content">
|
|
||||||
<h1>Создание предмета</h1>
|
|
||||||
<form id="lessonForm">
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="lessonTitle">Название предмета</label>
|
|
||||||
<input type="text" class="form-control" id="lessonTitle" placeholder="Введите название" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="lessonDescription">Описание</label>
|
|
||||||
<textarea class="form-control" id="lessonDescription" rows="4" placeholder="Введите описание"></textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="lessonDate">Дата проведения</label>
|
|
||||||
<input type="date" class="form-control" id="lessonDate" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="lessonTime">Время</label>
|
|
||||||
<input type="time" class="form-control" id="lessonTime" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="lessonGroup">Группа</label>
|
|
||||||
<select id="lessonGroup" class="form-control">
|
|
||||||
<option value="">Выберите группу</option>
|
|
||||||
<option value="PIbd-31">ПИбд-31</option>
|
|
||||||
<option value="PIbd-32">ПИбд-32</option>
|
|
||||||
<!-- можно добавить динамически -->
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary">Создать предмет</button>
|
|
||||||
</form>
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<!-- createStudentTraining.html -->
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ru">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Создание обучения</title>
|
|
||||||
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
|
||||||
<link rel="stylesheet" href="/css/edu-create.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="dashboard-layout">
|
|
||||||
<!-- Боковая панель -->
|
|
||||||
<aside class="sidebar">
|
|
||||||
<div class="logo-section">
|
|
||||||
<img src="/image/logo.png" alt="Логотип" class="main-logo">
|
|
||||||
</div>
|
|
||||||
<button class="back-button" onclick="location.href='/mainLK.html'">← Назад</button>
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<!-- Основной контент -->
|
|
||||||
<main class="form-content">
|
|
||||||
<h1>Создание обучения</h1>
|
|
||||||
<form id="trainingForm">
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="trainingTitle">Название курса</label>
|
|
||||||
<input type="text" class="form-control" id="trainingTitle" placeholder="Например, JavaScript для начинающих" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="trainingType">Тип курса</label>
|
|
||||||
<select id="trainingType" class="form-control" required>
|
|
||||||
<option value="">Выберите направление</option>
|
|
||||||
<option value="it">IT</option>
|
|
||||||
<option value="design">Дизайн</option>
|
|
||||||
<option value="business">Бизнес</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="trainingGoal">Цель обучения</label>
|
|
||||||
<textarea class="form-control" id="trainingGoal" rows="3" placeholder="Например, освоить основы JS"></textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="preferredTeacher">Желаемый преподаватель</label>
|
|
||||||
<input type="text" class="form-control" id="preferredTeacher" placeholder="ФИО (по желанию)">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" class="btn btn-success">Отправить заявку</button>
|
|
||||||
</form>
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -4,68 +4,41 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>Личный кабинет</title>
|
<title>Личный кабинет</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="/css/bootstrap.min.css" rel="stylesheet" />
|
||||||
<link href="/css/lk.css" rel="stylesheet" />
|
<link href="/css/lk.css" rel="stylesheet" />
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css" rel="stylesheet" />
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css" rel="stylesheet" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="dashboard-layout">
|
<div class="dashboard-layout">
|
||||||
<!-- Боковая панель -->
|
|
||||||
<aside class="sidebar">
|
<aside class="sidebar">
|
||||||
<div class="logo-section">
|
<div class="logo-section">
|
||||||
<img src="/image/logo.png" alt="Логотип УГУ" class="main-logo" />
|
<img src="/image/logo.png" alt="Логотип" class="main-logo" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="user-info">
|
<div class="user-info">
|
||||||
<h4 id="userName"></h4>
|
<h4 id="userName"></h4>
|
||||||
<p id="userRole"></p>
|
<p id="userRole"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nav-container">
|
<div class="nav-container">
|
||||||
<button class="nav-button active" data-section="profile">
|
<button class="nav-button active" data-section="profile"><i class="bi bi-person"></i> Профиль</button>
|
||||||
<i class="bi bi-person"></i> Профиль
|
<button class="nav-button" data-section="study" data-role="student"><i class="bi bi-journal-bookmark"></i> Обучение</button>
|
||||||
</button>
|
<button class="nav-button" data-section="payments" data-role="student"><i class="bi bi-credit-card"></i> Оплата</button>
|
||||||
|
<button class="nav-button" data-section="teaching" data-role="teacher"><i class="bi bi-mortarboard"></i> Преподавание</button>
|
||||||
<!-- Для студентов -->
|
<button class="nav-button" data-section="reports" data-role="teacher"><i class="bi bi-graph-up"></i> Отчеты</button>
|
||||||
<button class="nav-button" data-section="study" data-role="student">
|
<button class="nav-button" id="logoutBtn"><i class="bi bi-box-arrow-right"></i> Выход</button>
|
||||||
<i class="bi bi-journal-bookmark"></i> Обучение
|
|
||||||
</button>
|
|
||||||
<button class="nav-button" data-section="payments" data-role="student">
|
|
||||||
<i class="bi bi-credit-card"></i> Оплата
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<!-- Для преподавателей -->
|
|
||||||
<button class="nav-button" data-section="teaching" data-role="teacher">
|
|
||||||
<i class="bi bi-mortarboard"></i> Преподавание
|
|
||||||
</button>
|
|
||||||
<button class="nav-button" data-section="reports" data-role="teacher">
|
|
||||||
<i class="bi bi-graph-up"></i> Отчеты
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="nav-button" id="logoutBtn">
|
|
||||||
<i class="bi bi-box-arrow-right"></i> Выход
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<!-- Основной контент -->
|
|
||||||
<main class="student-info">
|
<main class="student-info">
|
||||||
<!-- Секция профиля -->
|
|
||||||
<div id="profileSection" class="content-section">
|
<div id="profileSection" class="content-section">
|
||||||
<h1>Личный профиль</h1>
|
<h1>Личный профиль</h1>
|
||||||
<div class="info-group">
|
<div class="info-group">
|
||||||
<p><strong>ФИО:</strong> <span id="userFio"></span></p>
|
<p><strong>ФИО:</strong> <span id="userFio"></span></p>
|
||||||
<p><strong>Email:</strong> <span id="userEmail"></span></p>
|
<p><strong>Email:</strong> <span id="userEmail"></span></p>
|
||||||
<p><strong>Телефон:</strong> <span id="userPhone"></span></p>
|
<p><strong>Телефон:</strong> <span id="userPhone"></span></p>
|
||||||
|
|
||||||
<!-- Для студентов -->
|
|
||||||
<div data-role="student">
|
<div data-role="student">
|
||||||
<p><strong>Факультет:</strong> <span id="studentFaculty"></span></p>
|
<p><strong>Факультет:</strong> <span id="studentFaculty"></span></p>
|
||||||
<p><strong>Группа:</strong> <span id="studentGroup"></span></p>
|
<p><strong>Группа:</strong> <span id="studentGroup"></span></p>
|
||||||
<p><strong>Курс:</strong> <span id="studentCourse"></span></p>
|
<p><strong>Курс:</strong> <span id="studentCourse"></span></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Для преподавателей -->
|
|
||||||
<div data-role="teacher">
|
<div data-role="teacher">
|
||||||
<p><strong>Должность:</strong> <span id="teacherPosition"></span></p>
|
<p><strong>Должность:</strong> <span id="teacherPosition"></span></p>
|
||||||
<p><strong>Дата приема:</strong> <span id="teacherHireDate"></span></p>
|
<p><strong>Дата приема:</strong> <span id="teacherHireDate"></span></p>
|
||||||
@@ -73,31 +46,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Секции для студентов -->
|
|
||||||
<div id="studySection" class="content-section" style="display:none;" data-role="student">
|
<div id="studySection" class="content-section" style="display:none;" data-role="student">
|
||||||
<h2>Учебная информация</h2>
|
<h2>Учебная информация</h2>
|
||||||
<div id="studyContent"></div>
|
<div id="studyContent"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="paymentsSection" class="content-section" style="display:none;" data-role="student">
|
<div id="paymentsSection" class="content-section" style="display:none;" data-role="student">
|
||||||
<h2>Финансовая информация</h2>
|
<h2>Финансовая информация</h2>
|
||||||
<div id="paymentsContent"></div>
|
<div id="paymentsContent"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Секции для преподавателей -->
|
|
||||||
<div id="teachingSection" class="content-section" style="display:none;" data-role="teacher">
|
<div id="teachingSection" class="content-section" style="display:none;" data-role="teacher">
|
||||||
<h2>Преподавательская деятельность</h2>
|
<h2>Преподавательская деятельность</h2>
|
||||||
<div id="teachingContent"></div>
|
<div id="teachingContent"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="reportsSection" class="content-section" style="display:none;" data-role="teacher">
|
<div id="reportsSection" class="content-section" style="display:none;" data-role="teacher">
|
||||||
<h2>Отчеты и аналитика</h2>
|
<h2>Отчеты и аналитика</h2>
|
||||||
<div id="reportsContent"></div>
|
<div id="reportsContent"></div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module" src="/js/main.js"></script>
|
<script type="module" src="/js/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
const role = localStorage.getItem("userRole"); // 'student' или 'teacher'
|
||||||
|
const userFio = localStorage.getItem("userFio") || "";
|
||||||
|
const userEmail = localStorage.getItem("userEmail") || "";
|
||||||
|
const userPhone = localStorage.getItem("userPhone") || "";
|
||||||
|
|
||||||
|
// Отображаем ФИО и роль
|
||||||
|
if (document.getElementById("userName")) {
|
||||||
|
document.getElementById("userName").textContent = userFio;
|
||||||
|
}
|
||||||
|
if (document.getElementById("userRole")) {
|
||||||
|
document.getElementById("userRole").textContent = role === "student" ? "Студент" : "Преподаватель";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Отображаем профиль
|
||||||
|
if (document.getElementById("userFio")) {
|
||||||
|
document.getElementById("userFio").textContent = userFio;
|
||||||
|
document.getElementById("userEmail").textContent = userEmail;
|
||||||
|
document.getElementById("userPhone").textContent = userPhone;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Отображаем только элементы текущей роли
|
||||||
|
document.querySelectorAll("[data-role]").forEach(el => {
|
||||||
|
el.style.display = el.getAttribute("data-role") === role ? "" : "none";
|
||||||
|
});
|
||||||
|
|
||||||
|
// Навигация по секциям
|
||||||
|
document.querySelectorAll(".nav-button").forEach(btn => {
|
||||||
|
btn.addEventListener("click", () => {
|
||||||
|
const sectionId = btn.dataset.section;
|
||||||
|
if (!sectionId) return;
|
||||||
|
|
||||||
|
document.querySelectorAll("main > div.content-section").forEach(sec => sec.style.display = "none");
|
||||||
|
const targetSection = document.getElementById(sectionId + "Section");
|
||||||
|
if (targetSection) targetSection.style.display = "";
|
||||||
|
|
||||||
|
document.querySelectorAll(".nav-button").forEach(b => b.classList.remove("active"));
|
||||||
|
btn.classList.add("active");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Обработка выхода
|
||||||
|
const logoutBtn = document.getElementById("logoutBtn");
|
||||||
|
if (logoutBtn) {
|
||||||
|
logoutBtn.addEventListener("click", () => {
|
||||||
|
localStorage.clear();
|
||||||
|
window.location.href = "/login.html";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,25 +1,24 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="ru">
|
<html lang="ru">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>УГУ - Вход в систему</title>
|
<title>УГУ - Вход</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="/css/bootstrap.min.css" rel="stylesheet" />
|
||||||
<link href="/css/site.css" rel="stylesheet">
|
<link href="/css/site.css" rel="stylesheet" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="page-layout">
|
<div class="page-layout">
|
||||||
<div class="logo-section">
|
<div class="logo-section">
|
||||||
<img src="/image/logo.png" alt="Логотип УГУ" class="main-logo">
|
<img src="/image/logo.png" alt="Логотип УГУ" class="main-logo" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="auth-container">
|
<div class="auth-container">
|
||||||
<div class="auth-box">
|
<div class="auth-box">
|
||||||
<h2>Вход</h2>
|
<h2>Вход</h2>
|
||||||
<form id="loginForm">
|
<form id="loginForm" class="auth-form">
|
||||||
<div id="errorMessage" class="alert alert-danger d-none"></div>
|
<div id="errorMessage" class="alert alert-danger d-none"></div>
|
||||||
<input type="text" id="loginInput" class="auth-input" placeholder="Логин" required>
|
<input type="text" id="loginInput" class="auth-input" placeholder="Логин" required />
|
||||||
<input type="password" id="passwordInput" class="auth-input" placeholder="Пароль" required>
|
<input type="password" id="passwordInput" class="auth-input" placeholder="Пароль" required />
|
||||||
<div class="auth-footer">
|
<div class="auth-footer">
|
||||||
<a href="/register.html" class="register-link">Регистрация</a>
|
<a href="/register.html" class="register-link">Регистрация</a>
|
||||||
<button type="submit" class="btn btn-primary login-btn">Войти</button>
|
<button type="submit" class="btn btn-primary login-btn">Войти</button>
|
||||||
@@ -28,7 +27,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module" src="/js/main.js"></script>
|
<script type="module" src="/js/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ru">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>Оплата обучения</title>
|
|
||||||
<link href="/css/payment.css" rel="stylesheet" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="payment-layout">
|
|
||||||
<!-- Боковая панель -->
|
|
||||||
<aside class="sidebar">
|
|
||||||
<div class="logo-section">
|
|
||||||
<img src="/image/logo.png" alt="Логотип" class="main-logo" />
|
|
||||||
</div>
|
|
||||||
<button class="back-button" onclick="location.href='/mainLK.html'">← На Главную</button>
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<!-- Основной контент -->
|
|
||||||
<main class="payment-content">
|
|
||||||
<h1 class="section-title">Оплата обучения</h1>
|
|
||||||
|
|
||||||
<div class="payment-info-box">
|
|
||||||
<p>
|
|
||||||
<strong>Обучение:</strong>
|
|
||||||
<select id="trainingSelect" class="payment-input" style="width: 100%; max-width: 400px; margin-bottom: 15px;">
|
|
||||||
<option value="" disabled selected>Выберите обучение</option>
|
|
||||||
<option value="programming">Программирование</option>
|
|
||||||
<option value="design">Дизайн</option>
|
|
||||||
<option value="marketing">Маркетинг</option>
|
|
||||||
</select>
|
|
||||||
</p>
|
|
||||||
<p><strong>Дата начала:</strong> <span id="startDate">none</span></p>
|
|
||||||
<p><strong>Дата окончания:</strong> <span id="endDate">none</span></p>
|
|
||||||
<p><strong>Цена:</strong> <span id="price">none</span></p>
|
|
||||||
<p><strong>Оплачено:</strong> <span id="paid">none</span></p>
|
|
||||||
<p><strong>Долг:</strong> <span id="debt">none</span></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="paymentForm" class="payment-form" style="display: none;">
|
|
||||||
<input type="number" id="amount" class="payment-input" placeholder="Сумма" />
|
|
||||||
<select id="paymentMethod" class="payment-input">
|
|
||||||
<option value="" disabled selected>Выберите способ оплаты</option>
|
|
||||||
<option value="sbp">СБП</option>
|
|
||||||
<option value="card">По номеру карты</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="cardDetails" style="display: none;">
|
|
||||||
<input type="text" class="payment-input" id="cardNumber" placeholder="Номер карты" />
|
|
||||||
<div class="card-row">
|
|
||||||
<input type="text" class="payment-input" id="cardExpiry" placeholder="MM/YY" />
|
|
||||||
<input type="text" class="payment-input" id="cardCSV" placeholder="CSV" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button id="payButton" class="pay-button">Оплатить</button>
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="/js/payment.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>Регистрация — УГУво</title>
|
<title>Регистрация — УГУ</title>
|
||||||
<link href="/css/bootstrap.min.css" rel="stylesheet" />
|
<link href="/css/bootstrap.min.css" rel="stylesheet" />
|
||||||
<link href="/css/site.css" rel="stylesheet" />
|
<link href="/css/site.css" rel="stylesheet" />
|
||||||
</head>
|
</head>
|
||||||
@@ -12,25 +12,21 @@
|
|||||||
<div class="logo-section">
|
<div class="logo-section">
|
||||||
<img src="/image/logo.png" alt="Логотип" class="main-logo" />
|
<img src="/image/logo.png" alt="Логотип" class="main-logo" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="auth-container">
|
<div class="auth-container">
|
||||||
<div class="auth-box">
|
<div class="auth-box">
|
||||||
<h2>Регистрация</h2>
|
<h2>Регистрация</h2>
|
||||||
|
|
||||||
<form id="registerForm" class="auth-form" novalidate>
|
<form id="registerForm" class="auth-form" novalidate>
|
||||||
<div class="role-switch">
|
<div class="role-switch">
|
||||||
<label><input type="radio" name="role" value="student" checked /> Студент</label>
|
<label><input type="radio" name="role" value="student" checked /> Студент</label>
|
||||||
<label><input type="radio" name="role" value="teacher" /> Преподаватель</label>
|
<label><input type="radio" name="role" value="teacher" /> Преподаватель</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="text" name="fio" class="auth-input" placeholder="ФИО" required />
|
<input type="text" name="fio" class="auth-input" placeholder="ФИО" required />
|
||||||
<input type="text" name="login" class="auth-input" placeholder="Логин" required />
|
<input type="text" name="login" class="auth-input" placeholder="Логин" required />
|
||||||
<input type="email" name="email" class="auth-input" placeholder="Электронная почта" required />
|
<input type="email" name="email" class="auth-input" placeholder="Email" required />
|
||||||
<input type="tel" name="phoneNomber" class="auth-input" placeholder="Телефон" required />
|
<input type="tel" name="phoneNomber" class="auth-input" placeholder="Телефон" required />
|
||||||
<input type="date" name="birthDate" class="auth-input" placeholder="Дата рождения" required />
|
<input type="date" name="birthDate" class="auth-input" placeholder="Дата рождения" required />
|
||||||
<input type="password" name="password" class="auth-input" placeholder="Пароль" required />
|
<input type="password" name="password" class="auth-input" placeholder="Пароль" required />
|
||||||
<input type="password" name="confirmPassword" class="auth-input" placeholder="Подтвердите пароль" required />
|
<input type="password" name="confirmPassword" class="auth-input" placeholder="Подтвердите пароль" required />
|
||||||
|
|
||||||
<div id="studentFields" class="additional-fields">
|
<div id="studentFields" class="additional-fields">
|
||||||
<select id="facultySelect" name="faculty" class="auth-input" required>
|
<select id="facultySelect" name="faculty" class="auth-input" required>
|
||||||
<option value="" disabled selected>Выберите факультет</option>
|
<option value="" disabled selected>Выберите факультет</option>
|
||||||
@@ -40,14 +36,12 @@
|
|||||||
</select>
|
</select>
|
||||||
<input type="number" id="courseInput" name="course" class="auth-input" placeholder="Курс" min="1" max="6" required />
|
<input type="number" id="courseInput" name="course" class="auth-input" placeholder="Курс" min="1" max="6" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="teacherFields" class="additional-fields" style="display:none;">
|
<div id="teacherFields" class="additional-fields" style="display:none;">
|
||||||
<select id="positionSelect" name="position" class="auth-input" required>
|
<select id="positionSelect" name="position" class="auth-input" required>
|
||||||
<option value="" disabled selected>Выберите должность</option>
|
<option value="" disabled selected>Выберите должность</option>
|
||||||
</select>
|
</select>
|
||||||
<input type="date" name="dateHiring" class="auth-input" placeholder="Дата приема на работу" required />
|
<input type="date" name="dateHiring" class="auth-input" placeholder="Дата приема на работу" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="auth-footer">
|
<div class="auth-footer">
|
||||||
<button type="submit" class="btn btn-primary login-btn">Зарегистрироваться</button>
|
<button type="submit" class="btn btn-primary login-btn">Зарегистрироваться</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -55,7 +49,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module" src="/js/main.js"></script>
|
<script type="module" src="/js/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ru">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Отчёты</title>
|
|
||||||
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
|
||||||
<link href="/css/reports.css" rel="stylesheet">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="reports-layout">
|
|
||||||
<!-- Боковая панель -->
|
|
||||||
<aside class="sidebar">
|
|
||||||
<div class="logo-section">
|
|
||||||
<img src="/image/logo.png" alt="Логотип" class="main-logo">
|
|
||||||
</div>
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<!-- Основной контент -->
|
|
||||||
<main class="reports-content">
|
|
||||||
<h1 class="section-title">Формирование отчетов</h1>
|
|
||||||
|
|
||||||
<div class="report-interface">
|
|
||||||
<label for="reportType">Выберите тип отчёта:</label>
|
|
||||||
<select id="reportType" class="report-select">
|
|
||||||
<option value="grades">Успеваемость</option>
|
|
||||||
<option value="payments">Оплаты</option>
|
|
||||||
<option value="attendance">Посещаемость</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<div class="date-range">
|
|
||||||
<label for="dateFrom">С:</label>
|
|
||||||
<input type="date" id="dateFrom" class="report-input">
|
|
||||||
|
|
||||||
<label for="dateTo">По:</label>
|
|
||||||
<input type="date" id="dateTo" class="report-input">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button class="generate-button" id="generateReport">Сформировать отчёт</button>
|
|
||||||
|
|
||||||
<div class="format-buttons hidden" id="formatButtons">
|
|
||||||
<button class="generate-button format-option">.DOC</button>
|
|
||||||
<button class="generate-button format-option">.XLS</button>
|
|
||||||
<button class="generate-button format-option">.PDF</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="/js/reports.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user