This commit is contained in:
Илья Федотов 2024-05-01 12:51:35 +04:00
parent d754b31220
commit c2faa8cfe5
11 changed files with 336 additions and 1 deletions

View File

@ -0,0 +1,18 @@
using DinerDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.BindingModels {
public class ClientBindingModel : IClientModel {
public string ClientFIO { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public int ID { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.BusinessLogicsContracts {
public interface IClientLogic {
List<ClientViewModel>? ReadList(ClientSearchModel? model);
ClientViewModel? ReadELement(ClientSearchModel model);
bool Create(ClientBindingModel model);
bool Update(ClientBindingModel model);
bool Delete(ClientBindingModel model);
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.SearchModels {
public class ClientSearchModel {
public int? ID { get; set; }
public string? ClientFIO { get; set; }
public string? Email { get; set; }
public string? Password { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.StoragesContracts {
public interface IClientStorage {
List<ClientViewModel> GetFullList();
List<ClientViewModel> GetFilteredList(ClientSearchModel model);
ClientViewModel? GetElement(ClientSearchModel model);
ClientViewModel? Insert(ClientBindingModel model);
ClientViewModel? Update(ClientBindingModel model);
ClientViewModel? Delete(ClientBindingModel model);
}
}

View File

@ -0,0 +1,24 @@
using DinerDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.ViewModels {
public class ClientViewModel : IClientModel {
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Логин (эл.почта)")]
public string Email { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
public int ID { get; set; }
}
}

View File

@ -17,7 +17,7 @@ namespace DinerContracts.ViewModels
public int Count { get; set; }
[DisplayName("Сумма")]
public Double Sum { get; set; }
public double Sum { get; set; }
[DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;

View File

@ -0,0 +1,37 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerDataBaseImplement.Implements {
public class ClientStorage : IClientStorage {
public ClientViewModel? Delete(ClientBindingModel model) {
throw new NotImplementedException();
}
public ClientViewModel? GetElement(ClientSearchModel model) {
throw new NotImplementedException();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model) {
throw new NotImplementedException();
}
public List<ClientViewModel> GetFullList() {
throw new NotImplementedException();
}
public ClientViewModel? Insert(ClientBindingModel model) {
throw new NotImplementedException();
}
public ClientViewModel? Update(ClientBindingModel model) {
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerDataModels.Models {
public interface IClientModel : IID {
string ClientFIO { get; }
string Email { get; }
string Password { get; }
}
}

View File

@ -0,0 +1,44 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerListImplement.Implements {
public class ClientStorage : IClientStorage {
private readonly DataListSingleton _source;
public ClientStorage() {
_source = DataListSingleton.GetInstance();
}
public ClientViewModel? Insert(ClientBindingModel model) {
throw new NotImplementedException();
}
public ClientViewModel? Update(ClientBindingModel model) {
throw new NotImplementedException();
}
public ClientViewModel? Delete(ClientBindingModel model) {
throw new NotImplementedException();
}
public ClientViewModel? GetElement(ClientSearchModel model) {
throw new NotImplementedException();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model) {
throw new NotImplementedException();
}
public List<ClientViewModel> GetFullList() {
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,37 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerFileImplement.Implements {
public class ClientStorage : IClientStorage {
public ClientViewModel? Delete(ClientBindingModel model) {
throw new NotImplementedException();
}
public ClientViewModel? GetElement(ClientSearchModel model) {
throw new NotImplementedException();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model) {
throw new NotImplementedException();
}
public List<ClientViewModel> GetFullList() {
throw new NotImplementedException();
}
public ClientViewModel? Insert(ClientBindingModel model) {
throw new NotImplementedException();
}
public ClientViewModel? Update(ClientBindingModel model) {
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,108 @@
using DinerContracts.BindingModels;
using DinerContracts.BusinessLogicsContracts;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using DocumentFormat.OpenXml.Vml.Spreadsheet;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DineryBusinessLogic.BusinessLogic {
public class ClientLogic : IClientLogic {
private readonly ILogger _logger;
private readonly IClientStorage _storage;
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage storage) {
_logger = logger;
_storage = storage;
}
public bool Create(ClientBindingModel model) {
CheckModel(model);
if (_storage.Insert(model) == null) {
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ClientBindingModel model) {
CheckModel(model, false);
_logger.LogInformation($"Delete. ID:{model.ID}");
if (_storage.Delete(model) == null) {
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Update(ClientBindingModel model) {
CheckModel(model);
if (_storage.Update(model) == null) {
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public ClientViewModel? ReadELement(ClientSearchModel model) {
if (model == null) {
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation($"ReadElement. Login:{model.ClientFIO}.ID:{model.ID}");
var element = _storage.GetElement(model);
if (element == null) {
_logger.LogWarning("ReadElement. element not found");
return null;
}
_logger.LogInformation($"ReadElement. find.ID:{element.ID}");
return element;
}
public List<ClientViewModel>? ReadList(ClientSearchModel? model) {
_logger.LogInformation($"ReadList. CLiendID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
if (list == null) {
_logger.LogWarning("ReadList. return nell list");
return null;
}
_logger.LogInformation($"ReadList. Count:{list.Count}");
return list;
}
private void CheckModel(ClientBindingModel model, bool withParams = true) {
if (model == null ) {
throw new ArgumentNullException(nameof(model));
}
if (!withParams) {
return;
}
if (string.IsNullOrEmpty(model.ClientFIO)) {
throw new ArgumentNullException("Нет ФИО пользователя", nameof(model.ClientFIO));
}
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.ID).ToString())) {
throw new ArgumentNullException("Нет ID пользователя", nameof(model.ID));
}
_logger.LogInformation($"Client. ID:{model.ID}.FIO:{model.ClientFIO}.Email:{model.Email}.Password:{model.Password}");
var element = _storage.GetElement(new ClientSearchModel {
ClientFIO = model.ClientFIO,
});
if (element != null && element.ClientFIO != model.ClientFIO) {
throw new InvalidOperationException("Клиент с таким логином уже есть");
}
}
}
}