Реализовал логику курсов приема
This commit is contained in:
parent
b36674cb86
commit
185bf52db8
@ -1,35 +1,105 @@
|
|||||||
using PolyclinicContracts.BindingModels;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PolyclinicContracts.BindingModels;
|
||||||
using PolyclinicContracts.BusinessLogicsContracts;
|
using PolyclinicContracts.BusinessLogicsContracts;
|
||||||
using PolyclinicContracts.SearchModels;
|
using PolyclinicContracts.SearchModels;
|
||||||
|
using PolyclinicContracts.StoragesContracts;
|
||||||
using PolyclinicContracts.ViewModels;
|
using PolyclinicContracts.ViewModels;
|
||||||
|
|
||||||
namespace PolyclinicBusinessLogic.BusinessLogics
|
namespace PolyclinicBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
public class CourseLogic : ICourseLogic
|
public class CourseLogic : ICourseLogic
|
||||||
{
|
{
|
||||||
|
private ILogger _logger;
|
||||||
|
private ICourseStorage _courseStorage;
|
||||||
|
|
||||||
|
public CourseLogic(ILogger logger, ICourseStorage courseStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_courseStorage = courseStorage;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Create(CourseBindingModel model)
|
public bool Create(CourseBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
CheckModel(model);
|
||||||
|
if (_courseStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Delete(CourseBindingModel model)
|
public bool Delete(CourseBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_courseStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CourseViewModel? ReadElement(CourseSearchModel model)
|
public CourseViewModel? ReadElement(CourseSearchModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||||
|
var element = _courseStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CourseViewModel>? ReadList(CourseSearchModel? model)
|
public List<CourseViewModel>? ReadList(CourseSearchModel? model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||||
|
var list = model == null ? _courseStorage.GetFullList() : _courseStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Update(CourseBindingModel model)
|
public bool Update(CourseBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
CheckModel(model);
|
||||||
|
if (_courseStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(CourseBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (model.DaysCount < 1)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Количество дней приема должно быть больше нуля", nameof(model.DaysCount));
|
||||||
|
}
|
||||||
|
if (model.PillsPerDay < 1)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Количество препарата в день должно быть больше нуля", nameof(model.PillsPerDay));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Course. Id: {Id}", model.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user