Compare commits
No commits in common. "main" and "15ae70574d9fada7702b8f7ac4ea93c916497c0f" have entirely different histories.
main
...
15ae70574d
63
.gitattributes
vendored
Normal file
63
.gitattributes
vendored
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
###############################################################################
|
||||||
|
# Set default behavior to automatically normalize line endings.
|
||||||
|
###############################################################################
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Set default behavior for command prompt diff.
|
||||||
|
#
|
||||||
|
# This is need for earlier builds of msysgit that does not have it on by
|
||||||
|
# default for csharp files.
|
||||||
|
# Note: This is only used by command line
|
||||||
|
###############################################################################
|
||||||
|
#*.cs diff=csharp
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Set the merge driver for project and solution files
|
||||||
|
#
|
||||||
|
# Merging from the command prompt will add diff markers to the files if there
|
||||||
|
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||||
|
# the diff markers are never inserted). Diff markers may cause the following
|
||||||
|
# file extensions to fail to load in VS. An alternative would be to treat
|
||||||
|
# these files as binary and thus will always conflict and require user
|
||||||
|
# intervention with every merge. To do so, just uncomment the entries below
|
||||||
|
###############################################################################
|
||||||
|
#*.sln merge=binary
|
||||||
|
#*.csproj merge=binary
|
||||||
|
#*.vbproj merge=binary
|
||||||
|
#*.vcxproj merge=binary
|
||||||
|
#*.vcproj merge=binary
|
||||||
|
#*.dbproj merge=binary
|
||||||
|
#*.fsproj merge=binary
|
||||||
|
#*.lsproj merge=binary
|
||||||
|
#*.wixproj merge=binary
|
||||||
|
#*.modelproj merge=binary
|
||||||
|
#*.sqlproj merge=binary
|
||||||
|
#*.wwaproj merge=binary
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# behavior for image files
|
||||||
|
#
|
||||||
|
# image files are treated as binary by default.
|
||||||
|
###############################################################################
|
||||||
|
#*.jpg binary
|
||||||
|
#*.png binary
|
||||||
|
#*.gif binary
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# diff behavior for common document formats
|
||||||
|
#
|
||||||
|
# Convert binary document formats to text before diffing them. This feature
|
||||||
|
# is only available from the command line. Turn it on by uncommenting the
|
||||||
|
# entries below.
|
||||||
|
###############################################################################
|
||||||
|
#*.doc diff=astextplain
|
||||||
|
#*.DOC diff=astextplain
|
||||||
|
#*.docx diff=astextplain
|
||||||
|
#*.DOCX diff=astextplain
|
||||||
|
#*.dot diff=astextplain
|
||||||
|
#*.DOT diff=astextplain
|
||||||
|
#*.pdf diff=astextplain
|
||||||
|
#*.PDF diff=astextplain
|
||||||
|
#*.rtf diff=astextplain
|
||||||
|
#*.RTF diff=astextplain
|
363
.gitignore
vendored
Normal file
363
.gitignore
vendored
Normal file
@ -0,0 +1,363 @@
|
|||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Oo]ut/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
13
BookBusinessLogic/BookBusinessLogic.csproj
Normal file
13
BookBusinessLogic/BookBusinessLogic.csproj
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BookContract\BookContract.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
61
BookBusinessLogic/BusinessLogic/BookLogic.cs
Normal file
61
BookBusinessLogic/BusinessLogic/BookLogic.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.BusinessLogicContracts;
|
||||||
|
using BookContract.StorageContracts;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookBusinessLogic.BusinessLogic
|
||||||
|
{
|
||||||
|
public class BookLogic : IBookLogic
|
||||||
|
{
|
||||||
|
private readonly IBookStorage _bookStorage;
|
||||||
|
|
||||||
|
public BookLogic(IBookStorage bookStorage)
|
||||||
|
{
|
||||||
|
_bookStorage = bookStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateOrUpdate(BookBindingModel model)
|
||||||
|
{
|
||||||
|
var element = _bookStorage.GetElement(new BookBindingModel { Title = model.Title });
|
||||||
|
if (element != null && element.Id != model.Id) {
|
||||||
|
throw new Exception("Книги с таким названием тут нет");
|
||||||
|
}
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
_bookStorage.Update(model);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_bookStorage.Insert(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(BookBindingModel model)
|
||||||
|
{
|
||||||
|
var element = _bookStorage.GetElement(new BookBindingModel { Title = model.Title });
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Книги с таким названием тут нет");
|
||||||
|
}
|
||||||
|
_bookStorage.Delete(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BookViewModel> Read(BookBindingModel model)
|
||||||
|
{
|
||||||
|
if(model == null)
|
||||||
|
return _bookStorage.GetFullList();
|
||||||
|
if (model.Id.HasValue) {
|
||||||
|
return new List<BookViewModel> {
|
||||||
|
_bookStorage.GetElement(model)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return _bookStorage.GetFullList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
66
BookBusinessLogic/BusinessLogic/HistoryLogic.cs
Normal file
66
BookBusinessLogic/BusinessLogic/HistoryLogic.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.BusinessLogicContracts;
|
||||||
|
using BookContract.StorageContracts;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookBusinessLogic.BusinessLogic
|
||||||
|
{
|
||||||
|
public class HistoryLogic : IHistoryLogic
|
||||||
|
{
|
||||||
|
private readonly IHistoryStorage _historyStorage;
|
||||||
|
|
||||||
|
public HistoryLogic(IHistoryStorage historyStorage)
|
||||||
|
{
|
||||||
|
_historyStorage = historyStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HistoryViewModel> Read(HistoryBindingModel model)
|
||||||
|
{
|
||||||
|
if(model == null)
|
||||||
|
{
|
||||||
|
return _historyStorage.GetFullList();
|
||||||
|
}
|
||||||
|
if (model.Id.HasValue) {
|
||||||
|
return new List<HistoryViewModel>
|
||||||
|
{
|
||||||
|
_historyStorage.GetElement(model)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return _historyStorage.GetHistoryByBookId(model.BookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateOrUpdate(HistoryBindingModel model)
|
||||||
|
{
|
||||||
|
var element = _historyStorage.GetElement(
|
||||||
|
new HistoryBindingModel
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new Exception("Такая связь уже существует");
|
||||||
|
}
|
||||||
|
_historyStorage.Insert(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(HistoryBindingModel model)
|
||||||
|
{
|
||||||
|
var element = _historyStorage.GetElement(new HistoryBindingModel
|
||||||
|
{
|
||||||
|
Id = model.Id
|
||||||
|
});
|
||||||
|
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Навык не найден");
|
||||||
|
}
|
||||||
|
|
||||||
|
_historyStorage.Delete(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
62
BookBusinessLogic/BusinessLogic/ReaderLogic.cs
Normal file
62
BookBusinessLogic/BusinessLogic/ReaderLogic.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.BusinessLogicContracts;
|
||||||
|
using BookContract.StorageContracts;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookBusinessLogic.BusinessLogic
|
||||||
|
{
|
||||||
|
public class ReaderLogic : IReaderLogic
|
||||||
|
{
|
||||||
|
private readonly IReaderStorage _readerStorage;
|
||||||
|
|
||||||
|
public ReaderLogic(IReaderStorage readerStorage)
|
||||||
|
{
|
||||||
|
_readerStorage = readerStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateOrUpdate(ReaderBindingModel model)
|
||||||
|
{
|
||||||
|
var element = _readerStorage.GetElement(new ReaderBindingModel { Name = model.Name });
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new Exception("Книги с таким названием тут нет");
|
||||||
|
}
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
_readerStorage.Update(model);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_readerStorage.Insert(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(ReaderBindingModel model)
|
||||||
|
{
|
||||||
|
var element = _readerStorage.GetElement(new ReaderBindingModel { Name = model.Name });
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Книги с таким названием тут нет");
|
||||||
|
}
|
||||||
|
_readerStorage.Delete(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReaderViewModel> Read(ReaderBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
return _readerStorage.GetFullList();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new List<ReaderViewModel> {
|
||||||
|
_readerStorage.GetElement(model)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return _readerStorage.GetFullList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
BookContract/BindingModels/BookBindingModel.cs
Normal file
17
BookContract/BindingModels/BookBindingModel.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.BindingModels
|
||||||
|
{
|
||||||
|
public class BookBindingModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string BookType { get; set; } = string.Empty;
|
||||||
|
public string Annotation { get; set; } = string.Empty;
|
||||||
|
public List<int> ReaderIds { get; set; } = new List<int>();
|
||||||
|
}
|
||||||
|
}
|
16
BookContract/BindingModels/HistoryBindingModel.cs
Normal file
16
BookContract/BindingModels/HistoryBindingModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.BindingModels
|
||||||
|
{
|
||||||
|
public class HistoryBindingModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public int BookId { get; set; }
|
||||||
|
public int ReaderId { get; set; }
|
||||||
|
public DateTime DateBorrowed { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
BookContract/BindingModels/ReaderBindingModel.cs
Normal file
14
BookContract/BindingModels/ReaderBindingModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.BindingModels
|
||||||
|
{
|
||||||
|
public class ReaderBindingModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
16
BookContract/BookContract.csproj
Normal file
16
BookContract/BookContract.csproj
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
19
BookContract/BusinessLogicContracts/IBookLogic.cs
Normal file
19
BookContract/BusinessLogicContracts/IBookLogic.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.BusinessLogicContracts
|
||||||
|
{
|
||||||
|
public interface IBookLogic
|
||||||
|
{
|
||||||
|
List<BookViewModel> Read(BookBindingModel model);
|
||||||
|
|
||||||
|
void CreateOrUpdate(BookBindingModel model);
|
||||||
|
|
||||||
|
void Delete(BookBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
19
BookContract/BusinessLogicContracts/IHistoryLogic.cs
Normal file
19
BookContract/BusinessLogicContracts/IHistoryLogic.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.BusinessLogicContracts
|
||||||
|
{
|
||||||
|
public interface IHistoryLogic
|
||||||
|
{
|
||||||
|
List<HistoryViewModel> Read(HistoryBindingModel model);
|
||||||
|
|
||||||
|
void CreateOrUpdate(HistoryBindingModel model);
|
||||||
|
|
||||||
|
void Delete(HistoryBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
19
BookContract/BusinessLogicContracts/IReaderLogic.cs
Normal file
19
BookContract/BusinessLogicContracts/IReaderLogic.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.BusinessLogicContracts
|
||||||
|
{
|
||||||
|
public interface IReaderLogic
|
||||||
|
{
|
||||||
|
List<ReaderViewModel> Read(ReaderBindingModel model);
|
||||||
|
|
||||||
|
void CreateOrUpdate(ReaderBindingModel model);
|
||||||
|
|
||||||
|
void Delete(ReaderBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
20
BookContract/StorageContracts/IBookStorage.cs
Normal file
20
BookContract/StorageContracts/IBookStorage.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.StorageContracts
|
||||||
|
{
|
||||||
|
public interface IBookStorage
|
||||||
|
{
|
||||||
|
List<BookViewModel> GetFullList();
|
||||||
|
List<BookViewModel> GetFilterList(BookBindingModel model);
|
||||||
|
BookViewModel GetElement(BookBindingModel model);
|
||||||
|
void Insert(BookBindingModel model);
|
||||||
|
void Update(BookBindingModel model);
|
||||||
|
void Delete(BookBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
19
BookContract/StorageContracts/IHistoryStorage.cs
Normal file
19
BookContract/StorageContracts/IHistoryStorage.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.StorageContracts
|
||||||
|
{
|
||||||
|
public interface IHistoryStorage
|
||||||
|
{
|
||||||
|
HistoryViewModel GetElement(HistoryBindingModel model);
|
||||||
|
List<HistoryViewModel> GetFullList();
|
||||||
|
List<HistoryViewModel> GetHistoryByBookId(int bookId);
|
||||||
|
void Insert(HistoryBindingModel model);
|
||||||
|
void Delete(HistoryBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
20
BookContract/StorageContracts/IReaderStorage.cs
Normal file
20
BookContract/StorageContracts/IReaderStorage.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.StorageContracts
|
||||||
|
{
|
||||||
|
public interface IReaderStorage
|
||||||
|
{
|
||||||
|
List<ReaderViewModel> GetFullList();
|
||||||
|
List<ReaderViewModel> GetFilterList(ReaderBindingModel model);
|
||||||
|
ReaderViewModel GetElement(ReaderBindingModel model);
|
||||||
|
void Insert(ReaderBindingModel model);
|
||||||
|
void Update(ReaderBindingModel model);
|
||||||
|
void Delete(ReaderBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
17
BookContract/ViewModels/BookViewModel.cs
Normal file
17
BookContract/ViewModels/BookViewModel.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.ViewModels
|
||||||
|
{
|
||||||
|
public class BookViewModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string BookType { get; set; } = string.Empty;
|
||||||
|
public string Annotation { get; set; } = string.Empty;
|
||||||
|
public List<ReaderViewModel> LastReaders { get; set; } = new List<ReaderViewModel>();
|
||||||
|
}
|
||||||
|
}
|
16
BookContract/ViewModels/HistoryViewModel.cs
Normal file
16
BookContract/ViewModels/HistoryViewModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.ViewModels
|
||||||
|
{
|
||||||
|
public class HistoryViewModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int BookId { get; set; }
|
||||||
|
public int ReaderId { get; set; }
|
||||||
|
public DateTime DateBorrowed { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
BookContract/ViewModels/ReaderViewModel.cs
Normal file
14
BookContract/ViewModels/ReaderViewModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookContract.ViewModels
|
||||||
|
{
|
||||||
|
public class ReaderViewModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
27
BookDatabaseImplement/BookDatabaseImplement.csproj
Normal file
27
BookDatabaseImplement/BookDatabaseImplement.csproj
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Npgsql" Version="8.0.5" />
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BookContract\BookContract.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
28
BookDatabaseImplement/BookLibraryDatabase .cs
Normal file
28
BookDatabaseImplement/BookLibraryDatabase .cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using BookDatabaseImplement.Model;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookDatabaseImplement
|
||||||
|
{
|
||||||
|
public class BookLibraryDatabase : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=BookLibrary_db;Username=postgres;Password=password");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||||
|
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||||
|
}
|
||||||
|
public virtual DbSet<Book> Books { get; set; }
|
||||||
|
public virtual DbSet<Reader> Readers { get; set; }
|
||||||
|
public virtual DbSet<History> Histories { get; set; }
|
||||||
|
}
|
||||||
|
}
|
126
BookDatabaseImplement/Implements/BookStorage.cs
Normal file
126
BookDatabaseImplement/Implements/BookStorage.cs
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.StorageContracts;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using BookDatabaseImplement.Model;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class BookStorage : IBookStorage
|
||||||
|
{
|
||||||
|
private Book CreateModel(BookBindingModel model, Book book)
|
||||||
|
{
|
||||||
|
book.Title = model.Title;
|
||||||
|
book.BookType = model.BookType;
|
||||||
|
book.Annotation = model.Annotation;
|
||||||
|
|
||||||
|
return book;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BookViewModel CreateModel(Book book)
|
||||||
|
{
|
||||||
|
return new BookViewModel
|
||||||
|
{
|
||||||
|
Id = book.Id,
|
||||||
|
Title = book.Title,
|
||||||
|
BookType = book.BookType,
|
||||||
|
Annotation = book.Annotation,
|
||||||
|
LastReaders = book.LastReaders
|
||||||
|
.OrderByDescending(h => h.DateBorrowed)
|
||||||
|
.Select(h => new ReaderViewModel
|
||||||
|
{
|
||||||
|
Id = h.Reader.Id,
|
||||||
|
Name = h.Reader.Name
|
||||||
|
})
|
||||||
|
.Take(6)
|
||||||
|
.ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BookViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
return context.Books
|
||||||
|
.Include(b => b.LastReaders)
|
||||||
|
.ThenInclude(h => h.Reader)
|
||||||
|
.ToList()
|
||||||
|
.Select(CreateModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BookViewModel> GetFilterList(BookBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
return context.Books
|
||||||
|
.Where(book => book.BookType.Contains(model.BookType))
|
||||||
|
.ToList().Select(CreateModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookViewModel? GetElement(BookBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
var book = context.Books.FirstOrDefault(rec => rec.Id == model.Id || rec.Title == model.Title);
|
||||||
|
return book != null ? CreateModel(book) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Insert(BookBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
context.Books.Add(CreateModel(model, new Book()));
|
||||||
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(BookBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var book = context.Books.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (book == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Книга не найдена");
|
||||||
|
}
|
||||||
|
CreateModel(model, book);
|
||||||
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(BookBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
var book = context.Books.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
|
||||||
|
if (book != null)
|
||||||
|
{
|
||||||
|
context.Books.Remove(book);
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Книга не найдена");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
87
BookDatabaseImplement/Implements/HistoryStorage.cs
Normal file
87
BookDatabaseImplement/Implements/HistoryStorage.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.StorageContracts;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using BookDatabaseImplement.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class HistoryStorage : IHistoryStorage
|
||||||
|
{
|
||||||
|
private History CreateModel(HistoryBindingModel model, History history)
|
||||||
|
{
|
||||||
|
history.BookId = model.BookId;
|
||||||
|
history.ReaderId = model.ReaderId;
|
||||||
|
history.DateBorrowed = model.DateBorrowed;
|
||||||
|
return history;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HistoryViewModel CreateModel(History history)
|
||||||
|
{
|
||||||
|
return new HistoryViewModel
|
||||||
|
{
|
||||||
|
Id = history.Id,
|
||||||
|
BookId = history.BookId,
|
||||||
|
ReaderId = history.ReaderId,
|
||||||
|
DateBorrowed = history.DateBorrowed
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HistoryViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
return context.Histories.ToList().Select(CreateModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HistoryViewModel> GetHistoryByBookId(int bookId)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
return context.Histories
|
||||||
|
.Where(history => history.BookId == bookId)
|
||||||
|
.ToList().Select(CreateModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistoryViewModel? GetElement(HistoryBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
var history = context.Histories.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
return history != null ? CreateModel(history) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Insert(HistoryBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
context.Histories.Add(CreateModel(model, new History()));
|
||||||
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(HistoryBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
var history = context.Histories.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (history != null)
|
||||||
|
{
|
||||||
|
context.Histories.Remove(history);
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Запись истории не найдена");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
105
BookDatabaseImplement/Implements/ReaderStorage.cs
Normal file
105
BookDatabaseImplement/Implements/ReaderStorage.cs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.StorageContracts;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using BookDatabaseImplement.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ReaderStorage : IReaderStorage
|
||||||
|
{
|
||||||
|
private Reader CreateModel(ReaderBindingModel model, Reader reader)
|
||||||
|
{
|
||||||
|
reader.Name = model.Name;
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReaderViewModel CreateModel(Reader reader)
|
||||||
|
{
|
||||||
|
return new ReaderViewModel
|
||||||
|
{
|
||||||
|
Id = reader.Id,
|
||||||
|
Name = reader.Name
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReaderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
return context.Readers.ToList().Select(CreateModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReaderViewModel> GetFilterList(ReaderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
return context.Readers
|
||||||
|
.Where(reader => reader.Name.Contains(model.Name))
|
||||||
|
.ToList().Select(CreateModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReaderViewModel? GetElement(ReaderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
var reader = context.Readers.FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name);
|
||||||
|
return reader != null ? CreateModel(reader) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Insert(ReaderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
context.Readers.Add(CreateModel(model, new Reader()));
|
||||||
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ReaderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var reader = context.Readers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (reader == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Читатель не найден");
|
||||||
|
}
|
||||||
|
CreateModel(model, reader);
|
||||||
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(ReaderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new BookLibraryDatabase();
|
||||||
|
var reader = context.Readers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (reader != null)
|
||||||
|
{
|
||||||
|
context.Readers.Remove(reader);
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Читатель не найден");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
128
BookDatabaseImplement/Migrations/20241028084936_InitMig.Designer.cs
generated
Normal file
128
BookDatabaseImplement/Migrations/20241028084936_InitMig.Designer.cs
generated
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using BookDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace BookDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(BookLibraryDatabase))]
|
||||||
|
[Migration("20241028084936_InitMig")]
|
||||||
|
partial class InitMig
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.10")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.Book", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Annotation")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(200)
|
||||||
|
.HasColumnType("character varying(200)");
|
||||||
|
|
||||||
|
b.Property<string>("BookType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Books");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.History", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("BookId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateBorrowed")
|
||||||
|
.HasColumnType("timestamp without time zone");
|
||||||
|
|
||||||
|
b.Property<int>("ReaderId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("BookId");
|
||||||
|
|
||||||
|
b.HasIndex("ReaderId");
|
||||||
|
|
||||||
|
b.ToTable("Histories");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.Reader", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Readers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.History", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("BookDatabaseImplement.Model.Book", "Book")
|
||||||
|
.WithMany("LastReaders")
|
||||||
|
.HasForeignKey("BookId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("BookDatabaseImplement.Model.Reader", "Reader")
|
||||||
|
.WithMany("BorrowedBooks")
|
||||||
|
.HasForeignKey("ReaderId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Book");
|
||||||
|
|
||||||
|
b.Navigation("Reader");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.Book", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("LastReaders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.Reader", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("BorrowedBooks");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
94
BookDatabaseImplement/Migrations/20241028084936_InitMig.cs
Normal file
94
BookDatabaseImplement/Migrations/20241028084936_InitMig.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace BookDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class InitMig : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Books",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Title = table.Column<string>(type: "text", nullable: false),
|
||||||
|
BookType = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Annotation = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Books", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Readers",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Readers", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Histories",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
BookId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
ReaderId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
DateBorrowed = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Histories", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Histories_Books_BookId",
|
||||||
|
column: x => x.BookId,
|
||||||
|
principalTable: "Books",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Histories_Readers_ReaderId",
|
||||||
|
column: x => x.ReaderId,
|
||||||
|
principalTable: "Readers",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Histories_BookId",
|
||||||
|
table: "Histories",
|
||||||
|
column: "BookId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Histories_ReaderId",
|
||||||
|
table: "Histories",
|
||||||
|
column: "ReaderId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Histories");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Books");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Readers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using BookDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace BookDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(BookLibraryDatabase))]
|
||||||
|
partial class BookLibraryDatabaseModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.10")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.Book", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Annotation")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(200)
|
||||||
|
.HasColumnType("character varying(200)");
|
||||||
|
|
||||||
|
b.Property<string>("BookType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Books");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.History", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("BookId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateBorrowed")
|
||||||
|
.HasColumnType("timestamp without time zone");
|
||||||
|
|
||||||
|
b.Property<int>("ReaderId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("BookId");
|
||||||
|
|
||||||
|
b.HasIndex("ReaderId");
|
||||||
|
|
||||||
|
b.ToTable("Histories");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.Reader", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Readers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.History", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("BookDatabaseImplement.Model.Book", "Book")
|
||||||
|
.WithMany("LastReaders")
|
||||||
|
.HasForeignKey("BookId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("BookDatabaseImplement.Model.Reader", "Reader")
|
||||||
|
.WithMany("BorrowedBooks")
|
||||||
|
.HasForeignKey("ReaderId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Book");
|
||||||
|
|
||||||
|
b.Navigation("Reader");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.Book", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("LastReaders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BookDatabaseImplement.Model.Reader", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("BorrowedBooks");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
BookDatabaseImplement/Model/Book.cs
Normal file
28
BookDatabaseImplement/Model/Book.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookDatabaseImplement.Model
|
||||||
|
{
|
||||||
|
public class Book
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string BookType { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(200, MinimumLength = 100)]
|
||||||
|
public string Annotation { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[InverseProperty("Book")]
|
||||||
|
public List<History> LastReaders { get; set; } = new List<History>();
|
||||||
|
}
|
||||||
|
}
|
30
BookDatabaseImplement/Model/History.cs
Normal file
30
BookDatabaseImplement/Model/History.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookDatabaseImplement.Model
|
||||||
|
{
|
||||||
|
public class History
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int BookId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("BookId")]
|
||||||
|
public Book Book { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int ReaderId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("ReaderId")]
|
||||||
|
public Reader Reader { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public DateTime DateBorrowed { get; set; }
|
||||||
|
}
|
||||||
|
}
|
19
BookDatabaseImplement/Model/Reader.cs
Normal file
19
BookDatabaseImplement/Model/Reader.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BookDatabaseImplement.Model
|
||||||
|
{
|
||||||
|
public class Reader
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public List<History> BorrowedBooks { get; set; } = new List<History>();
|
||||||
|
}
|
||||||
|
}
|
49
COP3.sln
Normal file
49
COP3.sln
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.11.35303.130
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookContract", "BookContract\BookContract.csproj", "{B6BADCB3-6326-4D78-B7EA-33E648B98B45}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookDatabaseImplement", "BookDatabaseImplement\BookDatabaseImplement.csproj", "{1ADFC6AE-FBB7-405C-9D0E-80E1EB5E15F9}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Desktop", "Desktop\Desktop.csproj", "{193A14AF-1D66-4FE6-B463-A985BE2E63BB}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{67A97857-028F-4E5B-A9CF-BDEFD8699C25}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookBusinessLogic", "BookBusinessLogic\BookBusinessLogic.csproj", "{1FCCA8B4-9391-4F9E-AF1F-556C56EAA352}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{B6BADCB3-6326-4D78-B7EA-33E648B98B45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B6BADCB3-6326-4D78-B7EA-33E648B98B45}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B6BADCB3-6326-4D78-B7EA-33E648B98B45}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B6BADCB3-6326-4D78-B7EA-33E648B98B45}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{1ADFC6AE-FBB7-405C-9D0E-80E1EB5E15F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1ADFC6AE-FBB7-405C-9D0E-80E1EB5E15F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1ADFC6AE-FBB7-405C-9D0E-80E1EB5E15F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1ADFC6AE-FBB7-405C-9D0E-80E1EB5E15F9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{193A14AF-1D66-4FE6-B463-A985BE2E63BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{193A14AF-1D66-4FE6-B463-A985BE2E63BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{193A14AF-1D66-4FE6-B463-A985BE2E63BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{193A14AF-1D66-4FE6-B463-A985BE2E63BB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{67A97857-028F-4E5B-A9CF-BDEFD8699C25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{67A97857-028F-4E5B-A9CF-BDEFD8699C25}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{67A97857-028F-4E5B-A9CF-BDEFD8699C25}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{67A97857-028F-4E5B-A9CF-BDEFD8699C25}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{1FCCA8B4-9391-4F9E-AF1F-556C56EAA352}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1FCCA8B4-9391-4F9E-AF1F-556C56EAA352}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1FCCA8B4-9391-4F9E-AF1F-556C56EAA352}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1FCCA8B4-9391-4F9E-AF1F-556C56EAA352}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {05DA2BD9-9B6D-4B78-897A-1EEAEEA4139A}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
20
COP3/COP3.csproj
Normal file
20
COP3/COP3.csproj
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BookContract\BookContract.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
7
COP3/Class1.cs
Normal file
7
COP3/Class1.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace COP3
|
||||||
|
{
|
||||||
|
public class Class1
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
27
Desktop/Desktop.csproj
Normal file
27
Desktop/Desktop.csproj
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Components" Version="1.0.0" />
|
||||||
|
<PackageReference Include="COP_V6" Version="1.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Unity" Version="5.11.10" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BookBusinessLogic\BookBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\BookContract\BookContract.csproj" />
|
||||||
|
<ProjectReference Include="..\BookDatabaseImplement\BookDatabaseImplement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
58
Desktop/Form1.Designer.cs
generated
Normal file
58
Desktop/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
namespace Desktop
|
||||||
|
{
|
||||||
|
partial class Form1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
bookList = new Components.VisualComponents.UserListBox();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// bookList
|
||||||
|
//
|
||||||
|
bookList.Location = new Point(-1, 1);
|
||||||
|
bookList.Name = "bookList";
|
||||||
|
bookList.SelectedIndex = -1;
|
||||||
|
bookList.Size = new Size(803, 450);
|
||||||
|
bookList.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// Form1
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(bookList);
|
||||||
|
Name = "Form1";
|
||||||
|
Text = "Form1";
|
||||||
|
Load += Form1_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Components.VisualComponents.UserListBox bookList;
|
||||||
|
}
|
||||||
|
}
|
45
Desktop/Form1.cs
Normal file
45
Desktop/Form1.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.BusinessLogicContracts;
|
||||||
|
using BookDatabaseImplement.Implements;
|
||||||
|
|
||||||
|
namespace Desktop
|
||||||
|
{
|
||||||
|
public partial class Form1 : Form
|
||||||
|
{
|
||||||
|
private IBookLogic _bookLogicl;
|
||||||
|
private IHistoryLogic _historyLogicl;
|
||||||
|
private IReaderLogic _readerLogicl;
|
||||||
|
|
||||||
|
|
||||||
|
public Form1(IBookLogic bookLogic, IHistoryLogic historyLogicl, IReaderLogic readerLogicl)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_bookLogicl = bookLogic;
|
||||||
|
_historyLogicl = historyLogicl;
|
||||||
|
_readerLogicl = readerLogicl;
|
||||||
|
|
||||||
|
bookList.SetTemplate("{", "}", "Ôîðìà êíèãè {BookType} Èíäèôèêàòîð {Id} Íàçâàíèå {Title} {Annotation} Àííîòàöèÿ");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Form1_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var books = _bookLogicl.Read(null);
|
||||||
|
|
||||||
|
foreach (var book in books)
|
||||||
|
{
|
||||||
|
bookList.Add<BookBindingModel>(new BookBindingModel { Id = book.Id, Title = book.Title, BookType = book.BookType, Annotation = book.Annotation });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void controlTextBox1_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bookList_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
120
Desktop/Form1.resx
Normal file
120
Desktop/Form1.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
51
Desktop/Program.cs
Normal file
51
Desktop/Program.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using BookBusinessLogic.BusinessLogic;
|
||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.BusinessLogicContracts;
|
||||||
|
using BookContract.StorageContracts;
|
||||||
|
using BookDatabaseImplement.Implements;
|
||||||
|
using Unity;
|
||||||
|
using Unity.Lifetime;
|
||||||
|
|
||||||
|
namespace Desktop
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
private static IUnityContainer container = null;
|
||||||
|
|
||||||
|
public static IUnityContainer Container
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (container == null)
|
||||||
|
{
|
||||||
|
container = BuildUnityContainer();
|
||||||
|
}
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||||
|
Application.EnableVisualStyles();
|
||||||
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application.Run(Container.Resolve<Form1>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IUnityContainer BuildUnityContainer()
|
||||||
|
{
|
||||||
|
var currentContainer = new UnityContainer();
|
||||||
|
|
||||||
|
currentContainer.RegisterType<IBookStorage, BookStorage>(new HierarchicalLifetimeManager());
|
||||||
|
currentContainer.RegisterType<IHistoryStorage, HistoryStorage>(new HierarchicalLifetimeManager());
|
||||||
|
currentContainer.RegisterType<IReaderStorage, ReaderStorage>(new HierarchicalLifetimeManager());
|
||||||
|
|
||||||
|
currentContainer.RegisterType<IBookLogic, BookLogic>(new HierarchicalLifetimeManager());
|
||||||
|
currentContainer.RegisterType<IHistoryLogic, HistoryLogic>(new HierarchicalLifetimeManager());
|
||||||
|
currentContainer.RegisterType<IReaderLogic, ReaderLogic>(new HierarchicalLifetimeManager());
|
||||||
|
|
||||||
|
return currentContainer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
119
Test/Program.cs
Normal file
119
Test/Program.cs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
using BookBusinessLogic.BusinessLogic;
|
||||||
|
using BookContract.BindingModels;
|
||||||
|
using BookContract.BusinessLogicContracts;
|
||||||
|
using BookContract.StorageContracts;
|
||||||
|
using BookContract.ViewModels;
|
||||||
|
using BookDatabaseImplement.Implements;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
//var bookStorage = new BookStorage();
|
||||||
|
//var readerStorage = new ReaderStorage();
|
||||||
|
//var historyStorage = new HistoryStorage();
|
||||||
|
|
||||||
|
//// создание книг
|
||||||
|
//var book1 = new bookbindingmodel { title = "книга 1", booktype = "фантастика", annotation = "аннотация к книге 1" };
|
||||||
|
//var book2 = new bookbindingmodel { title = "книга 2", booktype = "приключения", annotation = "аннотация к книге 2" };
|
||||||
|
|
||||||
|
//bookstorage.insert(book1);
|
||||||
|
//bookstorage.insert(book2);
|
||||||
|
|
||||||
|
//console.writeline("книги созданы.");
|
||||||
|
|
||||||
|
//// создание читателей
|
||||||
|
//var reader1 = new readerbindingmodel { name = "читатель 1" };
|
||||||
|
//var reader2 = new readerbindingmodel { name = "читатель 2" };
|
||||||
|
//var reader3 = new readerbindingmodel { name = "читатель 3" };
|
||||||
|
|
||||||
|
//readerstorage.insert(reader1);
|
||||||
|
//readerstorage.insert(reader2);
|
||||||
|
//readerstorage.insert(reader3);
|
||||||
|
|
||||||
|
//console.writeline("читатели созданы.");
|
||||||
|
|
||||||
|
|
||||||
|
//historystorage.insert(new historybindingmodel { bookid = 2, readerid = 1, dateborrowed = datetime.now });
|
||||||
|
//historystorage.insert(new historybindingmodel { bookid = 2, readerid = 2, dateborrowed = datetime.now });
|
||||||
|
//historystorage.insert(new historybindingmodel { bookid = 2, readerid = 3, dateborrowed = datetime.now });
|
||||||
|
|
||||||
|
|
||||||
|
//Console.WriteLine("Читатели добавлены к книге.");
|
||||||
|
|
||||||
|
//var books = bookStorage.GetFullList();
|
||||||
|
//foreach (var book in books)
|
||||||
|
//{
|
||||||
|
// Console.WriteLine($"Title: {book.Title}");
|
||||||
|
// Console.WriteLine("Readers: ");
|
||||||
|
// foreach (var reader in book.LastReaders)
|
||||||
|
// {
|
||||||
|
// Console.WriteLine($"- {reader.Name} (ID: {reader.Id})");
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
//Настройка DI (если используете)
|
||||||
|
var serviceProvider = new ServiceCollection()
|
||||||
|
.AddSingleton<IBookStorage, BookStorage>()
|
||||||
|
.AddSingleton<IBookLogic, BookLogic>()
|
||||||
|
.AddSingleton<IReaderLogic, ReaderLogic>()
|
||||||
|
.AddSingleton<IReaderStorage, ReaderStorage>()
|
||||||
|
.AddSingleton<IHistoryLogic, HistoryLogic>()
|
||||||
|
.AddSingleton<IHistoryStorage, HistoryStorage>()
|
||||||
|
.BuildServiceProvider();
|
||||||
|
|
||||||
|
var bookLogic = serviceProvider.GetService<IBookLogic>();
|
||||||
|
var readerLogic = serviceProvider.GetService<IReaderLogic>();
|
||||||
|
var historyLogic = serviceProvider.GetService<IHistoryLogic>();
|
||||||
|
|
||||||
|
var book1 = new BookBindingModel();
|
||||||
|
book1.Id = 1;
|
||||||
|
book1.BookType = "HHHH";
|
||||||
|
book1.Annotation = "asdafaf";
|
||||||
|
book1.Title = "Title";
|
||||||
|
//bookLogic.CreateOrUpdate(book1);
|
||||||
|
|
||||||
|
/* var pay1 = new HistoryBindingModel();
|
||||||
|
pay1.DateBorrowed = DateTime.Now;
|
||||||
|
pay1.Id = 5;
|
||||||
|
pay1.BookId = 1;
|
||||||
|
pay1.ReaderId = 4;
|
||||||
|
|
||||||
|
historyLogic.CreateOrUpdate(pay1);
|
||||||
|
|
||||||
|
DisplayAllBooks(bookLogic);
|
||||||
|
|
||||||
|
var readers = readerLogic.Read(null);
|
||||||
|
foreach (var reader in readers)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"ID: {reader.Id}, Name: {reader.Name}");
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DisplayAllBooks(IBookLogic bookLogic)
|
||||||
|
{
|
||||||
|
/*try
|
||||||
|
{
|
||||||
|
var books = bookLogic.Read(null);
|
||||||
|
if (books.Count == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Нет доступных книг.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var book in books)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"ID: {book.Id}, Title: {book.Title}, Type: {book.BookType}, Annotation: {book.Annotation}");
|
||||||
|
foreach (var reader in book.LastReaders)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"- {reader.Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
23
Test/Test.csproj
Normal file
23
Test/Test.csproj
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BookBusinessLogic\BookBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\BookContract\BookContract.csproj" />
|
||||||
|
<ProjectReference Include="..\BookDatabaseImplement\BookDatabaseImplement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user