add contracts, business logic & data models

This commit is contained in:
Максим Сергунов 2023-05-12 12:08:11 +04:00
parent 21fb1c9f98
commit 80e8ff165c
45 changed files with 1145 additions and 9 deletions

View File

@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.5.33530.505 VisualStudioVersion = 17.5.33530.505
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookShop", "BookShop\BookShop.csproj", "{946EC661-9CF9-43DA-9C97-A2CE481406D2}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookShopView", "BookShopView\BookShopView.csproj", "{1455C2BC-5C22-4B93-8954-ACC01353BD24}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookShopDataModels", "BookShopDataModels\BookShopDataModels.csproj", "{032BDFC0-6AAF-4A75-A9AE-B24C85A4679C}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,15 +13,19 @@ Global
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{946EC661-9CF9-43DA-9C97-A2CE481406D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1455C2BC-5C22-4B93-8954-ACC01353BD24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{946EC661-9CF9-43DA-9C97-A2CE481406D2}.Debug|Any CPU.Build.0 = Debug|Any CPU {1455C2BC-5C22-4B93-8954-ACC01353BD24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{946EC661-9CF9-43DA-9C97-A2CE481406D2}.Release|Any CPU.ActiveCfg = Release|Any CPU {1455C2BC-5C22-4B93-8954-ACC01353BD24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{946EC661-9CF9-43DA-9C97-A2CE481406D2}.Release|Any CPU.Build.0 = Release|Any CPU {1455C2BC-5C22-4B93-8954-ACC01353BD24}.Release|Any CPU.Build.0 = Release|Any CPU
{032BDFC0-6AAF-4A75-A9AE-B24C85A4679C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{032BDFC0-6AAF-4A75-A9AE-B24C85A4679C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{032BDFC0-6AAF-4A75-A9AE-B24C85A4679C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{032BDFC0-6AAF-4A75-A9AE-B24C85A4679C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F2A3B3D2-EC41-4B24-B6F1-95D5692C7561} SolutionGuid = {CC21F821-D99C-4781-AD62-0FA7B3BA0F82}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,116 @@
using BookShopContracts.BindingModels;
using BookShopContracts.BusinessLogicsContracts;
using BookShopContracts.SearchModels;
using BookShopContracts.StoragesContracts;
using BookShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace BookShopBusinessLogic.BusinessLogics
{
public class AuthorLogic : IAuthorLogic
{
private readonly ILogger _logger;
private readonly IAuthorStorage _authorStorage;
public AuthorLogic(ILogger<AuthorLogic> logger, IAuthorStorage authorStorage)
{
_logger = logger;
_authorStorage = authorStorage;
}
public bool Create(AuthorBindingModel model)
{
CheckModel(model);
if (_authorStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(AuthorBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_authorStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public AuthorViewModel? ReadElement(AuthorSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. AuthorSurname: {AuthorSurname}. AuthorName: {AuthorName}. Id: {Id}.", model.AuthorSurname, model.AuthorName, model.Id);
var element = _authorStorage.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<AuthorViewModel>? ReadList(AuthorSearchModel? model)
{
_logger.LogInformation("ReadList. AuthorSurname: {AuthorSurname}. AuthorName: {AuthorName}. Id: {Id}.", model?.AuthorSurname, model?.AuthorName, model?.Id);
var list = model == null ? _authorStorage.GetFullList() : _authorStorage.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(AuthorBindingModel model)
{
CheckModel(model);
if (_authorStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(AuthorBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.AuthorSurname))
{
throw new ArgumentNullException("Нет фамилии клиента", nameof(model.AuthorSurname));
}
if (string.IsNullOrEmpty(model.AuthorName))
{
throw new ArgumentNullException("Нет имени клиента", nameof(model.AuthorName));
}
_logger.LogInformation("Author. AuthorSurname: {AuthorSurname}. AuthorName: {AuthorName}. AuthorPatronymic: {AuthorPatronymic}. Id: {Id}.", model.AuthorSurname, model.AuthorName, model.AuthorPatronymic, model.Id);
var element = _authorStorage.GetElement(new AuthorSearchModel
{
AuthorSurname = model.AuthorSurname,
AuthorName = model.AuthorName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Автор с таким ФИО уже есть");
}
}
}
}

View File

@ -0,0 +1,129 @@
using BookShopContracts.BindingModels;
using BookShopContracts.BusinessLogicsContracts;
using BookShopContracts.SearchModels;
using BookShopContracts.StoragesContracts;
using BookShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace BookShopBusinessLogic.BusinessLogics
{
public class BookLogic : IBookLogic
{
private readonly ILogger _logger;
private readonly IBookStorage _bookStorage;
public BookLogic(ILogger<BookLogic> logger, IBookStorage bookStorage)
{
_logger = logger;
_bookStorage = bookStorage;
}
public bool Create(BookBindingModel model)
{
CheckModel(model);
if (_bookStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(BookBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_bookStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public BookViewModel? ReadElement(BookSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. BookName: {BookName}. Id: {Id}.", model.BookName, model.Id);
var element = _bookStorage.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<BookViewModel>? ReadList(BookSearchModel? model)
{
_logger.LogInformation("ReadList. BookName: {BookName}. Id: {Id}.", model?.BookName, model?.Id);
var list = model == null ? _bookStorage.GetFullList() : _bookStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public string TestInsertList(int num)
{
throw new NotImplementedException();
}
public string TestReadList(int num)
{
return _bookStorage.TestReadList(num);
}
public bool Update(BookBindingModel model)
{
CheckModel(model);
if (_bookStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(BookBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.BookName))
{
throw new ArgumentNullException("Нет названия книги", nameof(model.BookName));
}
if (model.Count < 0)
{
throw new ArgumentNullException("Количество не может быть меньше 0", nameof(model.BookName));
}
if (model.Cost <= 0)
{
throw new ArgumentNullException("Стоимость не может быть меньше 0", nameof(model.BookName));
}
_logger.LogInformation("Book. BookName: {BookName}. Cost: {Cost}. Id: {Id}.", model.BookName, model.Cost, model.Id);
var element = _bookStorage.GetElement(new BookSearchModel
{
BookName = model.BookName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Книга с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,119 @@
using BookShopContracts.BindingModels;
using BookShopContracts.BusinessLogicsContracts;
using BookShopContracts.SearchModels;
using BookShopContracts.StoragesContracts;
using BookShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace BookShopBusinessLogic.BusinessLogics
{
public class ClientLogic : IClientLogic
{
private readonly ILogger _logger;
private readonly IClientStorage _clientStorage;
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
{
_logger = logger;
_clientStorage = clientStorage;
}
public bool Create(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ClientBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_clientStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ClientViewModel? ReadElement(ClientSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ClientSurname: {ClientSurname}. ClientName: {ClientName}. ClientPatronymic: {ClientPatronymic}. Email: {Email}. Id: {Id}.", model.ClientSurname, model.ClientName, model.ClientPatronymic, model.Email, model.Id);
var element = _clientStorage.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<ClientViewModel>? ReadList(ClientSearchModel? model)
{
_logger.LogInformation("ReadList. ClientSurname: {ClientSurname}. ClientName: {ClientName}. ClientPatronymic: {ClientPatronymic}. Email: {Email}. Id: {Id}.", model?.ClientSurname, model?.ClientName, model?.ClientPatronymic, model?.Email, model?.Id);
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.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(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(ClientBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ClientSurname))
{
throw new ArgumentNullException("Нет фамилии клиента", nameof(model.ClientSurname));
}
if (string.IsNullOrEmpty(model.ClientName))
{
throw new ArgumentNullException("Нет имени клиента", nameof(model.ClientName));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет почты клиента", nameof(model.Email));
}
_logger.LogInformation("Client. ClientSurname: {ClientSurname}. ClientName: {ClientName}. ClientPatronymic: {ClientPatronymic}. Email: {Email}. Id: {Id}.", model.ClientSurname, model.ClientName, model.ClientPatronymic, model.Email, model.Id);
var element = _clientStorage.GetElement(new ClientSearchModel
{
Email = model.Email
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Клиент с такой почтой уже есть");
}
}
}
}

View File

@ -0,0 +1,111 @@
using BookShopContracts.BindingModels;
using BookShopContracts.BusinessLogicsContracts;
using BookShopContracts.SearchModels;
using BookShopContracts.StoragesContracts;
using BookShopContracts.ViewModels;
using BookShopDataModels.Models;
using Microsoft.Extensions.Logging;
namespace BookShopBusinessLogic.BusinessLogics
{
public class GenreLogic : IGenreLogic
{
private readonly ILogger _logger;
private readonly IGenreStorage _genreStorage;
public GenreLogic(ILogger<GenreLogic> logger, IGenreStorage genreStorage)
{
_logger = logger;
_genreStorage = genreStorage;
}
public bool Create(GenreBindingModel model)
{
CheckModel(model);
if (_genreStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(GenreBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_genreStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public GenreViewModel? ReadElement(GenreSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. GenreName: {GenreName}. Id: {Id}.", model.GenreName, model.Id);
var element = _genreStorage.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<GenreViewModel>? ReadList(GenreSearchModel? model)
{
_logger.LogInformation("ReadList. GenreName: {GenreName}. Id: {Id}.", model?.GenreName, model?.Id);
var list = model == null ? _genreStorage.GetFullList() : _genreStorage.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(GenreBindingModel model)
{
CheckModel(model);
if (_genreStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(GenreBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.GenreName))
{
throw new ArgumentNullException("Нет названия жанра", nameof(model.GenreName));
}
_logger.LogInformation("Genre. GenreName: {GenreName}. Id: {Id}.", model.GenreName, model.Id);
var element = _genreStorage.GetElement(new GenreSearchModel
{
GenreName = model.GenreName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Такой жанр уже есть");
}
}
}
}

View File

@ -0,0 +1,102 @@
using BookShopContracts.BindingModels;
using BookShopContracts.BusinessLogicsContracts;
using BookShopContracts.SearchModels;
using BookShopContracts.StoragesContracts;
using BookShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace BookShopBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public bool Create(OrderBindingModel model)
{
CheckModel(model);
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("Order. OrderId:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.BookId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор книги", nameof(model.BookId));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество книг в заказе должно быть больше 0", nameof(model.Count));
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
}
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. Id: { BookId}", model.Id, model.Sum, model.BookId);
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
var element = _orderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
}
}

View File

@ -0,0 +1,15 @@
using BookShopDataModels.Models;
namespace BookShopContracts.BindingModels
{
public class AuthorBindingModel : IAuthorModel
{
public int Id { get; set; }
public string AuthorSurname { get; set; } = string.Empty;
public string AuthorName { get; set; } = string.Empty;
public string AuthorPatronymic { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,28 @@
using BookShopDataModels.Models;
using System.ComponentModel;
namespace BookShopContracts.BindingModels
{
public class BookBindingModel : IBookModel
{
public int Id { get; set; }
[DisplayName("Название")]
public string BookName { get; set; } = string.Empty;
[DisplayName("Стоимость")]
public double Cost { get; set; }
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Жанр")]
public int GenreId { get; set; }
public Dictionary<int, IAuthorModel> BookAuthors
{
get;
set;
} = new();
}
}

View File

@ -0,0 +1,18 @@
using BookShopDataModels.Models;
namespace BookShopContracts.BindingModels
{
public class ClientBindingModel : IClientModel
{
public int Id { get; set; }
public string ClientSurname { get; set; } = string.Empty;
public string ClientName { get; set; } = string.Empty;
public string ClientPatronymic { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,11 @@
using BookShopDataModels.Models;
namespace BookShopContracts.BindingModels
{
public class GenreBindingModel : IGenreModel
{
public int Id { get; set; }
public string GenreName { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,23 @@
using BookShopDataModels.Models;
namespace BookShopContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public int BookId { get; set; }
public string BookName { get; set; } = string.Empty;
public int ClientId { get; set; }
public string ClientName { get; set; } = string.Empty;
public int Count { get; set; }
public double Sum { get; set; }
public DateTime DateCreate { get; set; } = DateTime.Now;
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,19 @@
using BookShopContracts.BindingModels;
using BookShopContracts.SearchModels;
using BookShopContracts.ViewModels;
namespace BookShopContracts.BusinessLogicsContracts
{
public interface IAuthorLogic
{
List<AuthorViewModel>? ReadList(AuthorSearchModel? model);
AuthorViewModel? ReadElement(AuthorSearchModel model);
bool Create(AuthorBindingModel model);
bool Update(AuthorBindingModel model);
bool Delete(AuthorBindingModel model);
}
}

View File

@ -0,0 +1,23 @@
using BookShopContracts.BindingModels;
using BookShopContracts.SearchModels;
using BookShopContracts.ViewModels;
namespace BookShopContracts.BusinessLogicsContracts
{
public interface IBookLogic
{
List<BookViewModel>? ReadList(BookSearchModel? model);
BookViewModel? ReadElement(BookSearchModel model);
bool Create(BookBindingModel model);
bool Update(BookBindingModel model);
bool Delete(BookBindingModel model);
string TestInsertList(int num);
string TestReadList(int num);
}
}

View File

@ -0,0 +1,19 @@
using BookShopContracts.BindingModels;
using BookShopContracts.SearchModels;
using BookShopContracts.ViewModels;
namespace BookShopContracts.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,19 @@
using BookShopContracts.BindingModels;
using BookShopContracts.SearchModels;
using BookShopContracts.ViewModels;
namespace BookShopContracts.BusinessLogicsContracts
{
public interface IGenreLogic
{
List<GenreViewModel>? ReadList(GenreSearchModel? model);
GenreViewModel? ReadElement(GenreSearchModel model);
bool Create(GenreBindingModel model);
bool Update(GenreBindingModel model);
bool Delete(GenreBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using BookShopContracts.BindingModels;
using BookShopContracts.SearchModels;
using BookShopContracts.ViewModels;
namespace BookShopContracts.BusinessLogicsContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
OrderViewModel? ReadElement(OrderSearchModel model);
bool Create(OrderBindingModel model);
}
}

View File

@ -0,0 +1,11 @@
namespace BookShopContracts.SearchModels
{
public class AuthorSearchModel
{
public int? Id { get; set; }
public string? AuthorSurname { get; set; }
public string? AuthorName { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace BookShopContracts.SearchModels
{
public class BookSearchModel
{
public int? Id { get; set; }
public string? BookName { get; set; }
}
}

View File

@ -0,0 +1,15 @@
namespace BookShopContracts.SearchModels
{
public class ClientSearchModel
{
public int? Id { get; set; }
public string? ClientSurname { get; set; }
public string? ClientName { get; set; }
public string? ClientPatronymic { get; set; }
public string? Email { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace BookShopContracts.SearchModels
{
public class GenreSearchModel
{
public int? Id { get; set; }
public string? GenreName { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace BookShopContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
public int? ClientId { get; set; }
public DateTime? DateCreate { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using BookShopContracts.BindingModels;
using BookShopContracts.SearchModels;
using BookShopContracts.ViewModels;
namespace BookShopContracts.StoragesContracts
{
public interface IAuthorStorage
{
List<AuthorViewModel> GetFullList();
List<AuthorViewModel> GetFilteredList(AuthorSearchModel model);
AuthorViewModel? GetElement(AuthorSearchModel model);
AuthorViewModel? Insert(AuthorBindingModel model);
AuthorViewModel? Update(AuthorBindingModel model);
AuthorViewModel? Delete(AuthorBindingModel model);
}
}

View File

@ -0,0 +1,25 @@
using BookShopContracts.BindingModels;
using BookShopContracts.SearchModels;
using BookShopContracts.ViewModels;
namespace BookShopContracts.StoragesContracts
{
public interface IBookStorage
{
List<BookViewModel> GetFullList();
List<BookViewModel> GetFilteredList(BookSearchModel model);
BookViewModel? GetElement(BookSearchModel model);
BookViewModel? Insert(BookBindingModel model);
BookViewModel? Update(BookBindingModel model);
BookViewModel? Delete(BookBindingModel model);
string TestInsertList(int num);
string TestReadList(int num);
}
}

View File

@ -0,0 +1,21 @@
using BookShopContracts.BindingModels;
using BookShopContracts.SearchModels;
using BookShopContracts.ViewModels;
namespace BookShopContracts.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,21 @@
using BookShopContracts.BindingModels;
using BookShopContracts.SearchModels;
using BookShopContracts.ViewModels;
namespace BookShopContracts.StoragesContracts
{
public interface IGenreStorage
{
List<GenreViewModel> GetFullList();
List<GenreViewModel> GetFilteredList(GenreSearchModel model);
GenreViewModel? GetElement(GenreSearchModel model);
GenreViewModel? Insert(GenreBindingModel model);
GenreViewModel? Update(GenreBindingModel model);
GenreViewModel? Delete(GenreBindingModel model);
}
}

View File

@ -0,0 +1,17 @@
using BookShopContracts.BindingModels;
using BookShopContracts.SearchModels;
using BookShopContracts.ViewModels;
namespace BookShopContracts.StoragesContracts
{
public interface IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
}
}

View File

@ -0,0 +1,19 @@
using BookShopDataModels.Models;
using System.ComponentModel;
namespace BookShopContracts.ViewModels
{
public class AuthorViewModel: IAuthorModel
{
public int Id { get; set; }
[DisplayName("Фамилия автора")]
public string AuthorSurname { get; set; } = string.Empty;
[DisplayName("Имя автора")]
public string AuthorName { get; set; } = string.Empty;
[DisplayName("Отчество автора")]
public string AuthorPatronymic { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,24 @@
using BookShopDataModels.Models;
using System.ComponentModel;
namespace BookShopContracts.ViewModels
{
public class BookViewModel: IBookModel
{
public int Id { get; set; }
[DisplayName("Название")]
public string BookName { get; set; } = string.Empty;
[DisplayName("Стоимость")]
public double Cost { get; set; }
public int Count { get; set; }
public int GenreId { get; set; }
public string GenreName { get; set; } = string.Empty;
public Dictionary<int, IAuthorModel> BookAuthors { get; set; } = new();
}
}

View File

@ -0,0 +1,23 @@
using BookShopContracts.BusinessLogicsContracts;
using BookShopDataModels.Models;
using System.ComponentModel;
namespace BookShopContracts.ViewModels
{
public class ClientViewModel: IClientModel
{
public int Id { get; set; }
[DisplayName("Фамилия клиента")]
public string ClientSurname { get; set; } = string.Empty;
[DisplayName("Имя клиента")]
public string ClientName { get; set; } = string.Empty;
[DisplayName("Отчество клиента")]
public string ClientPatronymic { get; set; } = string.Empty;
[DisplayName("Электронная почта клиента")]
public string Email { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,13 @@
using BookShopDataModels.Models;
using System.ComponentModel;
namespace BookShopContracts.ViewModels
{
public class GenreViewModel: IGenreModel
{
public int Id { get; set; }
[DisplayName("Жанр")]
public string GenreName { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,29 @@
using BookShopDataModels.Models;
using System.ComponentModel;
namespace BookShopContracts.ViewModels
{
public class OrderViewModel: IOrderModel
{
public int Id { get; set; }
public int BookId { get; set; }
[DisplayName("Название книги")]
public string BookName { get; set; } = string.Empty;
public int ClientId { get; set; }
[DisplayName("Фамилия клиента")]
public string ClientSurname {get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Дата заказа")]
public DateTime DateCreate { get; set; } = DateTime.Now;
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,7 @@
namespace BookShopDataModels
{
public interface IId
{
int Id { get; }
}
}

View File

@ -0,0 +1,11 @@
namespace BookShopDataModels.Models
{
public interface IAuthorModel: IId
{
string AuthorSurname { get; }
string AuthorName { get; }
string AuthorPatronymic { get; }
}
}

View File

@ -0,0 +1,15 @@
namespace BookShopDataModels.Models
{
public interface IBookModel: IId
{
string BookName { get; }
double Cost { get; }
int Count { get; }
int GenreId { get; }
Dictionary<int, IAuthorModel> BookAuthors { get; }
}
}

View File

@ -0,0 +1,13 @@
namespace BookShopDataModels.Models
{
public interface IClientModel: IId
{
string ClientSurname { get; }
string ClientName { get; }
string ClientPatronymic { get; }
string Email { get; }
}
}

View File

@ -0,0 +1,7 @@
namespace BookShopDataModels.Models
{
public interface IGenreModel : IId
{
string GenreName { get; }
}
}

View File

@ -0,0 +1,15 @@
namespace BookShopDataModels.Models
{
public interface IOrderModel: IId
{
int Count { get; }
int BookId { get; }
int ClientId { get; }
double Sum { get; }
DateTime DateCreate { get; }
}
}

View File

@ -1,4 +1,4 @@
namespace BookShop namespace BookShopView
{ {
partial class Form1 partial class Form1
{ {

View File

@ -1,4 +1,4 @@
namespace BookShop namespace BookShopView
{ {
public partial class Form1 : Form public partial class Form1 : Form
{ {

View File

@ -1,4 +1,4 @@
namespace BookShop namespace BookShopView
{ {
internal static class Program internal static class Program
{ {