fixed 0.3 :/

This commit is contained in:
Илья Федотов 2024-04-28 23:36:49 +04:00
parent 3cba2df163
commit f899455329

View File

@ -5,22 +5,20 @@ using ElectronicsShopContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic namespace ElectronicsShopBusinessLogic.BusinessLogic
{ {
public class ClientLogic : IUserLogic internal class UserLogic : IUserLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
//private readonly IClientStorage _storage; //private readonly IClientStorage _storage;
// todo нет интерфейса хранилища // todo нет интерфейса хранилища
public UserLogic(ILogger<UserLogic> logger) { public UserLogic(ILogger<UserLogic> logger)
{
_logger = logger; _logger = logger;
//storage = _storage; //storage = _storage;
} }
@ -29,7 +27,8 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
{ {
CheckModel(model); CheckModel(model);
// todo логика добавления в _clientStorage:_clientStorage.Insert(model) == null // todo логика добавления в _clientStorage:_clientStorage.Insert(model) == null
if (model == null) { if (model == null)
{
_logger.LogWarning("Add operation failed"); _logger.LogWarning("Add operation failed");
return false; return false;
} }
@ -51,9 +50,10 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
public bool Delete(UserBindingModel model) public bool Delete(UserBindingModel model)
{ {
CheckModel(model, false); CheckModel(model, false);
_logger.LogInformation($"Delete.ID:{model.UserID}"); _logger.LogInformation($"Delete.ID:{model.ID}");
// todo логика добавления в _clientStorage:_clientStorage.Delete(model) == null // todo логика добавления в _clientStorage:_clientStorage.Delete(model) == null
if (model == null) { if (model == null)
{
_logger.LogWarning("Delete operation failes"); _logger.LogWarning("Delete operation failes");
return false; return false;
} }
@ -63,28 +63,31 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
public UserViewModel? ReadElemet(UserSearchModel? model) public UserViewModel? ReadElemet(UserSearchModel? model)
{ {
if (model == null) { if (model == null)
{
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
_logger.LogInformation($"ReadElement: logint:{ model.Login}.ID:{model.UserID}"); _logger.LogInformation($"ReadElement: logint:{model.Login}.ID:{model.ID}");
// todo element = _clientStorage.GetElement(model); // todo element = _clientStorage.GetElement(model);
var element = model; var element = model;
if (element == null) { if (element == null)
{
_logger.LogWarning("ReadElement element not fount"); _logger.LogWarning("ReadElement element not fount");
return null; return null;
} }
_logger.LogInformation($"ReadElement: find.ID:{element.UserID}"); _logger.LogInformation($"ReadElement: find.ID:{element.ID}");
// todo retun element; // todo retun element;
return null; return null;
} }
public List<UserViewModel>? ReadList(UserSearchModel? model) public List<UserViewModel>? ReadList(UserSearchModel? model)
{ {
_logger.LogInformation($"ReadList: ClientID:{model?.UserID}"); _logger.LogInformation($"ReadList: ClientID:{model?.ID}");
// todo получение списка из хранилища, model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model); // todo получение списка из хранилища, model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
var list = model; var list = model;
if (list == null) { if (list == null)
{
_logger.LogWarning("ReadList: return null list"); _logger.LogWarning("ReadList: return null list");
return null; return null;
} }
@ -94,29 +97,38 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return null; return null;
} }
private void CheckModel(UserBindingModel model, bool withParams = true) { private void CheckModel(UserBindingModel model, bool withParams = true)
if (model == null) { {
if (model == null)
{
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
if (!withParams) { if (!withParams)
{
return; return;
} }
if (string.IsNullOrEmpty(model.Login)) { if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login)); throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login));
} }
if (string.IsNullOrEmpty(model.FirstName)) { if (string.IsNullOrEmpty(model.FirstName))
{
throw new ArgumentNullException("Нет имени пользователя", nameof(model.FirstName)); throw new ArgumentNullException("Нет имени пользователя", nameof(model.FirstName));
} }
if (string.IsNullOrEmpty(model.LastName)) { if (string.IsNullOrEmpty(model.LastName))
{
throw new ArgumentNullException("Нет фамилии пользоватея", nameof(model.LastName)); throw new ArgumentNullException("Нет фамилии пользоватея", nameof(model.LastName));
} }
if (string.IsNullOrEmpty(model.Email)) { if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет почты клиента", nameof(model.Email)); throw new ArgumentNullException("Нет почты клиента", nameof(model.Email));
} }
if (string.IsNullOrEmpty(model.Password)) { if (string.IsNullOrEmpty(model.Password))
throw new ArgumentNullException("Нет пароля пользователя", nameof (model.Password)); {
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
} }
if (string.IsNullOrEmpty(model.PhoneNumber)) { if (string.IsNullOrEmpty(model.PhoneNumber))
{
throw new ArgumentNullException("Нет номер телефона пользователя", nameof(model.PhoneNumber)); throw new ArgumentNullException("Нет номер телефона пользователя", nameof(model.PhoneNumber));
} }
_logger.LogInformation($"Client. Login:{model.Login}.FirstName:{model.FirstName}.LastName:{model.LastName}.Email:{model.Email}." + _logger.LogInformation($"Client. Login:{model.Login}.FirstName:{model.FirstName}.LastName:{model.LastName}.Email:{model.Email}." +