Реализовал логику для врачей

This commit is contained in:
Никита Потапов 2024-05-15 01:48:41 +04:00
parent 4f354276e9
commit b6922e4815
2 changed files with 70 additions and 1 deletions

View File

@ -3,7 +3,6 @@ using MedicalDatabaseContracts.Models;
using MedicalDatabaseContracts.SearchModels;
using MedicalDatabaseContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System.Globalization;
namespace MedicalBusinessLogic.BusinessLogics
{

View File

@ -0,0 +1,70 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using MedicalDatabaseContracts.SearchModels;
using MedicalDatabaseContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace MedicalBusinessLogic.BusinessLogics
{
public class DoctorLogic : AbstractLogic<Doctor, DoctorViewModel, DoctorSearchModel>
{
private readonly IStorage<Specialization> _specializationStorage;
public DoctorLogic(
ILogger<AbstractLogic<Doctor, DoctorViewModel, DoctorSearchModel>> logger,
IStorage<Doctor> storage,
IStorage<Specialization> specializationStorage) : base(logger, storage)
{
_specializationStorage = specializationStorage;
}
protected override bool CheckModelBySearchModel(Doctor model, DoctorSearchModel searchModel)
{
if (searchModel.Id != null && searchModel.Id != model.Id)
return false;
if (!string.IsNullOrEmpty(searchModel.Name) && searchModel.Name != model.Name)
return false;
if (!string.IsNullOrEmpty(searchModel.Surname) && searchModel.Surname != model.Surname)
return false;
if (!string.IsNullOrEmpty(searchModel.Patronymic) && searchModel.Patronymic != model.Patronymic)
return false;
if (searchModel.SpecializationId != null && searchModel.SpecializationId != model.SpecializationId)
return false;
return true;
}
protected override void CheckModelIsValid(Doctor model)
{
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException(nameof(model.Name));
}
else if (string.IsNullOrEmpty(model.Surname))
{
throw new ArgumentNullException(nameof(model.Surname));
}
else if (string.IsNullOrEmpty(model.PhoneNumber))
{
throw new ArgumentNullException(nameof(model.PhoneNumber));
}
}
protected override DoctorViewModel GetViewModel(Doctor model)
{
var doctorViewModel = new DoctorViewModel {
Name = model.Name,
Surname = model.Surname,
Patronymic = model.Patronymic ?? string.Empty,
PhoneNumber = model.PhoneNumber,
SpecializationId = model.SpecializationId
};
var specialization = _specializationStorage.Get(model.SpecializationId);
if (specialization != null)
{
doctorViewModel.SpecializationName = specialization.Name;
}
return doctorViewModel;
}
}
}