бизнесс логика, даже работает
This commit is contained in:
parent
8745ef65a8
commit
910e0d374e
127
Hospital/HospitalBusinessLogic/BusinessLogics/PharmacistLogic.cs
Normal file
127
Hospital/HospitalBusinessLogic/BusinessLogics/PharmacistLogic.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using HospitalDataModels.Models;
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.ViewModels;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
using HospitalContracts.SearchModels;
|
||||
using HospitalContracts.BusinessLogicContracts;
|
||||
|
||||
|
||||
namespace HospitalBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class PharmacistLogic : IPharmacistLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPharmacistStorage _pharmacistStorage;
|
||||
public PharmacistLogic(ILogger<PharmacistLogic> logger, IPharmacistStorage
|
||||
pharmacistStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_pharmacistStorage = pharmacistStorage;
|
||||
}
|
||||
public List<PharmacistViewModel>? ReadList(PharmacistSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. PharmacistFIO:{PharmacistFIO}. Id:{ Id}", model?.FIO, model?.Id);
|
||||
var list = model == null ? _pharmacistStorage.GetFullList() :
|
||||
_pharmacistStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public PharmacistViewModel? ReadElement(PharmacistSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. PharmacistFIO:{PharmacistFIO}.Id:{ Id}", model.FIO, model.Id);
|
||||
var element = _pharmacistStorage.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(PharmacistBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_pharmacistStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(PharmacistBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_pharmacistStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(PharmacistBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_pharmacistStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(PharmacistBindingModel model, bool withParams =
|
||||
true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.FIO))
|
||||
{
|
||||
throw new ArgumentNullException("Нет ФИО клиента",
|
||||
nameof(model.FIO));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет Email клиента",
|
||||
nameof(model.Login));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля клиента",
|
||||
nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("Pharmacist. PharmacistFIO:{PharmacistFIO}." +
|
||||
"Email:{ Email}. Password:{ Password}. Id: { Id} ", model.FIO, model.Login, model.Password, model.Id);
|
||||
var element = _pharmacistStorage.GetElement(new PharmacistSearchModel
|
||||
{
|
||||
Login = model.Login,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Клиент с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,4 +6,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HospitalContracts\HospitalContracts.csproj" />
|
||||
<ProjectReference Include="..\HospitalDataModels\HospitalDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace HospitalDataModels.Models
|
||||
{
|
||||
public interface IDescriptionProcedureModel
|
||||
|
Loading…
Reference in New Issue
Block a user