поручитель бизнес логика
This commit is contained in:
parent
7890d9ae71
commit
1190965599
@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryContracts.BusinessLogicContracts;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class DoctorLogic : IDoctorLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IDoctorStorage _doctorStorage;
|
||||
public DoctorLogic(ILogger<DoctorLogic> logger, IDoctorStorage doctorStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_doctorStorage = doctorStorage;
|
||||
}
|
||||
public List<DoctorViewModel>? ReadList(DoctorSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. DoctorFIO:{DoctorFIO}. Id:{ Id}", model?.DoctorFIO, model?.Id);
|
||||
var list = model == null ? _doctorStorage.GetFullList() : _doctorStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public DoctorViewModel? ReadElement(DoctorSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. DoctorFIO:{DoctorFIO}.Id:{ Id}", model.DoctorFIO, model.Id);
|
||||
var element = _doctorStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(DoctorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_doctorStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(DoctorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_doctorStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(DoctorBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_doctorStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(DoctorBindingModel model, bool withParams =
|
||||
true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.DoctorFIO))
|
||||
{
|
||||
throw new ArgumentNullException("Нет ФИО доктора",
|
||||
nameof(model.DoctorFIO));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет Login доктора",
|
||||
nameof(model.Login));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля доктора",
|
||||
nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("Doctor. DoctorFIO:{DoctorFIO}." +
|
||||
"Login:{ Login}. Password:{ Password}. Id: { Id} ", model.DoctorFIO, model.Login, model.Password, model.Id);
|
||||
var element = _doctorStorage.GetElement(new DoctorSearchModel
|
||||
{
|
||||
Login = model.Login,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Доктор с таким же логином уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryContracts.BusinessLogicContracts;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class DrugLogic : IDrugLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IDrugStorage _drugStorage;
|
||||
public DrugLogic(ILogger<DrugLogic> logger, IDrugStorage drugStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_drugStorage = drugStorage;
|
||||
}
|
||||
public List<DrugViewModel>? ReadList(DrugSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. DrugName:{DrugName}.Id:{ Id}", model?.DrugName, model?.Id);
|
||||
var list = model == null ? _drugStorage.GetFullList() : _drugStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public DrugViewModel? ReadElement(DrugSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. DrugName:{DrugName}.Id:{ Id}", model.DrugName, model.Id);
|
||||
var element = _drugStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(DrugBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_drugStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(DrugBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_drugStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(DrugBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_drugStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(DrugBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.DrugName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия лекарства", nameof(model.DrugName));
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Лекарств должно быть больше нуля", nameof(model.Count));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена лекарства должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("Drug. DrugName:{DrugName}.Count:{ Count}.Price:{ Price}. Id: { Id}", model.DrugName,model.Count, model.Price, model.Id);
|
||||
var element = _drugStorage.GetElement(new DrugSearchModel
|
||||
{
|
||||
DrugName = model.DrugName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Лекарство с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryContracts.BusinessLogicContracts;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
|
||||
|
||||
namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class MedicationLogic : IMedicationLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMedicationStorage _medicationStorage;
|
||||
public MedicationLogic(ILogger<MedicationLogic> logger, IMedicationStorage medicationStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_medicationStorage = medicationStorage;
|
||||
}
|
||||
public List<MedicationViewModel>? ReadList(MedicationSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. MedicationName:{MedicationName}.Id:{ Id}", model?.MedicationName, model?.Id);
|
||||
var list = model == null ? _medicationStorage.GetFullList() : _medicationStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public MedicationViewModel? ReadElement(MedicationSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. MedicationName:{MedicationName}.Id:{ Id}", model.MedicationName, model.Id);
|
||||
var element = _medicationStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(MedicationBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_medicationStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(MedicationBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_medicationStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(MedicationBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_medicationStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(MedicationBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.MedicationName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия медикамента",
|
||||
nameof(model.MedicationName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена медикамента должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("Medication. MedicationName:{MedicationName}.Price:{ Price}. Id: { Id}", model.MedicationName, model.Price, model.Id);
|
||||
var element = _medicationStorage.GetElement(new MedicationSearchModel
|
||||
{
|
||||
MedicationName = model.MedicationName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Медикамент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryContracts.BusinessLogicContracts;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
|
||||
namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ServiceLogic : IServiceLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IServiceStorage _serviceStorage;
|
||||
public ServiceLogic(ILogger<ServiceLogic> logger, IServiceStorage serviceStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceStorage = serviceStorage;
|
||||
}
|
||||
public List<ServiceViewModel>? ReadList(ServiceSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ServiceName:{ServiceName}.Id:{ Id}", model?.ServiceName, model?.Id);
|
||||
var list = model == null ? _serviceStorage.GetFullList() : _serviceStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public ServiceViewModel? ReadElement(ServiceSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ServiceName:{ServiceName}.Id:{ Id}", model.ServiceName, model.Id);
|
||||
var element = _serviceStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(ServiceBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_serviceStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ServiceBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_serviceStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ServiceBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_serviceStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ServiceBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ServiceName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия услуги", nameof(model.ServiceName));
|
||||
}
|
||||
_logger.LogInformation("Service. ServiceName:{ServiceName} Id: { Id}", model.ServiceName, model.Id);
|
||||
var element = _serviceStorage.GetElement(new ServiceSearchModel
|
||||
{
|
||||
ServiceName = model.ServiceName
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -7,11 +7,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VeterinaryContracts\VeterinaryContracts.csproj" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="BusinessLogic\" />
|
||||
<ProjectReference Include="..\VeterinaryContracts\VeterinaryContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -12,6 +12,7 @@ namespace VeterinaryContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public string DrugName { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IMedicationModel, int)> DrugMedications
|
||||
{
|
||||
get;
|
||||
|
@ -15,6 +15,9 @@ namespace VeterinaryContracts.ViewModels
|
||||
public string DrugName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
[DisplayName("Цена лекарства")]
|
||||
public double Price { get; set; }
|
||||
|
||||
public Dictionary<int, (IMedicationModel, int)> DrugMedications
|
||||
{
|
||||
get;
|
||||
|
@ -10,6 +10,7 @@ namespace VeterinaryDataModels
|
||||
{
|
||||
string DrugName { get; }
|
||||
int Count { get; }
|
||||
double Price { get; }
|
||||
Dictionary<int, (IMedicationModel, int)> DrugMedications { get; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user