49 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using MedicalDatabaseContracts.SearchModels;
using MedicalDatabaseContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace MedicalBusinessLogic.BusinessLogics
{
public class DiagnoseLogic : AbstractLogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel>
{
public DiagnoseLogic(
ILogger<AbstractLogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel>> logger,
IStorage<Diagnose> storage) : base(logger, storage) { }
protected override bool CheckModelBySearchModel(Diagnose model, DiagnoseSearchModel searchModel)
{
if (searchModel.Id != null && searchModel.Id != model.Id)
return false;
if (!string.IsNullOrEmpty(searchModel.Name) && searchModel.Name != model.Name)
return false;
return true;
}
protected override void CheckModelIsValid(Diagnose model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
else if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException(nameof(model.Name));
}
else if (ReadList(new DiagnoseSearchModel { Name = model.Name }).Count != 0)
{
throw new InvalidOperationException($"Диагноз с таким названием уже есть: \"{model.Name}\"");
}
}
protected override DiagnoseViewModel GetViewModel(Diagnose model)
{
return new DiagnoseViewModel {
Id = model.Id,
Name = model.Name
};
}
}
}