diff --git a/Bookshop/Bookshop.sln b/Bookshop/Bookshop.sln
index b953496..f225ff2 100644
--- a/Bookshop/Bookshop.sln
+++ b/Bookshop/Bookshop.sln
@@ -3,11 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookshopDataModels", "BookshopDataModels\BookshopDataModels.csproj", "{36D7E02E-39EE-4C04-9AEB-6298B67D935C}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookshopDataModels", "BookshopDataModels\BookshopDataModels.csproj", "{36D7E02E-39EE-4C04-9AEB-6298B67D935C}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookshopView", "BookshopView\BookshopView.csproj", "{8406C468-605F-4932-AB19-2BFD98480D19}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookshopView", "BookshopView\BookshopView.csproj", "{8406C468-605F-4932-AB19-2BFD98480D19}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookshopContracts", "BookshopContracts\BookshopContracts.csproj", "{9BC70D3F-9F6E-4B9B-A519-5C46417A9B6D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookshopContracts", "BookshopContracts\BookshopContracts.csproj", "{9BC70D3F-9F6E-4B9B-A519-5C46417A9B6D}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookshopBusinessLogic", "BookshopBusinessLogic\BookshopBusinessLogic.csproj", "{0A7EF39B-C9EC-4FDF-A962-06AEC11C0BF5}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookshopDatabaseImplement", "BookshopDatabaseImplement\BookshopDatabaseImplement.csproj", "{CA3B1C63-94A4-4AB6-A1CB-42259C13A866}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -27,6 +31,14 @@ Global
{9BC70D3F-9F6E-4B9B-A519-5C46417A9B6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BC70D3F-9F6E-4B9B-A519-5C46417A9B6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BC70D3F-9F6E-4B9B-A519-5C46417A9B6D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0A7EF39B-C9EC-4FDF-A962-06AEC11C0BF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0A7EF39B-C9EC-4FDF-A962-06AEC11C0BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0A7EF39B-C9EC-4FDF-A962-06AEC11C0BF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0A7EF39B-C9EC-4FDF-A962-06AEC11C0BF5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CA3B1C63-94A4-4AB6-A1CB-42259C13A866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CA3B1C63-94A4-4AB6-A1CB-42259C13A866}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CA3B1C63-94A4-4AB6-A1CB-42259C13A866}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CA3B1C63-94A4-4AB6-A1CB-42259C13A866}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Bookshop/BookshopBusinessLogic/BookshopBusinessLogic.csproj b/Bookshop/BookshopBusinessLogic/BookshopBusinessLogic.csproj
new file mode 100644
index 0000000..1361582
--- /dev/null
+++ b/Bookshop/BookshopBusinessLogic/BookshopBusinessLogic.csproj
@@ -0,0 +1,18 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/AuthorLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/AuthorLogic.cs
new file mode 100644
index 0000000..49c0cfd
--- /dev/null
+++ b/Bookshop/BookshopBusinessLogic/BusinessLogics/AuthorLogic.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.BusinessLogicsContracts;
+using BookshopContracts.StorageContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BookshopBusinessLogic.BusinessLogics
+{
+ public class AuthorLogic : IAuthorLogic
+ {
+ private readonly ILogger _logger;
+
+ private readonly IAuthorStorage _AuthorStorage;
+
+ public AuthorLogic(ILogger logger, IAuthorStorage AuthorStorage)
+ {
+ _logger = logger;
+ _AuthorStorage = AuthorStorage;
+ }
+
+ public List? ReadList(AuthorSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. AuthorName:{AuthorName}. Id:{Id}", 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 AuthorViewModel? ReadElement(AuthorSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. AuthorName:{AuthorName}. Id:{Id}", 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 bool Create(AuthorBindingModel model)
+ {
+ CheckModel(model);
+ if (_AuthorStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(AuthorBindingModel model)
+ {
+ CheckModel(model);
+ if (_AuthorStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update 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;
+ }
+
+ private void CheckModel(AuthorBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.AuthorName))
+ {
+ throw new ArgumentNullException("Не указано имя автора", nameof(model.AuthorName));
+ }
+ if (string.IsNullOrEmpty(model.Country))
+ {
+ throw new ArgumentNullException("Не указана страна автора", nameof(model.Country));
+ }
+ _logger.LogInformation("Author. AuthorName:{AuthorName}. Country:{Country}. Id:{Id}", model.AuthorName, model.Country, model.Id);
+ var element = _AuthorStorage.GetElement(new AuthorSearchModel
+ {
+ AuthorName = model.AuthorName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Такой автор уже существует");
+ }
+ }
+ }
+}
diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/BookLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/BookLogic.cs
new file mode 100644
index 0000000..72fd340
--- /dev/null
+++ b/Bookshop/BookshopBusinessLogic/BusinessLogics/BookLogic.cs
@@ -0,0 +1,124 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.BusinessLogicsContracts;
+using BookshopContracts.StorageContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BookshopBusinessLogic.BusinessLogics
+{
+ public class BookLogic : IBookLogic
+ {
+ private readonly ILogger _logger;
+
+ private readonly IBookStorage _BookStorage;
+
+ public BookLogic(ILogger logger, IBookStorage BookStorage)
+ {
+ _logger = logger;
+ _BookStorage = BookStorage;
+ }
+
+ public List? ReadList(BookSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. Title:{Title}. Id:{Id}", model?.Title, 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 BookViewModel? ReadElement(BookSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. Title:{Title}. Id:{Id}", model.Title, 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 bool Create(BookBindingModel model)
+ {
+ CheckModel(model);
+ if (_BookStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(BookBindingModel model)
+ {
+ CheckModel(model);
+ if (_BookStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update 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;
+ }
+
+ private void CheckModel(BookBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.Title))
+ {
+ throw new ArgumentNullException("Нет названия компонента", nameof(model.Title));
+ }
+ if (model.AuthorId <= 0)
+ {
+ throw new ArgumentNullException("Не указан идентификатор автора", nameof(model.AuthorId));
+ }
+ if (model.GenreId <= 0)
+ {
+ throw new ArgumentNullException("Не указан идентификатор жанра", nameof(model.GenreId));
+ }
+ _logger.LogInformation("Book. Id:{Id}", model.Id);
+ var element = _BookStorage.GetElement(new BookSearchModel
+ {
+ Title = model.Title
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Компонент с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/GenreLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/GenreLogic.cs
new file mode 100644
index 0000000..c091ea5
--- /dev/null
+++ b/Bookshop/BookshopBusinessLogic/BusinessLogics/GenreLogic.cs
@@ -0,0 +1,116 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.BusinessLogicsContracts;
+using BookshopContracts.StorageContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BookshopBusinessLogic.BusinessLogics
+{
+ public class GenreLogic : IGenreLogic
+ {
+ private readonly ILogger _logger;
+
+ private readonly IGenreStorage _GenreStorage;
+
+ public GenreLogic(ILogger logger, IGenreStorage GenreStorage)
+ {
+ _logger = logger;
+ _GenreStorage = GenreStorage;
+ }
+
+ public List? 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 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 bool Create(GenreBindingModel model)
+ {
+ CheckModel(model);
+ if (_GenreStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(GenreBindingModel model)
+ {
+ CheckModel(model);
+ if (_GenreStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update 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;
+ }
+
+ 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. Id:{Id}", model.Id);
+ var element = _GenreStorage.GetElement(new GenreSearchModel
+ {
+ GenreName = model.GenreName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Компонент с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/InstanceLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/InstanceLogic.cs
new file mode 100644
index 0000000..18b9efb
--- /dev/null
+++ b/Bookshop/BookshopBusinessLogic/BusinessLogics/InstanceLogic.cs
@@ -0,0 +1,112 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.BusinessLogicsContracts;
+using BookshopContracts.StorageContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BookshopBusinessLogic.BusinessLogics
+{
+ public class InstanceLogic : IInstanceLogic
+ {
+ private readonly ILogger _logger;
+
+ private readonly IInstanceStorage _InstanceStorage;
+
+ public InstanceLogic(ILogger logger, IInstanceStorage InstanceStorage)
+ {
+ _logger = logger;
+ _InstanceStorage = InstanceStorage;
+ }
+
+ public List? ReadList(InstanceSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. BookId:{BookId}. Id:{Id}", model?.BookId, model?.Id);
+ var list = model == null ? _InstanceStorage.GetFullList() : _InstanceStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public InstanceViewModel? ReadElement(InstanceSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. BookId:{BookId}. Id:{Id}", model.BookId, model.Id);
+ var element = _InstanceStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public bool Create(InstanceBindingModel model)
+ {
+ CheckModel(model);
+ if (_InstanceStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(InstanceBindingModel model)
+ {
+ CheckModel(model);
+ if (_InstanceStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(InstanceBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_InstanceStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(InstanceBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.StockQuantity <= 0)
+ {
+ throw new ArgumentNullException("Количество экзмепляров должно быть больше 0", nameof(model.StockQuantity));
+ }
+ if (model.Price <= 0)
+ {
+ throw new ArgumentNullException("Цена книги должна быть больше 0", nameof(model.Price));
+ }
+ _logger.LogInformation("Instance. Id:{Id}", model.Id);
+ }
+ }
+}
diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/OrderLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/OrderLogic.cs
new file mode 100644
index 0000000..faad434
--- /dev/null
+++ b/Bookshop/BookshopBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.BusinessLogicsContracts;
+using BookshopContracts.StorageContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BookshopBusinessLogic.BusinessLogics
+{
+ public class OrderLogic : IOrderLogic
+ {
+ private readonly ILogger _logger;
+
+ private readonly IOrderStorage _OrderStorage;
+
+ public OrderLogic(ILogger logger, IOrderStorage OrderStorage)
+ {
+ _logger = logger;
+ _OrderStorage = OrderStorage;
+ }
+
+ public List? ReadList(OrderSearchModel? model)
+ {
+ 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;
+ }
+
+ public OrderViewModel? ReadElement(OrderSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ 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;
+ }
+
+ public bool Create(OrderBindingModel model)
+ {
+ CheckModel(model);
+ if (_OrderStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(OrderBindingModel model)
+ {
+ CheckModel(model);
+ if (_OrderStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(OrderBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_OrderStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(OrderBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.Quantity <= 0)
+ {
+ throw new ArgumentNullException("Количество книг в заказе должно быть больше 0", nameof(model.Quantity));
+ }
+ if (model.InstanceId <= 0)
+ {
+ throw new ArgumentNullException("Не указан идентификатор экземляра", nameof(model.InstanceId));
+ }
+ if (model.UserId <= 0)
+ {
+ throw new ArgumentNullException("Не указан идентификатор пользователя", nameof(model.UserId));
+ }
+ _logger.LogInformation("Order. Id:{Id}", model.Id);
+ }
+ }
+}
diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/PublisherLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/PublisherLogic.cs
new file mode 100644
index 0000000..007c792
--- /dev/null
+++ b/Bookshop/BookshopBusinessLogic/BusinessLogics/PublisherLogic.cs
@@ -0,0 +1,128 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.BusinessLogicsContracts;
+using BookshopContracts.StorageContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BookshopBusinessLogic.BusinessLogics
+{
+ public class PublisherLogic : IPublisherLogic
+ {
+ private readonly ILogger _logger;
+
+ private readonly IPublisherStorage _PublisherStorage;
+
+ public PublisherLogic(ILogger logger, IPublisherStorage PublisherStorage)
+ {
+ _logger = logger;
+ _PublisherStorage = PublisherStorage;
+ }
+
+ public List? ReadList(PublisherSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. PublisherName:{PublisherName}. Id:{Id}", model?.PublisherName, model?.Id);
+ var list = model == null ? _PublisherStorage.GetFullList() : _PublisherStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public PublisherViewModel? ReadElement(PublisherSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. PublisherName:{PublisherName}. Id:{Id}", model.PublisherName, model.Id);
+ var element = _PublisherStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public bool Create(PublisherBindingModel model)
+ {
+ CheckModel(model);
+ if (_PublisherStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(PublisherBindingModel model)
+ {
+ CheckModel(model);
+ if (_PublisherStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(PublisherBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_PublisherStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(PublisherBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.PublisherName))
+ {
+ throw new ArgumentNullException("Нет названия издательства", nameof(model.PublisherName));
+ }
+ if (string.IsNullOrEmpty(model.Address))
+ {
+ throw new ArgumentNullException("Нет адресса издательства", nameof(model.Address));
+ }
+ if (string.IsNullOrEmpty(model.PhoneNumber))
+ {
+ throw new ArgumentNullException("Нет номера телефона", nameof(model.PhoneNumber));
+ }
+ if (string.IsNullOrEmpty(model.Email))
+ {
+ throw new ArgumentNullException("Нет электронной почты", nameof(model.Email));
+ }
+ _logger.LogInformation("Publisher. Id:{Id}", model.Id);
+ var element = _PublisherStorage.GetElement(new PublisherSearchModel
+ {
+ PublisherName = model.PublisherName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Издательство с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/ReviewLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/ReviewLogic.cs
new file mode 100644
index 0000000..ec6e96a
--- /dev/null
+++ b/Bookshop/BookshopBusinessLogic/BusinessLogics/ReviewLogic.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.BusinessLogicsContracts;
+using BookshopContracts.StorageContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BookshopBusinessLogic.BusinessLogics
+{
+ public class ReviewLogic : IReviewLogic
+ {
+ private readonly ILogger _logger;
+
+ private readonly IReviewStorage _ReviewStorage;
+
+ public ReviewLogic(ILogger logger, IReviewStorage ReviewStorage)
+ {
+ _logger = logger;
+ _ReviewStorage = ReviewStorage;
+ }
+
+ public List? ReadList(ReviewSearchModel? model)
+ {
+ var list = model == null ? _ReviewStorage.GetFullList() : _ReviewStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public ReviewViewModel? ReadElement(ReviewSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ var element = _ReviewStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public bool Create(ReviewBindingModel model)
+ {
+ CheckModel(model);
+ if (_ReviewStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(ReviewBindingModel model)
+ {
+ CheckModel(model);
+ if (_ReviewStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(ReviewBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_ReviewStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(ReviewBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ReviewText))
+ {
+ throw new ArgumentNullException("Нет текста отзыва", nameof(model.ReviewText));
+ }
+ if (model.InstanceId <= 0)
+ {
+ throw new ArgumentNullException("Не указан идентификатор экземляра", nameof(model.InstanceId));
+ }
+ if (model.UserId <= 0)
+ {
+ throw new ArgumentNullException("Не указан идентификатор пользователя", nameof(model.UserId));
+ }
+ _logger.LogInformation("Review. Id:{Id}", model.Id);
+ }
+ }
+}
diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/UserLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/UserLogic.cs
new file mode 100644
index 0000000..5fd7a02
--- /dev/null
+++ b/Bookshop/BookshopBusinessLogic/BusinessLogics/UserLogic.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.BusinessLogicsContracts;
+using BookshopContracts.StorageContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BookshopBusinessLogic.BusinessLogics
+{
+ public class UserLogic : IUserLogic
+ {
+ private readonly ILogger _logger;
+
+ private readonly IUserStorage _UserStorage;
+
+ public UserLogic(ILogger logger, IUserStorage UserStorage)
+ {
+ _logger = logger;
+ _UserStorage = UserStorage;
+ }
+
+ public List? ReadList(UserSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. Username:{Username}. Id:{Id}", model?.Username, model?.Id);
+ var list = model == null ? _UserStorage.GetFullList() : _UserStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public UserViewModel? ReadElement(UserSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. Username:{Username}. Id:{Id}", model.Username, model.Id);
+ var element = _UserStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public bool Create(UserBindingModel model)
+ {
+ CheckModel(model);
+ if (_UserStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(UserBindingModel model)
+ {
+ CheckModel(model);
+ if (_UserStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(UserBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_UserStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(UserBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.Username))
+ {
+ throw new ArgumentNullException("Нет названия компонента", nameof(model.Username));
+ }
+ if (string.IsNullOrEmpty(model.UserEmail))
+ {
+ throw new ArgumentNullException("Нет названия компонента", nameof(model.UserEmail));
+ }
+ _logger.LogInformation("User. Id:{Id}", model.Id);
+ var element = _UserStorage.GetElement(new UserSearchModel
+ {
+ UserEmail = model.UserEmail
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Пользователь с такой почтой уже есть");
+ }
+ }
+ }
+}
diff --git a/Bookshop/BookshopContracts/BookshopContracts.csproj b/Bookshop/BookshopContracts/BookshopContracts.csproj
index 0c36139..0d8182d 100644
--- a/Bookshop/BookshopContracts/BookshopContracts.csproj
+++ b/Bookshop/BookshopContracts/BookshopContracts.csproj
@@ -6,11 +6,6 @@
enable
-
-
-
-
-
diff --git a/Bookshop/BookshopContracts/BusinessLogicsContracts/IAuthorLogic.cs b/Bookshop/BookshopContracts/BusinessLogicsContracts/IAuthorLogic.cs
index 816c0c8..c3c285f 100644
--- a/Bookshop/BookshopContracts/BusinessLogicsContracts/IAuthorLogic.cs
+++ b/Bookshop/BookshopContracts/BusinessLogicsContracts/IAuthorLogic.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
namespace BookshopContracts.BusinessLogicsContracts
{
diff --git a/Bookshop/BookshopContracts/BusinessLogicsContracts/IBookLogic.cs b/Bookshop/BookshopContracts/BusinessLogicsContracts/IBookLogic.cs
index 6377957..5229cbc 100644
--- a/Bookshop/BookshopContracts/BusinessLogicsContracts/IBookLogic.cs
+++ b/Bookshop/BookshopContracts/BusinessLogicsContracts/IBookLogic.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
namespace BookshopContracts.BusinessLogicsContracts
{
diff --git a/Bookshop/BookshopContracts/BusinessLogicsContracts/IGenreLogic.cs b/Bookshop/BookshopContracts/BusinessLogicsContracts/IGenreLogic.cs
index ce1ad00..255c6e7 100644
--- a/Bookshop/BookshopContracts/BusinessLogicsContracts/IGenreLogic.cs
+++ b/Bookshop/BookshopContracts/BusinessLogicsContracts/IGenreLogic.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
namespace BookshopContracts.BusinessLogicsContracts
{
diff --git a/Bookshop/BookshopContracts/BusinessLogicsContracts/IInstanceLogic.cs b/Bookshop/BookshopContracts/BusinessLogicsContracts/IInstanceLogic.cs
index e48990f..2bfdee9 100644
--- a/Bookshop/BookshopContracts/BusinessLogicsContracts/IInstanceLogic.cs
+++ b/Bookshop/BookshopContracts/BusinessLogicsContracts/IInstanceLogic.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
namespace BookshopContracts.BusinessLogicsContracts
{
diff --git a/Bookshop/BookshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/Bookshop/BookshopContracts/BusinessLogicsContracts/IOrderLogic.cs
index 57d4c6d..c684283 100644
--- a/Bookshop/BookshopContracts/BusinessLogicsContracts/IOrderLogic.cs
+++ b/Bookshop/BookshopContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
namespace BookshopContracts.BusinessLogicsContracts
{
diff --git a/Bookshop/BookshopContracts/BusinessLogicsContracts/IPublisherLogic.cs b/Bookshop/BookshopContracts/BusinessLogicsContracts/IPublisherLogic.cs
index 12608ab..107c8e0 100644
--- a/Bookshop/BookshopContracts/BusinessLogicsContracts/IPublisherLogic.cs
+++ b/Bookshop/BookshopContracts/BusinessLogicsContracts/IPublisherLogic.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
namespace BookshopContracts.BusinessLogicsContracts
{
diff --git a/Bookshop/BookshopContracts/BusinessLogicsContracts/IReviewLogic.cs b/Bookshop/BookshopContracts/BusinessLogicsContracts/IReviewLogic.cs
index 731eba5..c369fff 100644
--- a/Bookshop/BookshopContracts/BusinessLogicsContracts/IReviewLogic.cs
+++ b/Bookshop/BookshopContracts/BusinessLogicsContracts/IReviewLogic.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
namespace BookshopContracts.BusinessLogicsContracts
{
diff --git a/Bookshop/BookshopContracts/BusinessLogicsContracts/IUserLogic.cs b/Bookshop/BookshopContracts/BusinessLogicsContracts/IUserLogic.cs
index bcbf7ef..01d1b6a 100644
--- a/Bookshop/BookshopContracts/BusinessLogicsContracts/IUserLogic.cs
+++ b/Bookshop/BookshopContracts/BusinessLogicsContracts/IUserLogic.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
namespace BookshopContracts.BusinessLogicsContracts
{
diff --git a/Bookshop/BookshopContracts/SearchModels/AuthorSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/AuthorSearchModel.cs
new file mode 100644
index 0000000..74d717e
--- /dev/null
+++ b/Bookshop/BookshopContracts/SearchModels/AuthorSearchModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.SearchModels
+{
+ public class AuthorSearchModel
+ {
+ public int? Id { get; set; }
+ public string? AuthorName { get; set; } = string.Empty;
+ public string? Country { get; set; } = string.Empty;
+ }
+}
diff --git a/Bookshop/BookshopContracts/SearchModels/BookSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/BookSearchModel.cs
new file mode 100644
index 0000000..d8e9882
--- /dev/null
+++ b/Bookshop/BookshopContracts/SearchModels/BookSearchModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.SearchModels
+{
+ public class BookSearchModel
+ {
+ public int? Id { get; set; }
+ public string? Title { get; set; } = string.Empty;
+ public int? YearOfPublication { get; set; }
+ public int? AuthorId { get; set; }
+ public int? GenreId { get; set; }
+ }
+}
diff --git a/Bookshop/BookshopContracts/SearchModels/GenreSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/GenreSearchModel.cs
new file mode 100644
index 0000000..b4f8357
--- /dev/null
+++ b/Bookshop/BookshopContracts/SearchModels/GenreSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.SearchModels
+{
+ public class GenreSearchModel
+ {
+ public int? Id { get; set; }
+ public string? GenreName { get; set; } = string.Empty;
+ }
+}
diff --git a/Bookshop/BookshopContracts/SearchModels/InstanceSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/InstanceSearchModel.cs
new file mode 100644
index 0000000..a97ae9c
--- /dev/null
+++ b/Bookshop/BookshopContracts/SearchModels/InstanceSearchModel.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.SearchModels
+{
+ public class InstanceSearchModel
+ {
+ public int? Id { get; set; }
+ public bool? Pictures { get; set; }
+ public int? StockQuantity { get; set; }
+ public double? Price { get; set; }
+ public int? BookId { get; set; }
+ public int? PublisherId { get; set; }
+ }
+}
diff --git a/Bookshop/BookshopContracts/SearchModels/OrderSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/OrderSearchModel.cs
new file mode 100644
index 0000000..bf37752
--- /dev/null
+++ b/Bookshop/BookshopContracts/SearchModels/OrderSearchModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.SearchModels
+{
+ public class OrderSearchModel
+ {
+ public int? Id { get; set; }
+ public DateTime? OrderDate { get; set; }
+ public int? Quantity { get; set; }
+ public int? InstanceId { get; set; }
+ public int? UserId { get; set; }
+ }
+}
diff --git a/Bookshop/BookshopContracts/SearchModels/PublisherSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/PublisherSearchModel.cs
new file mode 100644
index 0000000..d25a66d
--- /dev/null
+++ b/Bookshop/BookshopContracts/SearchModels/PublisherSearchModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.SearchModels
+{
+ public class PublisherSearchModel
+ {
+ public int? Id { get; set; }
+ public string? PublisherName { get; set; } = string.Empty;
+ public string? Address { get; set; } = string.Empty;
+ public string? PhoneNumber { get; set; } = string.Empty;
+ public string? Email { get; set; } = string.Empty;
+ }
+}
diff --git a/Bookshop/BookshopContracts/SearchModels/ReviewSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/ReviewSearchModel.cs
new file mode 100644
index 0000000..857bd47
--- /dev/null
+++ b/Bookshop/BookshopContracts/SearchModels/ReviewSearchModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.SearchModels
+{
+ public class ReviewSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ReviewText { get; set; } = string.Empty;
+ public DateTime? ReviewDate { get; set; }
+ public int? InstanceId { get; set; }
+ public int? UserId { get; set; }
+ }
+}
diff --git a/Bookshop/BookshopContracts/SearchModels/UserSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/UserSearchModel.cs
new file mode 100644
index 0000000..c429204
--- /dev/null
+++ b/Bookshop/BookshopContracts/SearchModels/UserSearchModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.SearchModels
+{
+ public class UserSearchModel
+ {
+ public int? Id { get; set; }
+ public string? Username { get; set; } = string.Empty;
+ public string? UserEmail { get; set; } = string.Empty;
+ }
+}
diff --git a/Bookshop/BookshopContracts/StorageContracts/IAuthorStorage.cs b/Bookshop/BookshopContracts/StorageContracts/IAuthorStorage.cs
index 72597d8..27d91ce 100644
--- a/Bookshop/BookshopContracts/StorageContracts/IAuthorStorage.cs
+++ b/Bookshop/BookshopContracts/StorageContracts/IAuthorStorage.cs
@@ -3,10 +3,19 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
namespace BookshopContracts.StorageContracts
{
- internal class IAuthorStorage
+ public interface IAuthorStorage
{
+ List GetFullList();
+ List GetFilteredList(AuthorSearchModel model);
+ AuthorViewModel? GetElement(AuthorSearchModel model);
+ AuthorViewModel? Insert(AuthorBindingModel model);
+ AuthorViewModel? Update(AuthorBindingModel model);
+ AuthorViewModel? Delete(AuthorBindingModel model);
}
}
diff --git a/Bookshop/BookshopContracts/StorageContracts/IBookStorage.cs b/Bookshop/BookshopContracts/StorageContracts/IBookStorage.cs
index 5221eaf..cacb5e3 100644
--- a/Bookshop/BookshopContracts/StorageContracts/IBookStorage.cs
+++ b/Bookshop/BookshopContracts/StorageContracts/IBookStorage.cs
@@ -3,10 +3,19 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
namespace BookshopContracts.StorageContracts
{
- internal class IBookStorage
+ public interface IBookStorage
{
+ List GetFullList();
+ List GetFilteredList(BookSearchModel model);
+ BookViewModel? GetElement(BookSearchModel model);
+ BookViewModel? Insert(BookBindingModel model);
+ BookViewModel? Update(BookBindingModel model);
+ BookViewModel? Delete(BookBindingModel model);
}
}
diff --git a/Bookshop/BookshopContracts/StorageContracts/IGenreStorage.cs b/Bookshop/BookshopContracts/StorageContracts/IGenreStorage.cs
new file mode 100644
index 0000000..15b568e
--- /dev/null
+++ b/Bookshop/BookshopContracts/StorageContracts/IGenreStorage.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+
+namespace BookshopContracts.StorageContracts
+{
+ public interface IGenreStorage
+ {
+ List GetFullList();
+ List GetFilteredList(GenreSearchModel model);
+ GenreViewModel? GetElement(GenreSearchModel model);
+ GenreViewModel? Insert(GenreBindingModel model);
+ GenreViewModel? Update(GenreBindingModel model);
+ GenreViewModel? Delete(GenreBindingModel model);
+ }
+}
diff --git a/Bookshop/BookshopContracts/StorageContracts/IInstanceStorage.cs b/Bookshop/BookshopContracts/StorageContracts/IInstanceStorage.cs
new file mode 100644
index 0000000..51b0c9c
--- /dev/null
+++ b/Bookshop/BookshopContracts/StorageContracts/IInstanceStorage.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+
+namespace BookshopContracts.StorageContracts
+{
+ public interface IInstanceStorage
+ {
+ List GetFullList();
+ List GetFilteredList(InstanceSearchModel model);
+ InstanceViewModel? GetElement(InstanceSearchModel model);
+ InstanceViewModel? Insert(InstanceBindingModel model);
+ InstanceViewModel? Update(InstanceBindingModel model);
+ InstanceViewModel? Delete(InstanceBindingModel model);
+ }
+}
diff --git a/Bookshop/BookshopContracts/StorageContracts/IOrderStorage.cs b/Bookshop/BookshopContracts/StorageContracts/IOrderStorage.cs
new file mode 100644
index 0000000..8c340ea
--- /dev/null
+++ b/Bookshop/BookshopContracts/StorageContracts/IOrderStorage.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+
+namespace BookshopContracts.StorageContracts
+{
+ public interface IOrderStorage
+ {
+ List GetFullList();
+ List GetFilteredList(OrderSearchModel model);
+ OrderViewModel? GetElement(OrderSearchModel model);
+ OrderViewModel? Insert(OrderBindingModel model);
+ OrderViewModel? Update(OrderBindingModel model);
+ OrderViewModel? Delete(OrderBindingModel model);
+ }
+}
diff --git a/Bookshop/BookshopContracts/StorageContracts/IPublisherStorage.cs b/Bookshop/BookshopContracts/StorageContracts/IPublisherStorage.cs
new file mode 100644
index 0000000..59a168a
--- /dev/null
+++ b/Bookshop/BookshopContracts/StorageContracts/IPublisherStorage.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+
+namespace BookshopContracts.StorageContracts
+{
+ public interface IPublisherStorage
+ {
+ List GetFullList();
+ List GetFilteredList(PublisherSearchModel model);
+ PublisherViewModel? GetElement(PublisherSearchModel model);
+ PublisherViewModel? Insert(PublisherBindingModel model);
+ PublisherViewModel? Update(PublisherBindingModel model);
+ PublisherViewModel? Delete(PublisherBindingModel model);
+ }
+}
diff --git a/Bookshop/BookshopContracts/StorageContracts/IReviewStorage.cs b/Bookshop/BookshopContracts/StorageContracts/IReviewStorage.cs
new file mode 100644
index 0000000..660504c
--- /dev/null
+++ b/Bookshop/BookshopContracts/StorageContracts/IReviewStorage.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+
+namespace BookshopContracts.StorageContracts
+{
+ public interface IReviewStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ReviewSearchModel model);
+ ReviewViewModel? GetElement(ReviewSearchModel model);
+ ReviewViewModel? Insert(ReviewBindingModel model);
+ ReviewViewModel? Update(ReviewBindingModel model);
+ ReviewViewModel? Delete(ReviewBindingModel model);
+ }
+}
diff --git a/Bookshop/BookshopContracts/StorageContracts/IUserStorage.cs b/Bookshop/BookshopContracts/StorageContracts/IUserStorage.cs
new file mode 100644
index 0000000..87fe68b
--- /dev/null
+++ b/Bookshop/BookshopContracts/StorageContracts/IUserStorage.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+
+namespace BookshopContracts.StorageContracts
+{
+ public interface IUserStorage
+ {
+ List GetFullList();
+ List GetFilteredList(UserSearchModel model);
+ UserViewModel? GetElement(UserSearchModel model);
+ UserViewModel? Insert(UserBindingModel model);
+ UserViewModel? Update(UserBindingModel model);
+ UserViewModel? Delete(UserBindingModel model);
+ }
+}
diff --git a/Bookshop/BookshopContracts/ViewModels/AuthorViewModel.cs b/Bookshop/BookshopContracts/ViewModels/AuthorViewModel.cs
new file mode 100644
index 0000000..af6bc8f
--- /dev/null
+++ b/Bookshop/BookshopContracts/ViewModels/AuthorViewModel.cs
@@ -0,0 +1,20 @@
+using BookshopContracts.BusinessLogicsContracts;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopDataModels.Models;
+using System.ComponentModel;
+
+namespace BookshopContracts.ViewModels
+{
+ public class AuthorViewModel : IAuthorModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Имя автора")]
+ public string AuthorName { get; set; } = string.Empty;
+ [DisplayName("Страна")]
+ public string Country { get; set; } = string.Empty;
+ }
+}
diff --git a/Bookshop/BookshopContracts/ViewModels/BookViewModel.cs b/Bookshop/BookshopContracts/ViewModels/BookViewModel.cs
new file mode 100644
index 0000000..7f0b142
--- /dev/null
+++ b/Bookshop/BookshopContracts/ViewModels/BookViewModel.cs
@@ -0,0 +1,21 @@
+using BookshopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.ViewModels
+{
+ public class BookViewModel : IBookModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Названик книги")]
+ public string Title { get; set; } = string.Empty;
+ [DisplayName("Год публикации")]
+ public int YearOfPublication { get; set; }
+ public int AuthorId { get; set; }
+ public int GenreId { get; set; }
+ }
+}
diff --git a/Bookshop/BookshopContracts/ViewModels/GenreViewModel.cs b/Bookshop/BookshopContracts/ViewModels/GenreViewModel.cs
new file mode 100644
index 0000000..cd8f048
--- /dev/null
+++ b/Bookshop/BookshopContracts/ViewModels/GenreViewModel.cs
@@ -0,0 +1,17 @@
+using BookshopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.ViewModels
+{
+ public class GenreViewModel : IGenreModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название жанра")]
+ public string GenreName { get; set; } = string.Empty;
+ }
+}
diff --git a/Bookshop/BookshopContracts/ViewModels/InstanceViewModel.cs b/Bookshop/BookshopContracts/ViewModels/InstanceViewModel.cs
new file mode 100644
index 0000000..4781cc9
--- /dev/null
+++ b/Bookshop/BookshopContracts/ViewModels/InstanceViewModel.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.ViewModels
+{
+ public class InstanceViewModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Наличие картинок")]
+ public bool Pictures { get; set; }
+ [DisplayName("Количество экземлпяров")]
+ public int StockQuantity { get; set; }
+ [DisplayName("Стоимость книги")]
+ public double Price { get; set; }
+ public int BookId { get; set; }
+ public int PublisherId { get; set; }
+ }
+}
diff --git a/Bookshop/BookshopContracts/ViewModels/OrderViewModel.cs b/Bookshop/BookshopContracts/ViewModels/OrderViewModel.cs
new file mode 100644
index 0000000..3f08d5c
--- /dev/null
+++ b/Bookshop/BookshopContracts/ViewModels/OrderViewModel.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.ViewModels
+{
+ public class OrderViewModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Дата заказа")]
+ public DateTime OrderDate { get; set; }
+ [DisplayName("Количество")]
+ public int Quantity { get; set; }
+ public int InstanceId { get; set; }
+ public int UserId { get; set; }
+ }
+}
diff --git a/Bookshop/BookshopContracts/ViewModels/PublisherViewModel.cs b/Bookshop/BookshopContracts/ViewModels/PublisherViewModel.cs
new file mode 100644
index 0000000..b3ef0df
--- /dev/null
+++ b/Bookshop/BookshopContracts/ViewModels/PublisherViewModel.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.ViewModels
+{
+ public class PublisherViewModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название издательства")]
+ public string PublisherName { get; set; } = string.Empty;
+ [DisplayName("Адресс издательства")]
+ public string Address { get; set; } = string.Empty;
+ [DisplayName("Номер телефона издательства")]
+ public string PhoneNumber { get; set; } = string.Empty;
+ [DisplayName("Электронная почта издательства")]
+ public string Email { get; set; } = string.Empty;
+ }
+}
diff --git a/Bookshop/BookshopContracts/ViewModels/ReviewViewModel.cs b/Bookshop/BookshopContracts/ViewModels/ReviewViewModel.cs
new file mode 100644
index 0000000..a7374d8
--- /dev/null
+++ b/Bookshop/BookshopContracts/ViewModels/ReviewViewModel.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.ViewModels
+{
+ public class ReviewViewModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Текст отзыва")]
+ public string ReviewText { get; set; } = string.Empty;
+ [DisplayName("Дата отзыва")]
+ public DateTime ReviewDate { get; set; }
+ public int InstanceId { get; set; }
+ public int UserId { get; set; }
+ }
+}
diff --git a/Bookshop/BookshopContracts/ViewModels/UserViewModel.cs b/Bookshop/BookshopContracts/ViewModels/UserViewModel.cs
new file mode 100644
index 0000000..fc84815
--- /dev/null
+++ b/Bookshop/BookshopContracts/ViewModels/UserViewModel.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BookshopContracts.ViewModels
+{
+ public class UserViewModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Имя пользователя")]
+ public string Username { get; set; } = string.Empty;
+ [DisplayName("Электронная почта пользователя")]
+ public string UserEmail { get; set; } = string.Empty;
+ }
+}
diff --git a/Bookshop/BookshopDataModels/Models/IUserModel.cs b/Bookshop/BookshopDataModels/Models/IUserModel.cs
index c6eea0a..082ad19 100644
--- a/Bookshop/BookshopDataModels/Models/IUserModel.cs
+++ b/Bookshop/BookshopDataModels/Models/IUserModel.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace BookshopDataModels.Models
{
- public interface IUserModel
+ public interface IUserModel : IId
{
string Username { get; }
string UserEmail { get; }
diff --git a/Bookshop/BookshopDatabaseImplement/BookshopDatabase.cs b/Bookshop/BookshopDatabaseImplement/BookshopDatabase.cs
new file mode 100644
index 0000000..9ea9693
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/BookshopDatabase.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore;
+using BookshopDatabaseImplement.Models;
+
+namespace BookshopDatabaseImplement
+{
+ public class BookshopDatabase : DbContext
+ {
+ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+ {
+ if (optionsBuilder.IsConfigured == false)
+ {
+ optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-0CI5KVE\SQLEXPRESS;Initial Catalog=BookshopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
+ }
+ base.OnConfiguring(optionsBuilder);
+ }
+ public virtual DbSet Authors { set; get; }
+ public virtual DbSet Books { set; get; }
+ public virtual DbSet Genres { set; get; }
+ public virtual DbSet Instances { set; get; }
+ public virtual DbSet Orders { set; get; }
+ public virtual DbSet Publishers { set; get; }
+ public virtual DbSet Reviews { set; get; }
+ public virtual DbSet Users { set; get; }
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/BookshopDatabaseImplement.csproj b/Bookshop/BookshopDatabaseImplement/BookshopDatabaseImplement.csproj
new file mode 100644
index 0000000..4973b71
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/BookshopDatabaseImplement.csproj
@@ -0,0 +1,23 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
diff --git a/Bookshop/BookshopDatabaseImplement/Implemets/AuthorStorage.cs b/Bookshop/BookshopDatabaseImplement/Implemets/AuthorStorage.cs
new file mode 100644
index 0000000..17af0c6
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Implemets/AuthorStorage.cs
@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.StorageContracts;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.BindingModels;
+using BookshopDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace BookshopDatabaseImplement.Implemets
+{
+ public class AuthorStorage : IAuthorStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new BookshopDatabase();
+ return context.Authors
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFilteredList(AuthorSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.AuthorName))
+ {
+ return new();
+ }
+ using var context = new BookshopDatabase();
+ return context.Authors
+ .Where(x => x.AuthorName.Contains(model.AuthorName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public AuthorViewModel? GetElement(AuthorSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.AuthorName) && string.IsNullOrEmpty(model.Country) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BookshopDatabase();
+ return context.Authors
+ .FirstOrDefault(x => x.Id.Equals(model.Id))
+ ?.GetViewModel;
+ }
+
+ public AuthorViewModel? Insert(AuthorBindingModel model)
+ {
+ var newAuthor = Author.Create(model);
+ if (newAuthor == null)
+ {
+ return null;
+ }
+ using var context = new BookshopDatabase();
+ context.Authors.Add(newAuthor);
+ context.SaveChanges();
+ return newAuthor.GetViewModel;
+ }
+
+ public AuthorViewModel? Update(AuthorBindingModel model)
+ {
+ using var context = new BookshopDatabase();
+ var client = context.Authors.FirstOrDefault(x => x.Id == model.Id);
+ if (client == null)
+ {
+ return null;
+ }
+ client.Update(model);
+ context.SaveChanges();
+ return client.GetViewModel;
+ }
+
+ public AuthorViewModel? Delete(AuthorBindingModel model)
+ {
+ using var context = new BookshopDatabase();
+ var element = context.Authors.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ context.Authors.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Implemets/BookStorage.cs b/Bookshop/BookshopDatabaseImplement/Implemets/BookStorage.cs
new file mode 100644
index 0000000..12e67ad
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Implemets/BookStorage.cs
@@ -0,0 +1,95 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.StorageContracts;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.BindingModels;
+using BookshopDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace BookshopDatabaseImplement.Implemets
+{
+ public class BookStorage : IBookStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new BookshopDatabase();
+ return context.Books
+ .Include(x => x.Author)
+ .Include(x => x.Genre)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFilteredList(BookSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.Title))
+ {
+ return new();
+ }
+ using var context = new BookshopDatabase();
+ return context.Books
+ .Include(x => x.Author)
+ .Include(x => x.Genre)
+ .Where(x => x.Title.Contains(model.Title))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public BookViewModel? GetElement(BookSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BookshopDatabase();
+ return context.Books
+ .Include(x => x.Author)
+ .Include(x => x.Genre)
+ .FirstOrDefault(x => x.Id.Equals(model.Id))
+ ?.GetViewModel;
+ }
+
+ public BookViewModel? Insert(BookBindingModel model)
+ {
+ var newBook = Book.Create(model);
+ if (newBook == null)
+ {
+ return null;
+ }
+ using var context = new BookshopDatabase();
+ context.Books.Add(newBook);
+ context.SaveChanges();
+ return newBook.GetViewModel;
+ }
+
+ public BookViewModel? Update(BookBindingModel model)
+ {
+ using var context = new BookshopDatabase();
+ var client = context.Books.FirstOrDefault(x => x.Id == model.Id);
+ if (client == null)
+ {
+ return null;
+ }
+ client.Update(model);
+ context.SaveChanges();
+ return client.GetViewModel;
+ }
+
+ public BookViewModel? Delete(BookBindingModel model)
+ {
+ using var context = new BookshopDatabase();
+ var element = context.Books.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ context.Books.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Implemets/GenreStorage.cs b/Bookshop/BookshopDatabaseImplement/Implemets/GenreStorage.cs
new file mode 100644
index 0000000..c95b992
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Implemets/GenreStorage.cs
@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.StorageContracts;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.BindingModels;
+using BookshopDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace BookshopDatabaseImplement.Implemets
+{
+ public class GenreStorage : IGenreStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new BookshopDatabase();
+ return context.Genres
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFilteredList(GenreSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.GenreName))
+ {
+ return new();
+ }
+ using var context = new BookshopDatabase();
+ return context.Genres
+ .Where(x => x.GenreName.Contains(model.GenreName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public GenreViewModel? GetElement(GenreSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.GenreName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BookshopDatabase();
+ return context.Genres
+ .FirstOrDefault(x => x.Id.Equals(model.Id))
+ ?.GetViewModel;
+ }
+
+ public GenreViewModel? Insert(GenreBindingModel model)
+ {
+ var newGenre = Genre.Create(model);
+ if (newGenre == null)
+ {
+ return null;
+ }
+ using var context = new BookshopDatabase();
+ context.Genres.Add(newGenre);
+ context.SaveChanges();
+ return newGenre.GetViewModel;
+ }
+
+ public GenreViewModel? Update(GenreBindingModel model)
+ {
+ using var context = new BookshopDatabase();
+ var client = context.Genres.FirstOrDefault(x => x.Id == model.Id);
+ if (client == null)
+ {
+ return null;
+ }
+ client.Update(model);
+ context.SaveChanges();
+ return client.GetViewModel;
+ }
+
+ public GenreViewModel? Delete(GenreBindingModel model)
+ {
+ using var context = new BookshopDatabase();
+ var element = context.Genres.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ context.Genres.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Implemets/InstanceStorage.cs b/Bookshop/BookshopDatabaseImplement/Implemets/InstanceStorage.cs
new file mode 100644
index 0000000..9354cb2
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Implemets/InstanceStorage.cs
@@ -0,0 +1,95 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.StorageContracts;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.BindingModels;
+using BookshopDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace BookshopDatabaseImplement.Implemets
+{
+ public class InstanceStorage : IInstanceStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new BookshopDatabase();
+ return context.Instances
+ .Include(x => x.Book)
+ .Include(x => x.Publisher)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFilteredList(InstanceSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.Title))
+ {
+ return new();
+ }
+ using var context = new BookshopDatabase();
+ return context.Instances
+ .Include(x => x.Author)
+ .Include(x => x.Genre)
+ .Where(x => x.Title.Contains(model.Title))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public InstanceViewModel? GetElement(InstanceSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BookshopDatabase();
+ return context.Instances
+ .Include(x => x.Author)
+ .Include(x => x.Genre)
+ .FirstOrDefault(x => x.Id.Equals(model.Id))
+ ?.GetViewModel;
+ }
+
+ public InstanceViewModel? Insert(InstanceBindingModel model)
+ {
+ var newInstance = Instance.Create(model);
+ if (newInstance == null)
+ {
+ return null;
+ }
+ using var context = new BookshopDatabase();
+ context.Instances.Add(newInstance);
+ context.SaveChanges();
+ return newInstance.GetViewModel;
+ }
+
+ public InstanceViewModel? Update(InstanceBindingModel model)
+ {
+ using var context = new BookshopDatabase();
+ var client = context.Instances.FirstOrDefault(x => x.Id == model.Id);
+ if (client == null)
+ {
+ return null;
+ }
+ client.Update(model);
+ context.SaveChanges();
+ return client.GetViewModel;
+ }
+
+ public InstanceViewModel? Delete(InstanceBindingModel model)
+ {
+ using var context = new BookshopDatabase();
+ var element = context.Instances.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ context.Instances.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Implemets/OrderStorage.cs b/Bookshop/BookshopDatabaseImplement/Implemets/OrderStorage.cs
new file mode 100644
index 0000000..fb3f6f3
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Implemets/OrderStorage.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.StorageContracts;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.BindingModels;
+using BookshopDatabaseImplement.Models;
+
+namespace BookshopDatabaseImplement.Implemets
+{
+ internal class OrderStorage
+ {
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Implemets/PublisherStorage.cs b/Bookshop/BookshopDatabaseImplement/Implemets/PublisherStorage.cs
new file mode 100644
index 0000000..09a8c0b
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Implemets/PublisherStorage.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.StorageContracts;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.BindingModels;
+using BookshopDatabaseImplement.Models;
+
+namespace BookshopDatabaseImplement.Implemets
+{
+ internal class PublisherStorage
+ {
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Implemets/ReviewStorage.cs b/Bookshop/BookshopDatabaseImplement/Implemets/ReviewStorage.cs
new file mode 100644
index 0000000..73bc7a1
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Implemets/ReviewStorage.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.StorageContracts;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.BindingModels;
+using BookshopDatabaseImplement.Models;
+
+namespace BookshopDatabaseImplement.Implemets
+{
+ internal class ReviewStorage
+ {
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Implemets/UserStorage.cs b/Bookshop/BookshopDatabaseImplement/Implemets/UserStorage.cs
new file mode 100644
index 0000000..390c631
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Implemets/UserStorage.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BookshopContracts.StorageContracts;
+using BookshopContracts.ViewModels;
+using BookshopContracts.SearchModels;
+using BookshopContracts.BindingModels;
+using BookshopDatabaseImplement.Models;
+
+namespace BookshopDatabaseImplement.Implemets
+{
+ internal class UserStorage
+ {
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Models/Author.cs b/Bookshop/BookshopDatabaseImplement/Models/Author.cs
new file mode 100644
index 0000000..fd6dbf7
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Models/Author.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations.Schema;
+using BookshopDataModels.Models;
+using System.ComponentModel.DataAnnotations;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+
+namespace BookshopDatabaseImplement.Models
+{
+ public class Author : IAuthorModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public string AuthorName { get; private set; } = string.Empty;
+ [Required]
+ public string Country { get; private set; } = string.Empty;
+ public static Author? Create(AuthorBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ AuthorName = model.AuthorName,
+ Country = model.Country,
+ };
+ }
+ public void Update(AuthorBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ AuthorName = model.AuthorName;
+ Country = model.Country;
+ }
+ public AuthorViewModel GetViewModel => new()
+ {
+ Id = Id,
+ AuthorName = AuthorName,
+ Country = Country
+ };
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Models/Book.cs b/Bookshop/BookshopDatabaseImplement/Models/Book.cs
new file mode 100644
index 0000000..b8b281d
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Models/Book.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations.Schema;
+using BookshopDataModels.Models;
+using System.ComponentModel.DataAnnotations;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using System.Diagnostics.Metrics;
+
+namespace BookshopDatabaseImplement.Models
+{
+ public class Book : IBookModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public string Title { get; private set; } = string.Empty;
+ [Required]
+ public int YearOfPublication { get; private set; }
+ [ForeignKey("AuthorId")]
+ public int AuthorId { get; private set; }
+ public virtual Author Author { get; private set; } = new();
+ [ForeignKey("GenreId")]
+ public int GenreId { get; private set; }
+ public virtual Genre Genre { get; private set; } = new();
+ public static Book? Create(BookBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Title = model.Title,
+ YearOfPublication = model.YearOfPublication,
+ AuthorId = model.AuthorId,
+ GenreId = model.GenreId,
+ };
+ }
+ public void Update(BookBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Title = model.Title;
+ YearOfPublication = model.YearOfPublication;
+ AuthorId = model.AuthorId;
+ GenreId = model.GenreId;
+ }
+ public BookViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Title = Title,
+ YearOfPublication = YearOfPublication,
+ AuthorId = AuthorId,
+ GenreId = GenreId,
+ };
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Models/Genre.cs b/Bookshop/BookshopDatabaseImplement/Models/Genre.cs
new file mode 100644
index 0000000..7a030fc
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Models/Genre.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations.Schema;
+using BookshopDataModels.Models;
+using System.ComponentModel.DataAnnotations;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+
+namespace BookshopDatabaseImplement.Models
+{
+ public class Genre : IGenreModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public string GenreName { get; private set; } = string.Empty;
+ public static Genre? Create(GenreBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ GenreName = model.GenreName,
+ };
+ }
+ public void Update(GenreBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ GenreName = model.GenreName;
+ }
+ public GenreViewModel GetViewModel => new()
+ {
+ Id = Id,
+ GenreName = GenreName,
+ };
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Models/Instance.cs b/Bookshop/BookshopDatabaseImplement/Models/Instance.cs
new file mode 100644
index 0000000..42f94bc
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Models/Instance.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations.Schema;
+using BookshopDataModels.Models;
+using System.ComponentModel.DataAnnotations;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using System.Diagnostics.Metrics;
+
+namespace BookshopDatabaseImplement.Models
+{
+ public class Instance : IInstanceModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public bool Pictures { get; private set; }
+ [Required]
+ public int StockQuantity { get; private set; }
+ [Required]
+ public double Price { get; private set; }
+ [ForeignKey("BookId")]
+ public int BookId { get; private set; }
+ public virtual Book Book { get; private set; } = new();
+ [ForeignKey("PublisherId")]
+ public int PublisherId { get; private set; }
+ public virtual Publisher Publisher { get; private set; } = new();
+ public static Instance? Create(InstanceBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Pictures = model.Pictures,
+ StockQuantity = model.StockQuantity,
+ Price = model.Price,
+ BookId = model.BookId,
+ PublisherId = model.PublisherId
+ };
+ }
+ public void Update(InstanceBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Pictures = model.Pictures;
+ StockQuantity = model.StockQuantity;
+ Price = model.Price;
+ BookId = model.BookId;
+ PublisherId = model.PublisherId;
+ }
+ public InstanceViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Pictures = Pictures,
+ StockQuantity = StockQuantity,
+ Price = Price,
+ BookId = BookId,
+ PublisherId=PublisherId
+ };
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Models/Order.cs b/Bookshop/BookshopDatabaseImplement/Models/Order.cs
new file mode 100644
index 0000000..38d0990
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Models/Order.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations.Schema;
+using BookshopDataModels.Models;
+using System.ComponentModel.DataAnnotations;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using System.Diagnostics;
+using System.Net;
+
+namespace BookshopDatabaseImplement.Models
+{
+ public class Order : IOrderModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public DateTime OrderDate { get; private set; }
+ [Required]
+ public int Quantity { get; private set; }
+ [ForeignKey("InstanceId")]
+ public int InstanceId { get; private set; }
+ public virtual Instance Instance { get; private set; } = new();
+ [ForeignKey("UserId")]
+ public int UserId { get; private set; }
+ public virtual User User { get; private set; } = new();
+ public static Order? Create(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ OrderDate = model.OrderDate,
+ Quantity = model.Quantity,
+ InstanceId = model.InstanceId,
+ UserId = model.UserId
+ };
+ }
+ public void Update(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ OrderDate = model.OrderDate;
+ Quantity = model.Quantity;
+ InstanceId = model.InstanceId;
+ UserId = model.UserId;
+ }
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ OrderDate = OrderDate,
+ Quantity = Quantity,
+ InstanceId = InstanceId,
+ UserId = UserId
+ };
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Models/Publisher.cs b/Bookshop/BookshopDatabaseImplement/Models/Publisher.cs
new file mode 100644
index 0000000..0696bf5
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Models/Publisher.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations.Schema;
+using BookshopDataModels.Models;
+using System.ComponentModel.DataAnnotations;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+
+namespace BookshopDatabaseImplement.Models
+{
+ public class Publisher : IPublisherModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public string PublisherName { get; private set; } = string.Empty;
+ [Required]
+ public string Address { get; private set; } = string.Empty;
+ [Required]
+ public string PhoneNumber { get; private set; } = string.Empty;
+ [Required]
+ public string Email { get; private set; } = string.Empty;
+ public static Publisher? Create(PublisherBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ PublisherName = model.PublisherName,
+ Address = model.Address,
+ PhoneNumber = model.PhoneNumber,
+ Email = model.Email,
+ };
+ }
+ public void Update(PublisherBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ PublisherName = model.PublisherName;
+ Address = model.Address;
+ PhoneNumber = model.PhoneNumber;
+ Email = model.Email;
+ }
+ public PublisherViewModel GetViewModel => new()
+ {
+ Id = Id,
+ PublisherName = PublisherName,
+ Address = Address,
+ PhoneNumber = PhoneNumber,
+ Email = Email,
+ };
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Models/Review.cs b/Bookshop/BookshopDatabaseImplement/Models/Review.cs
new file mode 100644
index 0000000..5d14292
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Models/Review.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations.Schema;
+using BookshopDataModels.Models;
+using System.ComponentModel.DataAnnotations;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+using System.Net;
+
+namespace BookshopDatabaseImplement.Models
+{
+ public class Review : IReviewModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public string ReviewText { get; private set; } = string.Empty;
+ [Required]
+ public DateTime ReviewDate { get; private set; }
+ [ForeignKey("InstanceId")]
+ public int InstanceId { get; private set; }
+ public virtual Instance Instance { get; private set; } = new();
+ [ForeignKey("UserId")]
+ public int UserId { get; private set; }
+ public virtual User User { get; private set; } = new();
+ public static Review? Create(ReviewBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ ReviewText = model.ReviewText,
+ ReviewDate = model.ReviewDate,
+ InstanceId = model.InstanceId,
+ UserId = model.UserId,
+ };
+ }
+ public void Update(ReviewBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ReviewText = model.ReviewText;
+ ReviewDate = model.ReviewDate;
+ InstanceId = model.InstanceId;
+ UserId = model.UserId;
+ }
+ public ReviewViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ReviewText = ReviewText,
+ ReviewDate = ReviewDate,
+ InstanceId = InstanceId,
+ UserId = UserId
+ };
+ }
+}
diff --git a/Bookshop/BookshopDatabaseImplement/Models/User.cs b/Bookshop/BookshopDatabaseImplement/Models/User.cs
new file mode 100644
index 0000000..ef711f4
--- /dev/null
+++ b/Bookshop/BookshopDatabaseImplement/Models/User.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations.Schema;
+using BookshopDataModels.Models;
+using System.ComponentModel.DataAnnotations;
+using BookshopContracts.BindingModels;
+using BookshopContracts.ViewModels;
+
+namespace BookshopDatabaseImplement.Models
+{
+ public class User : IUserModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public string Username { get; private set; } = string.Empty;
+ [Required]
+ public string UserEmail { get; private set; } = string.Empty;
+ public static User? Create(UserBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Username = model.Username,
+ UserEmail = model.UserEmail,
+ };
+ }
+ public void Update(UserBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Username = model.Username;
+ UserEmail = model.UserEmail;
+ }
+ public UserViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Username = Username,
+ UserEmail = UserEmail,
+ };
+ }
+}