126 lines
4.9 KiB
C#
126 lines
4.9 KiB
C#
|
using ElectronicsShopContracts.BindingModels;
|
|||
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
|||
|
using ElectronicsShopContracts.SearchModels;
|
|||
|
using ElectronicsShopContracts.ViewModels;
|
|||
|
using Microsoft.Extensions.Logging;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Linq;
|
|||
|
using System.Runtime.CompilerServices;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||
|
{
|
|||
|
public class ClientLogic : IClientLogic
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
//private readonly IClientStorage _storage;
|
|||
|
|
|||
|
// todo нет интерфейса хранилища
|
|||
|
public ClientLogic(ILogger logger) {
|
|||
|
_logger = logger;
|
|||
|
//storage = _storage;
|
|||
|
}
|
|||
|
|
|||
|
public bool Add(ClientBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
// todo логика добавления в _clientStorage:_clientStorage.Insert(model) == null
|
|||
|
if (model == null) {
|
|||
|
_logger.LogWarning("Add operation failed");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Update(ClientBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
// todo логика добавления в _clientStorage:_clientStorage.Update(model) == null
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
_logger.LogWarning("Update operation failed");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Delete(ClientBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model, false);
|
|||
|
_logger.LogInformation($"Delete.ID:{model.UserID}");
|
|||
|
// todo логика добавления в _clientStorage:_clientStorage.Delete(model) == null
|
|||
|
if (model == null) {
|
|||
|
_logger.LogWarning("Delete operation failes");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public ClientViewModel? ReadElemet(ClientSearchModel? model)
|
|||
|
{
|
|||
|
if (model == null) {
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
_logger.LogInformation($"ReadElement: logint:{ model.Login}.ID:{model.UserID}");
|
|||
|
// todo element = _clientStorage.GetElement(model);
|
|||
|
var element = model;
|
|||
|
if (element == null) {
|
|||
|
_logger.LogWarning("ReadElement: element not fount");
|
|||
|
return null;
|
|||
|
}
|
|||
|
_logger.LogInformation($"ReadElement: find.ID:{element.UserID}");
|
|||
|
// todo retun element;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
|||
|
{
|
|||
|
|
|||
|
_logger.LogInformation($"ReadList: ClientID:{model?.UserID}");
|
|||
|
// todo получение списка из хранилища, model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
|
|||
|
var list = model;
|
|||
|
if (list == null) {
|
|||
|
_logger.LogWarning("ReadList: return null list");
|
|||
|
return null;
|
|||
|
}
|
|||
|
// toto ReadList. Count:{Count}, list.count
|
|||
|
_logger.LogInformation("ReadList: Count:{Count}");
|
|||
|
// todo return list;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
private void CheckModel(ClientBindingModel model, bool withParams = true) {
|
|||
|
if (model == null) {
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
if (!withParams) {
|
|||
|
return;
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.Login)) {
|
|||
|
throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login));
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.FirstName)) {
|
|||
|
throw new ArgumentNullException("Нет имени пользователя", nameof(model.FirstName));
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.LastName)) {
|
|||
|
throw new ArgumentNullException("Нет фамилии пользоватея", nameof(model.LastName));
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.Email)) {
|
|||
|
throw new ArgumentNullException("Нет почты клиента", nameof(model.Email));
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.Password)) {
|
|||
|
throw new ArgumentNullException("Нет пароля пользователя", nameof (model.Password));
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.PhoneNumber)) {
|
|||
|
throw new ArgumentNullException("Нет номер телефона пользователя", nameof(model.PhoneNumber));
|
|||
|
}
|
|||
|
_logger.LogInformation($"Client: Login:{model.Login}.FirstName:{model.FirstName}.LastName:{model.LastName}.Email:{model.Email}." +
|
|||
|
$"Password:{model.Password}.PhoneNumber:{model.PhoneNumber}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|