Добавьте файлы проекта.

This commit is contained in:
salih 2024-10-28 13:26:01 +04:00
parent 30facd916a
commit 15ae70574d
38 changed files with 1744 additions and 0 deletions

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

View 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();
}
}
}

View 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);
}
}
}

View 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();
}
}
}

View 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>();
}
}

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

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

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

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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>();
}
}

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

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

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

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

View 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("Книга не найдена");
}
}
}
}

View 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("Запись истории не найдена");
}
}
}
}

View 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("Читатель не найден");
}
}
}
}

View 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
}
}
}

View 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");
}
}
}

View File

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

View 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>();
}
}

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

View 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
View 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
View 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
View File

@ -0,0 +1,7 @@
namespace COP3
{
public class Class1
{
}
}

27
Desktop/Desktop.csproj Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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>