Реализовал логику для врачей
This commit is contained in:
parent
4f354276e9
commit
b6922e4815
@ -3,7 +3,6 @@ using MedicalDatabaseContracts.Models;
|
|||||||
using MedicalDatabaseContracts.SearchModels;
|
using MedicalDatabaseContracts.SearchModels;
|
||||||
using MedicalDatabaseContracts.ViewModels;
|
using MedicalDatabaseContracts.ViewModels;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace MedicalBusinessLogic.BusinessLogics
|
namespace MedicalBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
|
70
Medical/MedicalBusinessLogic/BusinessLogics/DoctorLogic.cs
Normal file
70
Medical/MedicalBusinessLogic/BusinessLogics/DoctorLogic.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user