From 0d08c87f0bd9b2b327c891203a1c90e9aaab8ec3 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Tue, 25 Jun 2024 20:26:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=B0=D1=80=D1=82=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B8=20=D0=B2=D1=81=D1=91=20=D1=82=D0=B0=D0=BA=D0=BE?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BusinessLogic/BusinessLogic/MediaFileLogic.cs | 9 +- .../BindingModels/MediaFileBindingModel.cs | 3 +- Contracts/SearchModels/ProductSearchModel.cs | 4 +- Contracts/ViewModels/MediaFileViewModel.cs | 7 +- DataModels/Models/IMediaFile.cs | 3 +- .../Implements/ProductStorage.cs | 28 +- .../20240625124236_image.Designer.cs | 496 ++++++++++++++++++ .../Migrations/20240625124236_image.cs | 40 ++ .../20240625131604_image2.Designer.cs | 492 +++++++++++++++++ .../Migrations/20240625131604_image2.cs | 29 + .../Migrations/DatabaseModelSnapshot.cs | 8 +- DatabaseImplement/Models/MediaFile.cs | 16 +- RestAPI/Controllers/MediaFileController.cs | 13 +- RestAPI/Controllers/ProductController.cs | 13 +- RestAPI/Program.cs | 2 + WebApp/Pages/Index.cshtml | 41 +- WebApp/Pages/Index.cshtml.cs | 25 +- WebApp/wwwroot/css/site.css | 6 + WinFormsApp/FormMediaFiles.cs | 59 ++- 19 files changed, 1205 insertions(+), 89 deletions(-) create mode 100644 DatabaseImplement/Migrations/20240625124236_image.Designer.cs create mode 100644 DatabaseImplement/Migrations/20240625124236_image.cs create mode 100644 DatabaseImplement/Migrations/20240625131604_image2.Designer.cs create mode 100644 DatabaseImplement/Migrations/20240625131604_image2.cs diff --git a/BusinessLogic/BusinessLogic/MediaFileLogic.cs b/BusinessLogic/BusinessLogic/MediaFileLogic.cs index 14e1184..16cb88d 100644 --- a/BusinessLogic/BusinessLogic/MediaFileLogic.cs +++ b/BusinessLogic/BusinessLogic/MediaFileLogic.cs @@ -25,6 +25,7 @@ namespace BusinessLogic.BusinessLogic public bool Create(MediaFileBindingModel model) { CheckModel(model); + _logger.LogInformation("Работа идёт нормально, криэйт в логике"); if (_mediafileStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -96,13 +97,9 @@ namespace BusinessLogic.BusinessLogic { return; } - if (string.IsNullOrEmpty(model.Name)) + if (model.Image == null) { - throw new ArgumentNullException("Нет названия", nameof(model.Name)); - } - if (model.Location == null) - { - throw new ArgumentNullException("Нет пути", nameof(model.Name)); + //throw new ArgumentNullException("Нет изображения", nameof(model.Name)); } _logger.LogError("Проверка модели медиа файла выдала ошибку."); } diff --git a/Contracts/BindingModels/MediaFileBindingModel.cs b/Contracts/BindingModels/MediaFileBindingModel.cs index dfa6386..9165977 100644 --- a/Contracts/BindingModels/MediaFileBindingModel.cs +++ b/Contracts/BindingModels/MediaFileBindingModel.cs @@ -11,7 +11,6 @@ namespace Contracts.BindingModels { public Guid Id { get; set; } public Guid ProductId { get; set; } - public string Name { get; set; } = string.Empty; - public string Location { get; set; } = string.Empty; + public required byte[] Image { get; set; } } } diff --git a/Contracts/SearchModels/ProductSearchModel.cs b/Contracts/SearchModels/ProductSearchModel.cs index 1759010..dac5012 100644 --- a/Contracts/SearchModels/ProductSearchModel.cs +++ b/Contracts/SearchModels/ProductSearchModel.cs @@ -11,7 +11,9 @@ namespace Contracts.SearchModels public Guid? Id { get; set; } public string? Name { get; set; } public double? Price { get; set; } - public double? Rate { get; set; } + public double? PriceFrom { get; set; } + public double? PriceTo { get; set; } + public double? Rate { get; set; } public int? Amount { get; set; } public bool? IsBeingSold { get; set; } } diff --git a/Contracts/ViewModels/MediaFileViewModel.cs b/Contracts/ViewModels/MediaFileViewModel.cs index c2f25bd..9986fc0 100644 --- a/Contracts/ViewModels/MediaFileViewModel.cs +++ b/Contracts/ViewModels/MediaFileViewModel.cs @@ -5,14 +5,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static System.Net.Mime.MediaTypeNames; namespace Contracts.ViewModels { public class MediaFileViewModel { public Guid Id { get; set; } - public string Location { get; set; } = string.Empty; - public string Name { get; set; } = string.Empty; + public required byte[] Image { get; set; } public Guid ProductId { get; set; } public string ProductName { get; set; } = string.Empty; public MediaFileBindingModel GetBindingModel() @@ -20,8 +20,7 @@ namespace Contracts.ViewModels return new MediaFileBindingModel { Id = Id, - Name = Name, - Location = Location, + Image = Image, ProductId = ProductId }; } diff --git a/DataModels/Models/IMediaFile.cs b/DataModels/Models/IMediaFile.cs index d4db8bd..4d50871 100644 --- a/DataModels/Models/IMediaFile.cs +++ b/DataModels/Models/IMediaFile.cs @@ -8,8 +8,7 @@ namespace DataModels.Models { public interface IMediaFile : IId { - string Name { get; } - string Location { get; } + byte[] Image { get; } Guid ProductId { get; } } } diff --git a/DatabaseImplement/Implements/ProductStorage.cs b/DatabaseImplement/Implements/ProductStorage.cs index d3de1d9..42ef011 100644 --- a/DatabaseImplement/Implements/ProductStorage.cs +++ b/DatabaseImplement/Implements/ProductStorage.cs @@ -41,7 +41,7 @@ namespace DatabaseImplement.Implements public List GetFilteredList(ProductSearchModel model) { - if (!model.IsBeingSold.HasValue && !model.Price.HasValue && !model.Rate.HasValue && !model.Amount.HasValue && string.IsNullOrEmpty(model.Name)) + if (!model.IsBeingSold.HasValue && !model.PriceFrom.HasValue && !model.PriceTo.HasValue && !model.Price.HasValue && !model.Rate.HasValue && !model.Amount.HasValue && string.IsNullOrEmpty(model.Name)) { return new(); } @@ -54,6 +54,30 @@ namespace DatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + if (model.PriceFrom.HasValue && model.PriceTo.HasValue) + { + return context.Products + .Where(x => x.Price <= model.PriceTo && x.Price >= model.PriceFrom) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.PriceFrom.HasValue) + { + return context.Products + .Where(x => x.Price >= model.PriceFrom) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.PriceTo.HasValue) + { + return context.Products + .Where(x => x.Price <= model.PriceTo) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } if (model.Rate.HasValue) { return context.Products @@ -71,7 +95,7 @@ namespace DatabaseImplement.Implements .ToList(); } return context.Products - .Where(x => x.Name == model.Name) + .Where(x => x.Name.Contains(model.Name)) .ToList() .Select(x => x.GetViewModel) .ToList(); diff --git a/DatabaseImplement/Migrations/20240625124236_image.Designer.cs b/DatabaseImplement/Migrations/20240625124236_image.Designer.cs new file mode 100644 index 0000000..6b2d959 --- /dev/null +++ b/DatabaseImplement/Migrations/20240625124236_image.Designer.cs @@ -0,0 +1,496 @@ +// +using System; +using DatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20240625124236_image")] + partial class image + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DatePurchase") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp with time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("SecondName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.HasOne("DatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany("PurchaseProducts") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Purchase", "Purchase") + .WithMany("Products") + .HasForeignKey("PurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Purchase"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.HasOne("DatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany("SellProducts") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Sell", "Sell") + .WithMany("Products") + .HasForeignKey("SellId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Sell"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Supplier", "Supplier") + .WithMany("Products") + .HasForeignKey("SupplierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Supplier"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.HasOne("DatabaseImplement.Models.Supplier", "Supplier") + .WithMany() + .HasForeignKey("SupplierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Supplier"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Supply", "Supply") + .WithMany("Products") + .HasForeignKey("SupplyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Supply"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.HasOne("DatabaseImplement.Models.Role", "Role") + .WithMany() + .HasForeignKey("RoleId"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Navigation("PurchaseProducts"); + + b.Navigation("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Navigation("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatabaseImplement/Migrations/20240625124236_image.cs b/DatabaseImplement/Migrations/20240625124236_image.cs new file mode 100644 index 0000000..7d26430 --- /dev/null +++ b/DatabaseImplement/Migrations/20240625124236_image.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class image : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Location", + table: "MediaFiles"); + + migrationBuilder.AddColumn( + name: "Image", + table: "MediaFiles", + type: "bytea", + nullable: false, + defaultValue: new byte[0]); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Image", + table: "MediaFiles"); + + migrationBuilder.AddColumn( + name: "Location", + table: "MediaFiles", + type: "text", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/DatabaseImplement/Migrations/20240625131604_image2.Designer.cs b/DatabaseImplement/Migrations/20240625131604_image2.Designer.cs new file mode 100644 index 0000000..f47981b --- /dev/null +++ b/DatabaseImplement/Migrations/20240625131604_image2.Designer.cs @@ -0,0 +1,492 @@ +// +using System; +using DatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20240625131604_image2")] + partial class image2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DatePurchase") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp with time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("SecondName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.HasOne("DatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany("PurchaseProducts") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Purchase", "Purchase") + .WithMany("Products") + .HasForeignKey("PurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Purchase"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.HasOne("DatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany("SellProducts") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Sell", "Sell") + .WithMany("Products") + .HasForeignKey("SellId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Sell"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Supplier", "Supplier") + .WithMany("Products") + .HasForeignKey("SupplierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Supplier"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.HasOne("DatabaseImplement.Models.Supplier", "Supplier") + .WithMany() + .HasForeignKey("SupplierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Supplier"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Supply", "Supply") + .WithMany("Products") + .HasForeignKey("SupplyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Supply"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.HasOne("DatabaseImplement.Models.Role", "Role") + .WithMany() + .HasForeignKey("RoleId"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Navigation("PurchaseProducts"); + + b.Navigation("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Navigation("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatabaseImplement/Migrations/20240625131604_image2.cs b/DatabaseImplement/Migrations/20240625131604_image2.cs new file mode 100644 index 0000000..065fa59 --- /dev/null +++ b/DatabaseImplement/Migrations/20240625131604_image2.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class image2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Name", + table: "MediaFiles"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Name", + table: "MediaFiles", + type: "text", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs b/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs index 013f054..4956384 100644 --- a/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs +++ b/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -28,13 +28,9 @@ namespace DatabaseImplement.Migrations .ValueGeneratedOnAdd() .HasColumnType("uuid"); - b.Property("Location") + b.Property("Image") .IsRequired() - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); + .HasColumnType("bytea"); b.Property("ProductId") .HasColumnType("uuid"); diff --git a/DatabaseImplement/Models/MediaFile.cs b/DatabaseImplement/Models/MediaFile.cs index 829e792..9ddb940 100644 --- a/DatabaseImplement/Models/MediaFile.cs +++ b/DatabaseImplement/Models/MediaFile.cs @@ -15,12 +15,9 @@ namespace DatabaseImplement.Models [Required] public Guid Id { get; set; } [Required] - public string Name { get; set; } = string.Empty; - [Required] - public string Location { get; set; } = string.Empty; - [Required] public Guid ProductId { get; set; } - + [Required] + public byte[] Image { get; set; } public virtual Product Product { get; set; } public static MediaFile? Create(MediaFileBindingModel? model) @@ -32,8 +29,7 @@ namespace DatabaseImplement.Models return new MediaFile { Id = model.Id, - Name = model.Name, - Location = model.Location, + Image = model.Image, ProductId = model.ProductId, }; } @@ -44,8 +40,7 @@ namespace DatabaseImplement.Models { return; } - Location = model.Location; - Name = model.Name; + Image = model.Image; } public MediaFileViewModel GetViewModel @@ -56,8 +51,7 @@ namespace DatabaseImplement.Models return new() { Id = Id, - Name = Name, - Location = Location, + Image = Image, ProductId = ProductId, ProductName = context.Products.FirstOrDefault(x => x.Id == ProductId)?.Name ?? string.Empty, }; diff --git a/RestAPI/Controllers/MediaFileController.cs b/RestAPI/Controllers/MediaFileController.cs index 1168022..4dba4d7 100644 --- a/RestAPI/Controllers/MediaFileController.cs +++ b/RestAPI/Controllers/MediaFileController.cs @@ -1,4 +1,5 @@ -using Contracts.BusinessLogicContracts; +using BusinessLogic.BusinessLogic; +using Contracts.BusinessLogicContracts; using Contracts.SearchModels; using Contracts.ViewModels; using DatabaseImplement.Models; @@ -7,12 +8,14 @@ using System.Collections.Generic; namespace RestAPI.Controllers { + [Route("[controller]/[action]")] + [ApiController] public class MediaFileController : Controller { private readonly IMediaFileLogic _mediaFileLogic; private readonly IProductLogic _productLogic; private readonly ILogger _logger; - public MediaFileController(ILogger logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic) + public MediaFileController(ILogger logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic) { _logger = logger; _mediaFileLogic = mediaFileLogic; @@ -32,11 +35,11 @@ namespace RestAPI.Controllers } } [HttpGet] - public Dictionary> GetByProducts() + public Dictionary> GetByProducts() { try { - var dict = new Dictionary>(); + var dict = new Dictionary>(); var products = _productLogic.ReadList(null); foreach (var product in products) @@ -45,7 +48,7 @@ namespace RestAPI.Controllers { ProductId = product.Id, }); - dict.Add(product, media); + dict.Add(product.Id, media); } return dict; diff --git a/RestAPI/Controllers/ProductController.cs b/RestAPI/Controllers/ProductController.cs index 651adf7..5a875ab 100644 --- a/RestAPI/Controllers/ProductController.cs +++ b/RestAPI/Controllers/ProductController.cs @@ -22,11 +22,20 @@ namespace RestAPI.Controllers _product = productLogic; } [HttpGet] - public List? GetFullList() + public List? GetList(string? search, double? pricefrom, double? priceto) { try { - return _product.ReadList(null); + if (search == null && pricefrom == null && priceto == null) + return _product.ReadList(null); + + else + return _product.ReadList(new ProductSearchModel() + { + Name = search, + PriceFrom = pricefrom, + PriceTo = priceto + }); } catch (Exception ex) { diff --git a/RestAPI/Program.cs b/RestAPI/Program.cs index ea7534c..19c5492 100644 --- a/RestAPI/Program.cs +++ b/RestAPI/Program.cs @@ -23,6 +23,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddSingleton(); @@ -31,6 +32,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); diff --git a/WebApp/Pages/Index.cshtml b/WebApp/Pages/Index.cshtml index 4c98134..b19ad67 100644 --- a/WebApp/Pages/Index.cshtml +++ b/WebApp/Pages/Index.cshtml @@ -15,27 +15,27 @@
- +
- +
- +
@@ -44,18 +44,23 @@ @* КАРТОЧКИ ТОВАРОВ *@ -
- @foreach (var weapon in @Model.ProductsModel) - { -
- @weapon.Name -
-
@weapon.Name
-

Цена: >@weapon.Price руб.

- В корзину +
+
+ @foreach (var weapon in @Model.ProductsModel) + { +
+
+ @weapon.Name +
+
@weapon.Name
+

Цена: @weapon.Price руб.

+ В корзину + Просмотр +
+
-
- } + } +
@section Scripts { diff --git a/WebApp/Pages/Index.cshtml.cs b/WebApp/Pages/Index.cshtml.cs index 644a6de..452bc27 100644 --- a/WebApp/Pages/Index.cshtml.cs +++ b/WebApp/Pages/Index.cshtml.cs @@ -1,3 +1,4 @@ +using Contracts.SearchModels; using Contracts.ViewModels; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -9,17 +10,27 @@ namespace WebApp.Pages public class IndexModel : PageModel { public List ProductsModel { get; set; } - public Dictionary> MediaByProductsModel { get; set; } + public Dictionary> MediaByProductsModel { get; set; } - public void OnGet() + public void OnGet(double? pricefrom, double? priceto, string? search) { - ProductsModel = APIClient.GetRequest>($"Product/GetFullList"); - MediaByProductsModel = APIClient.GetRequest>>($"MediaFile/GetByProducts?"); + string request = "Product/GetList"; + if (!string.IsNullOrEmpty(search)) + request += $"?search={search}"; + + if (pricefrom != null) + request += $"?pricefrom={pricefrom}"; + + if (priceto != null) + request += $"?priceto={priceto}"; + + ProductsModel = APIClient.GetRequest>(request); + MediaByProductsModel = APIClient.GetRequest>>($"MediaFile/GetByProducts?"); } - public List GetMediaByProduct(ProductViewModel productModel) + public byte[] GetMediaByProduct(ProductViewModel productModel) { - MediaByProductsModel.TryGetValue(productModel, out List models); - return models; + MediaByProductsModel.TryGetValue(productModel.Id, out List models); + return models[0].Image; } } } diff --git a/WebApp/wwwroot/css/site.css b/WebApp/wwwroot/css/site.css index f8d98fc..d92271e 100644 --- a/WebApp/wwwroot/css/site.css +++ b/WebApp/wwwroot/css/site.css @@ -19,4 +19,10 @@ html { body { margin-bottom: 60px; +} + +.card-img-top { + height: 300px; + width: 100%; + object-fit: cover; } \ No newline at end of file diff --git a/WinFormsApp/FormMediaFiles.cs b/WinFormsApp/FormMediaFiles.cs index b26ad2f..f710de4 100644 --- a/WinFormsApp/FormMediaFiles.cs +++ b/WinFormsApp/FormMediaFiles.cs @@ -20,14 +20,14 @@ namespace WinFormsApp private readonly ILogger _logger; private readonly IMediaFileLogic _mediafileLogic; private readonly IProductLogic _productLogic; - private string? _filename; + private byte[]? _image; public FormMediaFiles(ILogger logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic) { InitializeComponent(); _logger = logger; _mediafileLogic = mediaFileLogic; _productLogic = productLogic; - _filename = null; + _image = null; } private void LoadData() @@ -51,23 +51,30 @@ namespace WinFormsApp ProductId = (Guid?)comboBoxProduct.SelectedValue ?? Guid.Empty, }); panelFiles.Controls.Clear(); - foreach (var item in list) + if (list.Count != 0) { - var imageBox = new PictureBox(); - imageBox.Dock = DockStyle.Top; - imageBox.Image = new Bitmap(item.Location); - imageBox.Width = groupBox1.Width; - panelFiles.Controls.Add(imageBox); - imageBox.SizeMode = PictureBoxSizeMode.Zoom; - imageBox.Height = 400; - imageBox.BorderStyle = BorderStyle.FixedSingle; - - var imageLabel = new Label(); - imageLabel.Text = item.Name; - imageLabel.Dock = DockStyle.Top; - imageLabel.TextAlign = ContentAlignment.MiddleCenter; - panelFiles.Controls.Add(imageLabel); - panelFiles.Refresh(); + foreach (var item in list) + { + + var imageBox = new PictureBox(); + imageBox.Dock = DockStyle.Top; + using (var ms = new MemoryStream(item.Image)) + { + Image image = Image.FromStream(ms); + imageBox.Image = image; + } + imageBox.Width = groupBox1.Width; + panelFiles.Controls.Add(imageBox); + imageBox.SizeMode = PictureBoxSizeMode.Zoom; + imageBox.Height = 400; + imageBox.BorderStyle = BorderStyle.FixedSingle; + + var imageLabel = new Label(); + imageLabel.Dock = DockStyle.Top; + imageLabel.TextAlign = ContentAlignment.MiddleCenter; + panelFiles.Controls.Add(imageLabel); + panelFiles.Refresh(); + } } } @@ -100,16 +107,18 @@ namespace WinFormsApp private void buttonAdd_Click(object sender, EventArgs e) { - if (comboBoxProduct.SelectedIndex != -1 && !string.IsNullOrEmpty(_filename)) + if (comboBoxProduct.SelectedIndex != -1 && _image is not null) { _mediafileLogic.Create(new MediaFileBindingModel() { Id = Guid.NewGuid(), - Name = System.IO.Path.GetFileNameWithoutExtension(_filename), - Location = _filename, + Image = _image, ProductId = (Guid)comboBoxProduct.SelectedValue, }); + dataGridView.Update(); + panelFiles.Refresh(); } + } private void buttonSelectFile_Click(object sender, EventArgs e) @@ -118,8 +127,12 @@ namespace WinFormsApp dialog.Filter = "Image Files(*.jpg; *.png; *.jpeg; *.gif; *.bmp)|*.jpg;*.png;*.jpeg;*.gif;*.bmp"; if (dialog.ShowDialog() == DialogResult.OK) { - _filename = dialog.FileName; - labelFile.Text = System.IO.Path.GetFileName(_filename); + using (var fs = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read)) + { + _image = new byte[fs.Length]; + fs.Read(_image, 0, (int)fs.Length); + } + labelFile.Text = Path.GetFileName(dialog.FileName); } }