Реализовал логику пациентов
This commit is contained in:
parent
b6922e4815
commit
c65f745450
59
Medical/MedicalBusinessLogic/BusinessLogics/PatientLogic.cs
Normal file
59
Medical/MedicalBusinessLogic/BusinessLogics/PatientLogic.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using MedicalDatabaseContracts;
|
||||
using MedicalDatabaseContracts.Models;
|
||||
using MedicalDatabaseContracts.SearchModels;
|
||||
using MedicalDatabaseContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MedicalBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class PatientLogic : AbstractLogic<Patient, PatientViewModel, PatientSearchModel>
|
||||
{
|
||||
public PatientLogic(
|
||||
ILogger<AbstractLogic<Patient, PatientViewModel, PatientSearchModel>> logger,
|
||||
IStorage<Patient> storage) : base(logger, storage) { }
|
||||
|
||||
protected override bool CheckModelBySearchModel(Patient model, PatientSearchModel 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;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void CheckModelIsValid(Patient 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 PatientViewModel GetViewModel(Patient model)
|
||||
{
|
||||
return new PatientViewModel
|
||||
{
|
||||
Name = model.Name,
|
||||
Surname = model.Surname,
|
||||
Patronymic = model.Patronymic ?? string.Empty,
|
||||
PhoneNumber = model.PhoneNumber,
|
||||
Gender = model.Gender,
|
||||
Birthday = model.Birthday,
|
||||
Weight = model.Weight,
|
||||
Height = model.Height
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user