2024-04-21 19:12:38 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UniversityContracts.BindingModels;
|
|
|
|
|
using UniversityContracts.BusinessLogicsContracts;
|
|
|
|
|
using UniversityContracts.SearchModels;
|
|
|
|
|
using UniversityContracts.StorageContracts;
|
|
|
|
|
using UniversityContracts.ViewModels;
|
|
|
|
|
using UniversityDataModels.Enums;
|
|
|
|
|
|
|
|
|
|
namespace UniversityBusinessLogic.BusinessLogics
|
2024-04-25 17:00:45 +04:00
|
|
|
|
{
|
2024-04-21 19:12:38 +04:00
|
|
|
|
public class AttestationLogic : IAttestationLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IAttestationStorage _attestationStorage;
|
|
|
|
|
public AttestationLogic(ILogger<AttestationLogic> logger, IAttestationStorage
|
|
|
|
|
attestationStorage)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_attestationStorage = attestationStorage;
|
|
|
|
|
}
|
|
|
|
|
public List<AttestationViewModel>? ReadList(AttestationSearchModel? model)
|
|
|
|
|
{
|
2024-04-25 17:00:45 +04:00
|
|
|
|
_logger.LogInformation("ReadList.AttestationId:{Id} ",
|
|
|
|
|
model?.Id);
|
2024-04-21 19:12:38 +04:00
|
|
|
|
var list = model == null ? _attestationStorage.GetFullList() :
|
|
|
|
|
_attestationStorage.GetFilteredList(model);
|
|
|
|
|
if (list == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadList return null list");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
public AttestationViewModel? ReadElement(AttestationSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
2024-04-25 17:00:45 +04:00
|
|
|
|
_logger.LogInformation("ReadElement.Id:{Id}",
|
|
|
|
|
model.Id);
|
2024-04-21 19:12:38 +04:00
|
|
|
|
var element = _attestationStorage.GetElement(model);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadElement element not found");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
|
|
|
|
return element;
|
|
|
|
|
}
|
2024-04-25 17:00:45 +04:00
|
|
|
|
public bool CreateAttestation(AttestationBindingModel model)
|
2024-04-21 19:12:38 +04:00
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
|
|
|
|
|
model.Score = AttestationScore.Неявка;
|
|
|
|
|
|
|
|
|
|
if (_attestationStorage.Insert(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Insert operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-04-25 17:00:45 +04:00
|
|
|
|
public bool ScoreUpdate(AttestationBindingModel model, AttestationScore newScore)
|
2024-04-21 19:12:38 +04:00
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
2024-04-26 00:03:46 +04:00
|
|
|
|
|
|
|
|
|
if (!Enum.IsDefined(typeof(AttestationScore), newScore))
|
2024-04-21 19:12:38 +04:00
|
|
|
|
{
|
2024-04-26 00:03:46 +04:00
|
|
|
|
_logger.LogWarning("Score update to " + newScore.ToString() + " operation failed. Attestation status incorrect.");
|
2024-04-21 19:12:38 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_attestationStorage.Update(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Update operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 00:03:46 +04:00
|
|
|
|
model.Score = newScore;
|
2024-04-21 19:12:38 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-04-26 00:03:46 +04:00
|
|
|
|
public bool SetPass(AttestationBindingModel model)
|
2024-04-21 19:12:38 +04:00
|
|
|
|
{
|
2024-04-26 00:03:46 +04:00
|
|
|
|
return ScoreUpdate(model, AttestationScore.Зачёт);
|
2024-04-21 19:12:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 00:03:46 +04:00
|
|
|
|
public bool SetNotPass(AttestationBindingModel model)
|
2024-04-21 19:12:38 +04:00
|
|
|
|
{
|
2024-04-26 00:03:46 +04:00
|
|
|
|
return ScoreUpdate(model, AttestationScore.Незачёт);
|
2024-04-21 19:12:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 00:03:46 +04:00
|
|
|
|
public bool SetTwo(AttestationBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return ScoreUpdate(model, AttestationScore.Неудовлетворительно);
|
|
|
|
|
}
|
|
|
|
|
public bool SetThree(AttestationBindingModel model)
|
2024-04-21 19:12:38 +04:00
|
|
|
|
{
|
2024-04-26 00:03:46 +04:00
|
|
|
|
return ScoreUpdate(model, AttestationScore.Удовлетворительно);
|
|
|
|
|
}
|
|
|
|
|
public bool SetFour(AttestationBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return ScoreUpdate(model, AttestationScore.Хорошо);
|
|
|
|
|
}
|
|
|
|
|
public bool SetFive(AttestationBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return ScoreUpdate(model, AttestationScore.Отлично);
|
2024-04-21 19:12:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 00:03:46 +04:00
|
|
|
|
private void CheckModel(AttestationBindingModel model, bool withParams = true)
|
2024-04-21 19:12:38 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
if (!withParams)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-26 00:03:46 +04:00
|
|
|
|
if (string.IsNullOrEmpty(model.FormOfEvaluation))
|
2024-04-21 19:12:38 +04:00
|
|
|
|
{
|
2024-04-26 00:03:46 +04:00
|
|
|
|
throw new ArgumentNullException("Не выбрана форма оценивания", nameof(model.FormOfEvaluation));
|
2024-04-21 19:12:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 00:03:46 +04:00
|
|
|
|
if (model.StudentId <= 0)
|
2024-04-21 19:12:38 +04:00
|
|
|
|
{
|
2024-04-26 00:03:46 +04:00
|
|
|
|
throw new ArgumentNullException("Некорректный идентификатор студента", nameof(model.StudentId));
|
2024-04-21 19:12:38 +04:00
|
|
|
|
}
|
2024-04-26 00:03:46 +04:00
|
|
|
|
_logger.LogInformation("Attestation. AttestationId:{Id}.FormOfEvaluation:{FormOfEvaluation}. StudentId: { StudentId}",
|
|
|
|
|
model.Id, model.FormOfEvaluation, model.StudentId);
|
2024-04-21 19:12:38 +04:00
|
|
|
|
}
|
2024-04-25 17:00:45 +04:00
|
|
|
|
}
|
2024-04-21 19:12:38 +04:00
|
|
|
|
}
|