что то делается

This commit is contained in:
Полина Чубыкина 2024-05-21 20:38:30 +04:00
parent a983eba249
commit 9e8e7a4f0e
62 changed files with 2386 additions and 11 deletions

View File

@ -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

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BookshopContracts\BookshopContracts.csproj" />
<ProjectReference Include="..\BookshopDataModels\BookshopDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -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<AuthorLogic> logger, IAuthorStorage AuthorStorage)
{
_logger = logger;
_AuthorStorage = AuthorStorage;
}
public List<AuthorViewModel>? 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("Такой автор уже существует");
}
}
}
}

View File

@ -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<BookLogic> logger, IBookStorage BookStorage)
{
_logger = logger;
_BookStorage = BookStorage;
}
public List<BookViewModel>? 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("Компонент с таким названием уже есть");
}
}
}
}

View File

@ -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<GenreLogic> logger, IGenreStorage GenreStorage)
{
_logger = logger;
_GenreStorage = GenreStorage;
}
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 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("Компонент с таким названием уже есть");
}
}
}
}

View File

@ -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<InstanceLogic> logger, IInstanceStorage InstanceStorage)
{
_logger = logger;
_InstanceStorage = InstanceStorage;
}
public List<InstanceViewModel>? 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);
}
}
}

View File

@ -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<OrderLogic> logger, IOrderStorage OrderStorage)
{
_logger = logger;
_OrderStorage = OrderStorage;
}
public List<OrderViewModel>? 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);
}
}
}

View File

@ -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<PublisherLogic> logger, IPublisherStorage PublisherStorage)
{
_logger = logger;
_PublisherStorage = PublisherStorage;
}
public List<PublisherViewModel>? 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("Издательство с таким названием уже есть");
}
}
}
}

View File

@ -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<ReviewLogic> logger, IReviewStorage ReviewStorage)
{
_logger = logger;
_ReviewStorage = ReviewStorage;
}
public List<ReviewViewModel>? 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);
}
}
}

View File

@ -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<UserLogic> logger, IUserStorage UserStorage)
{
_logger = logger;
_UserStorage = UserStorage;
}
public List<UserViewModel>? 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("Пользователь с такой почтой уже есть");
}
}
}
}

View File

@ -6,11 +6,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="SearchModel\" />
<Folder Include="ViewModels\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BookshopDataModels\BookshopDataModels.csproj" />
</ItemGroup>

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -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;
}
}

View File

@ -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<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

@ -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<BookViewModel> GetFullList();
List<BookViewModel> GetFilteredList(BookSearchModel model);
BookViewModel? GetElement(BookSearchModel model);
BookViewModel? Insert(BookBindingModel model);
BookViewModel? Update(BookBindingModel model);
BookViewModel? Delete(BookBindingModel model);
}
}

View File

@ -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<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,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<InstanceViewModel> GetFullList();
List<InstanceViewModel> GetFilteredList(InstanceSearchModel model);
InstanceViewModel? GetElement(InstanceSearchModel model);
InstanceViewModel? Insert(InstanceBindingModel model);
InstanceViewModel? Update(InstanceBindingModel model);
InstanceViewModel? Delete(InstanceBindingModel model);
}
}

View File

@ -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<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
}
}

View File

@ -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<PublisherViewModel> GetFullList();
List<PublisherViewModel> GetFilteredList(PublisherSearchModel model);
PublisherViewModel? GetElement(PublisherSearchModel model);
PublisherViewModel? Insert(PublisherBindingModel model);
PublisherViewModel? Update(PublisherBindingModel model);
PublisherViewModel? Delete(PublisherBindingModel model);
}
}

View File

@ -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<ReviewViewModel> GetFullList();
List<ReviewViewModel> GetFilteredList(ReviewSearchModel model);
ReviewViewModel? GetElement(ReviewSearchModel model);
ReviewViewModel? Insert(ReviewBindingModel model);
ReviewViewModel? Update(ReviewBindingModel model);
ReviewViewModel? Delete(ReviewBindingModel model);
}
}

View File

@ -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<UserViewModel> GetFullList();
List<UserViewModel> GetFilteredList(UserSearchModel model);
UserViewModel? GetElement(UserSearchModel model);
UserViewModel? Insert(UserBindingModel model);
UserViewModel? Update(UserBindingModel model);
UserViewModel? Delete(UserBindingModel model);
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -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;
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace BookshopDataModels.Models
{
public interface IUserModel
public interface IUserModel : IId
{
string Username { get; }
string UserEmail { get; }

View File

@ -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<Author> Authors { set; get; }
public virtual DbSet<Book> Books { set; get; }
public virtual DbSet<Genre> Genres { set; get; }
public virtual DbSet<Instance> Instances { set; get; }
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Publisher> Publishers { set; get; }
public virtual DbSet<Review> Reviews { set; get; }
public virtual DbSet<User> Users { set; get; }
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.19" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.19" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.19">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BookshopContracts\BookshopContracts.csproj" />
<ProjectReference Include="..\BookshopDataModels\BookshopDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -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<AuthorViewModel> GetFullList()
{
using var context = new BookshopDatabase();
return context.Authors
.Select(x => x.GetViewModel)
.ToList();
}
public List<AuthorViewModel> 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;
}
}
}

View File

@ -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<BookViewModel> GetFullList()
{
using var context = new BookshopDatabase();
return context.Books
.Include(x => x.Author)
.Include(x => x.Genre)
.Select(x => x.GetViewModel)
.ToList();
}
public List<BookViewModel> 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;
}
}
}

View File

@ -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<GenreViewModel> GetFullList()
{
using var context = new BookshopDatabase();
return context.Genres
.Select(x => x.GetViewModel)
.ToList();
}
public List<GenreViewModel> 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;
}
}
}

View File

@ -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<InstanceViewModel> GetFullList()
{
using var context = new BookshopDatabase();
return context.Instances
.Include(x => x.Book)
.Include(x => x.Publisher)
.Select(x => x.GetViewModel)
.ToList();
}
public List<InstanceViewModel> 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;
}
}
}

View File

@ -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
{
}
}

View File

@ -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
{
}
}

View File

@ -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
{
}
}

View File

@ -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
{
}
}

View File

@ -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
};
}
}

View File

@ -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,
};
}
}

View File

@ -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,
};
}
}

View File

@ -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
};
}
}

View File

@ -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
};
}
}

View File

@ -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,
};
}
}

View File

@ -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
};
}
}

View File

@ -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,
};
}
}