66 lines
1.6 KiB
C#
66 lines
1.6 KiB
C#
|
using Contracts.BindingModels;
|
|||
|
using Contracts.BusinessLogicContracts;
|
|||
|
using Contracts.StorageContracts;
|
|||
|
using Contracts.ViewModels;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace BusinessLogic
|
|||
|
{
|
|||
|
public class ManufacturerLogic : IManufacturerLogic
|
|||
|
{
|
|||
|
private readonly IManufacturerStorage _ManufacturerStorage;
|
|||
|
public ManufacturerLogic(IManufacturerStorage ManufacturerStorage)
|
|||
|
{
|
|||
|
_ManufacturerStorage = ManufacturerStorage;
|
|||
|
}
|
|||
|
|
|||
|
public void CreateOrUpdate(ManufacturerBindingModel model)
|
|||
|
{
|
|||
|
var element = _ManufacturerStorage.GetElement(
|
|||
|
new ManufacturerBindingModel
|
|||
|
{
|
|||
|
Name = model.Name
|
|||
|
});
|
|||
|
if (element != null && element.Id != model.Id)
|
|||
|
{
|
|||
|
throw new Exception("Такой статус уже существует");
|
|||
|
}
|
|||
|
if (model.Id.HasValue)
|
|||
|
{
|
|||
|
_ManufacturerStorage.Update(model);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_ManufacturerStorage.Insert(model);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Delete(ManufacturerBindingModel model)
|
|||
|
{
|
|||
|
var element = _ManufacturerStorage.GetElement(new ManufacturerBindingModel { Id = model.Id });
|
|||
|
if (element == null)
|
|||
|
{
|
|||
|
throw new Exception("Статус не найден");
|
|||
|
}
|
|||
|
_ManufacturerStorage.Delete(model);
|
|||
|
}
|
|||
|
|
|||
|
public List<ManufacturerViewModel> Read(ManufacturerBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return _ManufacturerStorage.GetFullList();
|
|||
|
}
|
|||
|
if (model.Id.HasValue)
|
|||
|
{
|
|||
|
return new List<ManufacturerViewModel> { _ManufacturerStorage.GetElement(model) };
|
|||
|
}
|
|||
|
return _ManufacturerStorage.GetFilteredList(model);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|