начало работы с формочками (они уже ломаются)

This commit is contained in:
Полина Чубыкина 2024-05-21 22:53:01 +04:00
parent af5041044f
commit c1c4991315
28 changed files with 2328 additions and 35 deletions

View File

@ -18,37 +18,28 @@ namespace BookshopDatabaseImplement.Implemets
{
using var context = new BookshopDatabase();
return context.Orders
.Include(x => x.Author)
.Include(x => x.Genre)
.Include(x => x.Book)
.Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (string.IsNullOrEmpty(model.Title))
{
return new();
}
using var context = new BookshopDatabase();
return context.Orders
.Include(x => x.Author)
.Include(x => x.Genre)
.Where(x => x.Title.Contains(model.Title))
.Include(x => x.Book)
.Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue)
{
return null;
}
using var context = new BookshopDatabase();
return context.Orders
.Include(x => x.Author)
.Include(x => x.Genre)
.Include(x => x.Book)
.Include(x => x.User)
.FirstOrDefault(x => x.Id.Equals(model.Id))
?.GetViewModel;
}

View File

@ -8,10 +8,82 @@ using BookshopContracts.ViewModels;
using BookshopContracts.SearchModels;
using BookshopContracts.BindingModels;
using BookshopDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace BookshopDatabaseImplement.Implemets
{
internal class PublisherStorage
public class PublisherStorage : IPublisherStorage
{
public List<PublisherViewModel> GetFullList()
{
using var context = new BookshopDatabase();
return context.Publishers
.Select(x => x.GetViewModel)
.ToList();
}
public List<PublisherViewModel> GetFilteredList(PublisherSearchModel model)
{
if (string.IsNullOrEmpty(model.PublisherName))
{
return new();
}
using var context = new BookshopDatabase();
return context.Publishers
.Where(x => x.PublisherName.Contains(model.PublisherName))
.Select(x => x.GetViewModel)
.ToList();
}
public PublisherViewModel? GetElement(PublisherSearchModel model)
{
if (string.IsNullOrEmpty(model.PublisherName) && !model.Id.HasValue)
{
return null;
}
using var context = new BookshopDatabase();
return context.Publishers
.FirstOrDefault(x => x.Id.Equals(model.Id))
?.GetViewModel;
}
public PublisherViewModel? Insert(PublisherBindingModel model)
{
var newPublisher = Publisher.Create(model);
if (newPublisher == null)
{
return null;
}
using var context = new BookshopDatabase();
context.Publishers.Add(newPublisher);
context.SaveChanges();
return newPublisher.GetViewModel;
}
public PublisherViewModel? Update(PublisherBindingModel model)
{
using var context = new BookshopDatabase();
var client = context.Publishers.FirstOrDefault(x => x.Id == model.Id);
if (client == null)
{
return null;
}
client.Update(model);
context.SaveChanges();
return client.GetViewModel;
}
public PublisherViewModel? Delete(PublisherBindingModel model)
{
using var context = new BookshopDatabase();
var element = context.Publishers.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Publishers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -8,10 +8,79 @@ using BookshopContracts.ViewModels;
using BookshopContracts.SearchModels;
using BookshopContracts.BindingModels;
using BookshopDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace BookshopDatabaseImplement.Implemets
{
internal class ReviewStorage
public class ReviewStorage : IReviewStorage
{
public List<ReviewViewModel> GetFullList()
{
using var context = new BookshopDatabase();
return context.Reviews
.Include(x => x.Book)
.Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
}
public List<ReviewViewModel> GetFilteredList(ReviewSearchModel model)
{
using var context = new BookshopDatabase();
return context.Reviews
.Include(x => x.Book)
.Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
}
public ReviewViewModel? GetElement(ReviewSearchModel model)
{
using var context = new BookshopDatabase();
return context.Reviews
.Include(x => x.Book)
.Include(x => x.User)
.FirstOrDefault(x => x.Id.Equals(model.Id))
?.GetViewModel;
}
public ReviewViewModel? Insert(ReviewBindingModel model)
{
var newReview = Review.Create(model);
if (newReview == null)
{
return null;
}
using var context = new BookshopDatabase();
context.Reviews.Add(newReview);
context.SaveChanges();
return newReview.GetViewModel;
}
public ReviewViewModel? Update(ReviewBindingModel model)
{
using var context = new BookshopDatabase();
var client = context.Reviews.FirstOrDefault(x => x.Id == model.Id);
if (client == null)
{
return null;
}
client.Update(model);
context.SaveChanges();
return client.GetViewModel;
}
public ReviewViewModel? Delete(ReviewBindingModel model)
{
using var context = new BookshopDatabase();
var element = context.Reviews.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Reviews.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -8,10 +8,82 @@ using BookshopContracts.ViewModels;
using BookshopContracts.SearchModels;
using BookshopContracts.BindingModels;
using BookshopDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace BookshopDatabaseImplement.Implemets
{
internal class UserStorage
public class UserStorage : IUserStorage
{
public List<UserViewModel> GetFullList()
{
using var context = new BookshopDatabase();
return context.Users
.Select(x => x.GetViewModel)
.ToList();
}
public List<UserViewModel> GetFilteredList(UserSearchModel model)
{
if (string.IsNullOrEmpty(model.Username))
{
return new();
}
using var context = new BookshopDatabase();
return context.Users
.Where(x => x.Username.Contains(model.Username))
.Select(x => x.GetViewModel)
.ToList();
}
public UserViewModel? GetElement(UserSearchModel model)
{
if (string.IsNullOrEmpty(model.Username) && string.IsNullOrEmpty(model.UserEmail) && !model.Id.HasValue)
{
return null;
}
using var context = new BookshopDatabase();
return context.Users
.FirstOrDefault(x => x.Id.Equals(model.Id))
?.GetViewModel;
}
public UserViewModel? Insert(UserBindingModel model)
{
var newUser = User.Create(model);
if (newUser == null)
{
return null;
}
using var context = new BookshopDatabase();
context.Users.Add(newUser);
context.SaveChanges();
return newUser.GetViewModel;
}
public UserViewModel? Update(UserBindingModel model)
{
using var context = new BookshopDatabase();
var client = context.Users.FirstOrDefault(x => x.Id == model.Id);
if (client == null)
{
return null;
}
client.Update(model);
context.SaveChanges();
return client.GetViewModel;
}
public UserViewModel? Delete(UserBindingModel model)
{
using var context = new BookshopDatabase();
var element = context.Users.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Users.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,264 @@
// <auto-generated />
using System;
using BookshopDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace BookshopDatabaseImplement.Migrations
{
[DbContext(typeof(BookshopDatabase))]
[Migration("20240521183229_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.19")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("BookshopDatabaseImplement.Models.Author", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AuthorName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Country")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Authors");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Book", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AuthorId")
.HasColumnType("int");
b.Property<int>("GenreId")
.HasColumnType("int");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("YearOfPublication")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.HasIndex("GenreId");
b.ToTable("Books");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Genre", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("GenreName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Genres");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BookId")
.HasColumnType("int");
b.Property<DateTime>("OrderDate")
.HasColumnType("datetime2");
b.Property<int>("Quantity")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BookId");
b.HasIndex("UserId");
b.ToTable("Orders");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Publisher", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PublisherName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Publishers");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Review", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BookId")
.HasColumnType("int");
b.Property<DateTime>("ReviewDate")
.HasColumnType("datetime2");
b.Property<string>("ReviewText")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BookId");
b.HasIndex("UserId");
b.ToTable("Reviews");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("UserEmail")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Book", b =>
{
b.HasOne("BookshopDatabaseImplement.Models.Author", "Author")
.WithMany()
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BookshopDatabaseImplement.Models.Genre", "Genre")
.WithMany()
.HasForeignKey("GenreId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
b.Navigation("Genre");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Order", b =>
{
b.HasOne("BookshopDatabaseImplement.Models.Book", "Book")
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BookshopDatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Book");
b.Navigation("User");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Review", b =>
{
b.HasOne("BookshopDatabaseImplement.Models.Book", "Book")
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BookshopDatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Book");
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,211 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BookshopDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Authors",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AuthorName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Country = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Authors", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Genres",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
GenreName = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Genres", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Publishers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PublisherName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Publishers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Username = table.Column<string>(type: "nvarchar(max)", nullable: false),
UserEmail = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Books",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
YearOfPublication = table.Column<int>(type: "int", nullable: false),
AuthorId = table.Column<int>(type: "int", nullable: false),
GenreId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Books", x => x.Id);
table.ForeignKey(
name: "FK_Books_Authors_AuthorId",
column: x => x.AuthorId,
principalTable: "Authors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Books_Genres_GenreId",
column: x => x.GenreId,
principalTable: "Genres",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OrderDate = table.Column<DateTime>(type: "datetime2", nullable: false),
Quantity = table.Column<int>(type: "int", nullable: false),
BookId = table.Column<int>(type: "int", nullable: false),
UserId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Reviews",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ReviewText = table.Column<string>(type: "nvarchar(max)", nullable: false),
ReviewDate = table.Column<DateTime>(type: "datetime2", nullable: false),
BookId = table.Column<int>(type: "int", nullable: false),
UserId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Reviews", x => x.Id);
table.ForeignKey(
name: "FK_Reviews_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Reviews_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Books_AuthorId",
table: "Books",
column: "AuthorId");
migrationBuilder.CreateIndex(
name: "IX_Books_GenreId",
table: "Books",
column: "GenreId");
migrationBuilder.CreateIndex(
name: "IX_Orders_BookId",
table: "Orders",
column: "BookId");
migrationBuilder.CreateIndex(
name: "IX_Orders_UserId",
table: "Orders",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Reviews_BookId",
table: "Reviews",
column: "BookId");
migrationBuilder.CreateIndex(
name: "IX_Reviews_UserId",
table: "Reviews",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "Publishers");
migrationBuilder.DropTable(
name: "Reviews");
migrationBuilder.DropTable(
name: "Books");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Authors");
migrationBuilder.DropTable(
name: "Genres");
}
}
}

View File

@ -0,0 +1,261 @@
// <auto-generated />
using System;
using BookshopDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace BookshopDatabaseImplement.Migrations
{
[DbContext(typeof(BookshopDatabase))]
partial class BookshopDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.19")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("BookshopDatabaseImplement.Models.Author", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AuthorName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Country")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Authors");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Book", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AuthorId")
.HasColumnType("int");
b.Property<int>("GenreId")
.HasColumnType("int");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("YearOfPublication")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.HasIndex("GenreId");
b.ToTable("Books");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Genre", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("GenreName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Genres");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BookId")
.HasColumnType("int");
b.Property<DateTime>("OrderDate")
.HasColumnType("datetime2");
b.Property<int>("Quantity")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BookId");
b.HasIndex("UserId");
b.ToTable("Orders");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Publisher", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PublisherName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Publishers");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Review", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BookId")
.HasColumnType("int");
b.Property<DateTime>("ReviewDate")
.HasColumnType("datetime2");
b.Property<string>("ReviewText")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BookId");
b.HasIndex("UserId");
b.ToTable("Reviews");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("UserEmail")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Book", b =>
{
b.HasOne("BookshopDatabaseImplement.Models.Author", "Author")
.WithMany()
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BookshopDatabaseImplement.Models.Genre", "Genre")
.WithMany()
.HasForeignKey("GenreId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
b.Navigation("Genre");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Order", b =>
{
b.HasOne("BookshopDatabaseImplement.Models.Book", "Book")
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BookshopDatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Book");
b.Navigation("User");
});
modelBuilder.Entity("BookshopDatabaseImplement.Models.Review", b =>
{
b.HasOne("BookshopDatabaseImplement.Models.Book", "Book")
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BookshopDatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Book");
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.19">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BookshopBusinessLogic\BookshopBusinessLogic.csproj" />
<ProjectReference Include="..\BookshopContracts\BookshopContracts.csproj" />
<ProjectReference Include="..\BookshopDatabaseImplement\BookshopDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -1,10 +0,0 @@
namespace BookshopView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,119 @@
namespace BookshopView
{
partial class FormAuthor
{
/// <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()
{
this.ButtonCancel = new System.Windows.Forms.Button();
this.ButtonSave = new System.Windows.Forms.Button();
this.textBoxName = new System.Windows.Forms.TextBox();
this.labelName = new System.Windows.Forms.Label();
this.textBoxCountry = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(317, 126);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(94, 29);
this.ButtonCancel.TabIndex = 15;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(105, 126);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(94, 29);
this.ButtonSave.TabIndex = 14;
this.ButtonSave.Text = "Сохранить";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(174, 24);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(295, 27);
this.textBoxName.TabIndex = 13;
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(55, 27);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(94, 20);
this.labelName.TabIndex = 12;
this.labelName.Text = "Имя автора:";
//
// textBoxCountry
//
this.textBoxCountry.Location = new System.Drawing.Point(174, 71);
this.textBoxCountry.Name = "textBoxCountry";
this.textBoxCountry.Size = new System.Drawing.Size(295, 27);
this.textBoxCountry.TabIndex = 17;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(55, 74);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(61, 20);
this.label1.TabIndex = 16;
this.label1.Text = "Страна:";
//
// FormAuthor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(555, 172);
this.Controls.Add(this.textBoxCountry);
this.Controls.Add(this.label1);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelName);
this.Name = "FormAuthor";
this.Text = "Автор";
this.Load += new System.EventHandler(this.FormAuthor_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button ButtonCancel;
private Button ButtonSave;
private TextBox textBoxName;
private Label labelName;
private TextBox textBoxCountry;
private Label label1;
}
}

View File

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Extensions.Logging;
using BookshopContracts.BindingModels;
using BookshopContracts.BusinessLogicsContracts;
using BookshopContracts.SearchModels;
namespace BookshopView
{
public partial class FormAuthor : Form
{
private readonly ILogger _logger;
private readonly IAuthorLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormAuthor(ILogger<FormAuthor> logger, IAuthorLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormAuthor_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение компонента");
var view = _logic.ReadElement(new AuthorSearchModel
{
Id =
_id.Value
});
if (view != null)
{
textBoxName.Text = view.AuthorName;
textBoxCountry.Text = view.Country;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение компонента");
try
{
var model = new AuthorBindingModel
{
Id = _id ?? 0,
AuthorName = textBoxName.Text,
Country = textBoxCountry.Text
};
var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,110 @@
namespace BookshopView
{
partial class FormAuthors
{
/// <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()
{
this.ButtonUpd = new System.Windows.Forms.Button();
this.ButtonDel = new System.Windows.Forms.Button();
this.ButtonRef = new System.Windows.Forms.Button();
this.ButtonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// ButtonUpd
//
this.ButtonUpd.Location = new System.Drawing.Point(543, 94);
this.ButtonUpd.Name = "ButtonUpd";
this.ButtonUpd.Size = new System.Drawing.Size(111, 32);
this.ButtonUpd.TabIndex = 14;
this.ButtonUpd.Text = "Изменить";
this.ButtonUpd.UseVisualStyleBackColor = true;
//
// ButtonDel
//
this.ButtonDel.Location = new System.Drawing.Point(543, 163);
this.ButtonDel.Name = "ButtonDel";
this.ButtonDel.Size = new System.Drawing.Size(111, 32);
this.ButtonDel.TabIndex = 13;
this.ButtonDel.Text = "Удалить";
this.ButtonDel.UseVisualStyleBackColor = true;
//
// ButtonRef
//
this.ButtonRef.Location = new System.Drawing.Point(543, 232);
this.ButtonRef.Name = "ButtonRef";
this.ButtonRef.Size = new System.Drawing.Size(111, 32);
this.ButtonRef.TabIndex = 12;
this.ButtonRef.Text = "Обновить";
this.ButtonRef.UseVisualStyleBackColor = true;
//
// ButtonAdd
//
this.ButtonAdd.Location = new System.Drawing.Point(543, 26);
this.ButtonAdd.Name = "ButtonAdd";
this.ButtonAdd.Size = new System.Drawing.Size(111, 32);
this.ButtonAdd.TabIndex = 11;
this.ButtonAdd.Text = "Добавить";
this.ButtonAdd.UseVisualStyleBackColor = true;
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(21, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(490, 426);
this.dataGridView.TabIndex = 10;
//
// FormAuthors
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(675, 450);
this.Controls.Add(this.ButtonUpd);
this.Controls.Add(this.ButtonDel);
this.Controls.Add(this.ButtonRef);
this.Controls.Add(this.ButtonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormAuthors";
this.Text = "Авторы";
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button ButtonUpd;
private Button ButtonDel;
private Button ButtonRef;
private Button ButtonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,118 @@
using BookshopContracts.BindingModels;
using BookshopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BookshopView
{
public partial class FormAuthors : Form
{
private readonly ILogger _logger;
private readonly IAuthorLogic _logic;
public FormAuthors(ILogger<FormAuthors> logger, IAuthorLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormAuthors_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["AuthorName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Country"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка компонентов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки компонентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAuthor));
if (service is FormAuthor form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service =
Program.ServiceProvider?.GetService(typeof(FormAuthor));
if (service is FormAuthor form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление компонента");
try
{
if (!_logic.Delete(new AuthorBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,39 @@
namespace BookshopView
{
partial class FormCreateOrder
{
/// <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()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "FormCreateOrder";
}
#endregion
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BookshopView
{
public partial class FormCreateOrder : Form
{
public FormCreateOrder()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,97 @@
namespace BookshopView
{
partial class FormGenre
{
/// <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()
{
this.ButtonCancel = new System.Windows.Forms.Button();
this.ButtonSave = new System.Windows.Forms.Button();
this.textBoxName = new System.Windows.Forms.TextBox();
this.labelName = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(288, 127);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(94, 29);
this.ButtonCancel.TabIndex = 11;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(76, 127);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(94, 29);
this.ButtonSave.TabIndex = 10;
this.ButtonSave.Text = "Сохранить";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(145, 57);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(295, 27);
this.textBoxName.TabIndex = 8;
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(26, 60);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(80, 20);
this.labelName.TabIndex = 6;
this.labelName.Text = "Название:";
//
// FormGenre
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(466, 184);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelName);
this.Name = "FormGenre";
this.Text = "Жанр";
this.Load += new System.EventHandler(this.FormGenre_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button ButtonCancel;
private Button ButtonSave;
private TextBox textBoxName;
private Label labelName;
}
}

View File

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Extensions.Logging;
using BookshopContracts.BindingModels;
using BookshopContracts.BusinessLogicsContracts;
using BookshopContracts.SearchModels;
namespace BookshopView
{
public partial class FormGenre : Form
{
private readonly ILogger _logger;
private readonly IGenreLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormGenre(ILogger<FormGenre> logger, IGenreLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormGenre_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение компонента");
var view = _logic.ReadElement(new GenreSearchModel
{
Id =
_id.Value
});
if (view != null)
{
textBoxName.Text = view.GenreName;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение компонента");
try
{
var model = new GenreBindingModel
{
Id = _id ?? 0,
GenreName = textBoxName.Text
};
var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,115 @@
namespace BookshopView
{
partial class FormGenres
{
/// <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()
{
this.ButtonUpd = new System.Windows.Forms.Button();
this.ButtonDel = new System.Windows.Forms.Button();
this.ButtonRef = new System.Windows.Forms.Button();
this.ButtonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// ButtonUpd
//
this.ButtonUpd.Location = new System.Drawing.Point(535, 94);
this.ButtonUpd.Name = "ButtonUpd";
this.ButtonUpd.Size = new System.Drawing.Size(111, 32);
this.ButtonUpd.TabIndex = 9;
this.ButtonUpd.Text = "Изменить";
this.ButtonUpd.UseVisualStyleBackColor = true;
this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// ButtonDel
//
this.ButtonDel.Location = new System.Drawing.Point(535, 163);
this.ButtonDel.Name = "ButtonDel";
this.ButtonDel.Size = new System.Drawing.Size(111, 32);
this.ButtonDel.TabIndex = 8;
this.ButtonDel.Text = "Удалить";
this.ButtonDel.UseVisualStyleBackColor = true;
this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// ButtonRef
//
this.ButtonRef.Location = new System.Drawing.Point(535, 232);
this.ButtonRef.Name = "ButtonRef";
this.ButtonRef.Size = new System.Drawing.Size(111, 32);
this.ButtonRef.TabIndex = 7;
this.ButtonRef.Text = "Обновить";
this.ButtonRef.UseVisualStyleBackColor = true;
this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// ButtonAdd
//
this.ButtonAdd.Location = new System.Drawing.Point(535, 26);
this.ButtonAdd.Name = "ButtonAdd";
this.ButtonAdd.Size = new System.Drawing.Size(111, 32);
this.ButtonAdd.TabIndex = 6;
this.ButtonAdd.Text = "Добавить";
this.ButtonAdd.UseVisualStyleBackColor = true;
this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(13, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(490, 426);
this.dataGridView.TabIndex = 5;
//
// FormGenres
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(659, 450);
this.Controls.Add(this.ButtonUpd);
this.Controls.Add(this.ButtonDel);
this.Controls.Add(this.ButtonRef);
this.Controls.Add(this.ButtonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormGenres";
this.Text = "Жанры";
this.Load += new System.EventHandler(this.FormGenres_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button ButtonUpd;
private Button ButtonDel;
private Button ButtonRef;
private Button ButtonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Extensions.Logging;
using BookshopContracts.BindingModels;
using BookshopContracts.BusinessLogicsContracts;
using BookshopContracts.SearchModels;
namespace BookshopView
{
public partial class FormGenres : Form
{
private readonly ILogger _logger;
private readonly IGenreLogic _logic;
public FormGenres(ILogger<FormGenres> logger, IGenreLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormGenres_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["GenreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка компонентов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки компонентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormGenre));
if (service is FormGenre form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service =
Program.ServiceProvider?.GetService(typeof(FormGenre));
if (service is FormGenre form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление компонента");
try
{
if (!_logic.Delete(new GenreBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -1,14 +1,14 @@
namespace BookshopView
{
partial class Form1
partial class FormMain
{
/// <summary>
/// Required designer variable.
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// 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)
@ -23,15 +23,15 @@
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
this.Text = "FormMain";
}
#endregion

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BookshopView
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
}
}

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>

View File

@ -1,7 +1,18 @@
using BookshopBusinessLogic.BusinessLogics;
using BookshopContracts.BusinessLogicsContracts;
using BookshopContracts.StorageContracts;
using BookshopDatabaseImplement.Implemets;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System;
namespace BookshopView
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -11,7 +22,32 @@ namespace BookshopView
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormAuthors>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IAuthorStorage, AuthorStorage>();
services.AddTransient<IGenreStorage, GenreStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IAuthorLogic, AuthorLogic>();
services.AddTransient<IGenreLogic, GenreLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormGenre>();
services.AddTransient<FormGenres>();
services.AddTransient<FormAuthor>();
services.AddTransient<FormAuthors>();
}
}
}