business logic done
This commit is contained in:
parent
4a20353af1
commit
166e13913b
@ -0,0 +1,149 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoCenterContracts.BindingModels;
|
||||
using AutoCenterContracts.BusinessLogicsContracts;
|
||||
using AutoCenterContracts.SearchModels;
|
||||
using AutoCenterContracts.StoragesContracts;
|
||||
using AutoCenterContracts.ViewModels;
|
||||
|
||||
namespace AutoCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class PresellingWorkLogic : IPresellingWorkLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IPresellingWorkStorage _PresellingWorkStorage;
|
||||
|
||||
public PresellingWorkLogic(ILogger<PresellingWorkLogic> logger, IPresellingWorkStorage PresellingWorkStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_PresellingWorkStorage = PresellingWorkStorage;
|
||||
}
|
||||
|
||||
public bool Create(PresellingWorkBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_PresellingWorkStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(PresellingWorkBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_PresellingWorkStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public PresellingWorkViewModel? ReadElement(PresellingWorkSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. PresellingWork:{Name}.Id:{Id}", model.Name, model.Id);
|
||||
|
||||
var element = _PresellingWorkStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<PresellingWorkViewModel>? ReadList(PresellingWorkSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. PresellingWork:{Name}.Id:{Id}", model.Name, model.Id);
|
||||
|
||||
var list = model == null ? _PresellingWorkStorage.GetFullList() : _PresellingWorkStorage.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(PresellingWorkBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_PresellingWorkStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(PresellingWorkBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия предпродажной работы", nameof(model.Name));
|
||||
}
|
||||
|
||||
if (model.UserId < 1)
|
||||
{
|
||||
throw new ArgumentNullException("Невалидный идентификатор пользователя", nameof(model.UserId));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Description))
|
||||
{
|
||||
throw new ArgumentNullException("Нет описания предпродажной работы", nameof(model.Name));
|
||||
}
|
||||
|
||||
_logger.LogInformation("PresellingWork. PresellingWork:{Name}.Id:{Id}", model.Name, model.Id);
|
||||
|
||||
var element = _PresellingWorkStorage.GetElement(new PresellingWorkSearchModel
|
||||
{
|
||||
Name = model.Name,
|
||||
Description = model.Description,
|
||||
UserId = model.UserId,
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Такая Предпродажная работа уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoCenterContracts.BindingModels;
|
||||
using AutoCenterContracts.BusinessLogicsContracts;
|
||||
using AutoCenterContracts.SearchModels;
|
||||
using AutoCenterContracts.StoragesContracts;
|
||||
using AutoCenterContracts.ViewModels;
|
||||
|
||||
namespace AutoCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class PurchaseLogic : IPurchaseLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IPurchaseStorage _PurchaseStorage;
|
||||
|
||||
public PurchaseLogic(ILogger<PurchaseLogic> logger, IPurchaseStorage PurchaseStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_PurchaseStorage = PurchaseStorage;
|
||||
}
|
||||
public bool Create(PurchaseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_PurchaseStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool Delete(PurchaseBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_PurchaseStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public PurchaseViewModel? ReadElement(PurchaseSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Purchase: Id:{Id}", model.Id);
|
||||
|
||||
var element = _PurchaseStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
public List<PurchaseViewModel>? ReadList(PurchaseSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Purchase: Id:{Id}", model.Id);
|
||||
|
||||
var list = model == null ? _PurchaseStorage.GetFullList() : _PurchaseStorage.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(PurchaseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_PurchaseStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(PurchaseBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (model.ShopId < 1)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор магазина", nameof(model.Id));
|
||||
}
|
||||
if (model.UserId < 1)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор пользователя", nameof(model.Id));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Purchase. Purchase: Id:{Id}", model.Id);
|
||||
|
||||
var element = _PurchaseStorage.GetElement(new PurchaseSearchModel
|
||||
{
|
||||
ShopId = model.ShopId,
|
||||
Date = model.Date,
|
||||
IsCashPaid = model.IsCashPaid,
|
||||
UserId = model.UserId
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Такая покупка уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
138
AutoCenter/AutoCenterBusinessLogic/BusinessLogics/ShopLogic.cs
Normal file
138
AutoCenter/AutoCenterBusinessLogic/BusinessLogics/ShopLogic.cs
Normal file
@ -0,0 +1,138 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoCenterContracts.BindingModels;
|
||||
using AutoCenterContracts.BusinessLogicsContracts;
|
||||
using AutoCenterContracts.SearchModels;
|
||||
using AutoCenterContracts.StoragesContracts;
|
||||
using AutoCenterContracts.ViewModels;
|
||||
|
||||
namespace AutoCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ShopLogic : IShopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IShopStorage _ShopStorage;
|
||||
|
||||
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage ShopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_ShopStorage = ShopStorage;
|
||||
}
|
||||
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_ShopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_ShopStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Shop:{Address}.Id:{Id}", model.Address, model.Id);
|
||||
|
||||
var element = _ShopStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Shop:{Address}.Id:{Id}", model?.Address, model?.Id);
|
||||
|
||||
var list = model == null ? _ShopStorage.GetFullList() : _ShopStorage.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(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_ShopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Address))
|
||||
{
|
||||
throw new ArgumentNullException("Нет адреса магазина", nameof(model.Address));
|
||||
}
|
||||
|
||||
|
||||
_logger.LogInformation("Shop. Shop:{Address}.Id:{Id}", model.Address, model.Id);
|
||||
|
||||
var element = _ShopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
Address = model.Address
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Такой магазин уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
149
AutoCenter/AutoCenterBusinessLogic/BusinessLogics/WishLogic.cs
Normal file
149
AutoCenter/AutoCenterBusinessLogic/BusinessLogics/WishLogic.cs
Normal file
@ -0,0 +1,149 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoCenterContracts.BindingModels;
|
||||
using AutoCenterContracts.BusinessLogicsContracts;
|
||||
using AutoCenterContracts.SearchModels;
|
||||
using AutoCenterContracts.StoragesContracts;
|
||||
using AutoCenterContracts.ViewModels;
|
||||
|
||||
namespace AutoCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class WishLogic : IWishLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IWishStorage _WishStorage;
|
||||
|
||||
public WishLogic(ILogger<WishLogic> logger, IWishStorage WishStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_WishStorage = WishStorage;
|
||||
}
|
||||
|
||||
public bool Create(WishBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_WishStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(WishBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_WishStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public WishViewModel? ReadElement(WishSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Wish:{Name}.Id:{Id}", model.Name, model.Id);
|
||||
|
||||
var element = _WishStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<WishViewModel>? ReadList(WishSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Wish:{Name}.Id:{Id}", model.Name, model.Id);
|
||||
|
||||
var list = model == null ? _WishStorage.GetFullList() : _WishStorage.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(WishBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_WishStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(WishBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия пожелания", nameof(model.Name));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Description))
|
||||
{
|
||||
throw new ArgumentNullException("Нет описания пожелания", nameof(model.Description));
|
||||
}
|
||||
|
||||
if (model.PresellingWorkId < 1)
|
||||
{
|
||||
throw new ArgumentNullException("Невалидный идентификатор предпродажной работы", nameof(model.PresellingWorkId));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Wish. Wish:{Name}.Id:{Id}", model.Name, model.Id);
|
||||
|
||||
var element = _WishStorage.GetElement(new WishSearchModel
|
||||
{
|
||||
Name = model.Name,
|
||||
Description = model.Description,
|
||||
PresellingWorkId = model.PresellingWorkId
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Такое пожелание уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user