Картинки и всё такое

This commit is contained in:
devil_1nc 2024-06-25 20:26:34 +04:00
parent 882a46ba3b
commit 0d08c87f0b
19 changed files with 1205 additions and 89 deletions

View File

@ -25,6 +25,7 @@ namespace BusinessLogic.BusinessLogic
public bool Create(MediaFileBindingModel model) public bool Create(MediaFileBindingModel model)
{ {
CheckModel(model); CheckModel(model);
_logger.LogInformation("Работа идёт нормально, криэйт в логике");
if (_mediafileStorage.Insert(model) == null) if (_mediafileStorage.Insert(model) == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
@ -96,13 +97,9 @@ namespace BusinessLogic.BusinessLogic
{ {
return; return;
} }
if (string.IsNullOrEmpty(model.Name)) if (model.Image == null)
{ {
throw new ArgumentNullException("Нет названия", nameof(model.Name)); //throw new ArgumentNullException("Нет изображения", nameof(model.Name));
}
if (model.Location == null)
{
throw new ArgumentNullException("Нет пути", nameof(model.Name));
} }
_logger.LogError("Проверка модели медиа файла выдала ошибку."); _logger.LogError("Проверка модели медиа файла выдала ошибку.");
} }

View File

@ -11,7 +11,6 @@ namespace Contracts.BindingModels
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public Guid ProductId { get; set; } public Guid ProductId { get; set; }
public string Name { get; set; } = string.Empty; public required byte[] Image { get; set; }
public string Location { get; set; } = string.Empty;
} }
} }

View File

@ -11,7 +11,9 @@ namespace Contracts.SearchModels
public Guid? Id { get; set; } public Guid? Id { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public double? Price { 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 int? Amount { get; set; }
public bool? IsBeingSold { get; set; } public bool? IsBeingSold { get; set; }
} }

View File

@ -5,14 +5,14 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
namespace Contracts.ViewModels namespace Contracts.ViewModels
{ {
public class MediaFileViewModel public class MediaFileViewModel
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Location { get; set; } = string.Empty; public required byte[] Image { get; set; }
public string Name { get; set; } = string.Empty;
public Guid ProductId { get; set; } public Guid ProductId { get; set; }
public string ProductName { get; set; } = string.Empty; public string ProductName { get; set; } = string.Empty;
public MediaFileBindingModel GetBindingModel() public MediaFileBindingModel GetBindingModel()
@ -20,8 +20,7 @@ namespace Contracts.ViewModels
return new MediaFileBindingModel return new MediaFileBindingModel
{ {
Id = Id, Id = Id,
Name = Name, Image = Image,
Location = Location,
ProductId = ProductId ProductId = ProductId
}; };
} }

View File

@ -8,8 +8,7 @@ namespace DataModels.Models
{ {
public interface IMediaFile : IId public interface IMediaFile : IId
{ {
string Name { get; } byte[] Image { get; }
string Location { get; }
Guid ProductId { get; } Guid ProductId { get; }
} }
} }

View File

@ -41,7 +41,7 @@ namespace DatabaseImplement.Implements
public List<ProductViewModel> GetFilteredList(ProductSearchModel model) public List<ProductViewModel> 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(); return new();
} }
@ -54,6 +54,30 @@ namespace DatabaseImplement.Implements
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .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) if (model.Rate.HasValue)
{ {
return context.Products return context.Products
@ -71,7 +95,7 @@ namespace DatabaseImplement.Implements
.ToList(); .ToList();
} }
return context.Products return context.Products
.Where(x => x.Name == model.Name) .Where(x => x.Name.Contains(model.Name))
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();

View File

@ -0,0 +1,496 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<byte[]>("Image")
.IsRequired()
.HasColumnType("bytea");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("PurchaseId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateArriving")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class image : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Location",
table: "MediaFiles");
migrationBuilder.AddColumn<byte[]>(
name: "Image",
table: "MediaFiles",
type: "bytea",
nullable: false,
defaultValue: new byte[0]);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Image",
table: "MediaFiles");
migrationBuilder.AddColumn<string>(
name: "Location",
table: "MediaFiles",
type: "text",
nullable: false,
defaultValue: "");
}
}
}

View File

@ -0,0 +1,492 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<byte[]>("Image")
.IsRequired()
.HasColumnType("bytea");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("PurchaseId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateArriving")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class image2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Name",
table: "MediaFiles");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Name",
table: "MediaFiles",
type: "text",
nullable: false,
defaultValue: "");
}
}
}

View File

@ -28,13 +28,9 @@ namespace DatabaseImplement.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("uuid"); .HasColumnType("uuid");
b.Property<string>("Location") b.Property<byte[]>("Image")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("bytea");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId") b.Property<Guid>("ProductId")
.HasColumnType("uuid"); .HasColumnType("uuid");

View File

@ -15,12 +15,9 @@ namespace DatabaseImplement.Models
[Required] [Required]
public Guid Id { get; set; } public Guid Id { get; set; }
[Required] [Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Location { get; set; } = string.Empty;
[Required]
public Guid ProductId { get; set; } public Guid ProductId { get; set; }
[Required]
public byte[] Image { get; set; }
public virtual Product Product { get; set; } public virtual Product Product { get; set; }
public static MediaFile? Create(MediaFileBindingModel? model) public static MediaFile? Create(MediaFileBindingModel? model)
@ -32,8 +29,7 @@ namespace DatabaseImplement.Models
return new MediaFile return new MediaFile
{ {
Id = model.Id, Id = model.Id,
Name = model.Name, Image = model.Image,
Location = model.Location,
ProductId = model.ProductId, ProductId = model.ProductId,
}; };
} }
@ -44,8 +40,7 @@ namespace DatabaseImplement.Models
{ {
return; return;
} }
Location = model.Location; Image = model.Image;
Name = model.Name;
} }
public MediaFileViewModel GetViewModel public MediaFileViewModel GetViewModel
@ -56,8 +51,7 @@ namespace DatabaseImplement.Models
return new() return new()
{ {
Id = Id, Id = Id,
Name = Name, Image = Image,
Location = Location,
ProductId = ProductId, ProductId = ProductId,
ProductName = context.Products.FirstOrDefault(x => x.Id == ProductId)?.Name ?? string.Empty, ProductName = context.Products.FirstOrDefault(x => x.Id == ProductId)?.Name ?? string.Empty,
}; };

View File

@ -1,4 +1,5 @@
using Contracts.BusinessLogicContracts; using BusinessLogic.BusinessLogic;
using Contracts.BusinessLogicContracts;
using Contracts.SearchModels; using Contracts.SearchModels;
using Contracts.ViewModels; using Contracts.ViewModels;
using DatabaseImplement.Models; using DatabaseImplement.Models;
@ -7,12 +8,14 @@ using System.Collections.Generic;
namespace RestAPI.Controllers namespace RestAPI.Controllers
{ {
[Route("[controller]/[action]")]
[ApiController]
public class MediaFileController : Controller public class MediaFileController : Controller
{ {
private readonly IMediaFileLogic _mediaFileLogic; private readonly IMediaFileLogic _mediaFileLogic;
private readonly IProductLogic _productLogic; private readonly IProductLogic _productLogic;
private readonly ILogger _logger; private readonly ILogger _logger;
public MediaFileController(ILogger logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic) public MediaFileController(ILogger<MediaFileLogic> logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic)
{ {
_logger = logger; _logger = logger;
_mediaFileLogic = mediaFileLogic; _mediaFileLogic = mediaFileLogic;
@ -32,11 +35,11 @@ namespace RestAPI.Controllers
} }
} }
[HttpGet] [HttpGet]
public Dictionary<ProductViewModel, List<MediaFileViewModel>> GetByProducts() public Dictionary<Guid, List<MediaFileViewModel>> GetByProducts()
{ {
try try
{ {
var dict = new Dictionary<ProductViewModel, List<MediaFileViewModel>>(); var dict = new Dictionary<Guid, List<MediaFileViewModel>>();
var products = _productLogic.ReadList(null); var products = _productLogic.ReadList(null);
foreach (var product in products) foreach (var product in products)
@ -45,7 +48,7 @@ namespace RestAPI.Controllers
{ {
ProductId = product.Id, ProductId = product.Id,
}); });
dict.Add(product, media); dict.Add(product.Id, media);
} }
return dict; return dict;

View File

@ -22,11 +22,20 @@ namespace RestAPI.Controllers
_product = productLogic; _product = productLogic;
} }
[HttpGet] [HttpGet]
public List<ProductViewModel>? GetFullList() public List<ProductViewModel>? GetList(string? search, double? pricefrom, double? priceto)
{ {
try 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) catch (Exception ex)
{ {

View File

@ -23,6 +23,7 @@ builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>(); builder.Services.AddTransient<IProductLogic, ProductLogic>();
builder.Services.AddTransient<ISellLogic, SellLogic>(); builder.Services.AddTransient<ISellLogic, SellLogic>();
builder.Services.AddTransient<IPurchaseLogic, PurchaseLogic>(); builder.Services.AddTransient<IPurchaseLogic, PurchaseLogic>();
builder.Services.AddTransient<IMediaFileLogic, MediaFileLogic>();
builder.Services.AddSingleton<ITwoFactorAuthService, TwoFactorAuthService>(); builder.Services.AddSingleton<ITwoFactorAuthService, TwoFactorAuthService>();
@ -31,6 +32,7 @@ builder.Services.AddTransient<IUserStorage, UserStorage>();
builder.Services.AddTransient<IProductStorage, ProductStorage>(); builder.Services.AddTransient<IProductStorage, ProductStorage>();
builder.Services.AddTransient<ISellStorage, SellStorage>(); builder.Services.AddTransient<ISellStorage, SellStorage>();
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>(); builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
builder.Services.AddTransient<IMediaFileStorage, MediaFileStorage>();
builder.Services.AddSingleton<JwtProvider>(); builder.Services.AddSingleton<JwtProvider>();
builder.Services.AddSingleton<MailSender>(); builder.Services.AddSingleton<MailSender>();

View File

@ -15,27 +15,27 @@
<ul class="navbar-nav me-auto mb-2 mb-lg-0"> <ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Категории Category
</a> </a>
@* МОЖНО РЕАЛИЗОВАТЬ ПОЗЖЕ *@ @* МОЖНО РЕАЛИЗОВАТЬ ПОЗЖЕ *@
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">Пистолеты</a></li> <li><a class="dropdown-item" href="#">Pistols</a></li>
<li><a class="dropdown-item" href="#">Револьверы</a></li> <li><a class="dropdown-item" href="#">Rifles</a></li>
<li><a class="dropdown-item" href="#">Винтовки</a></li> <li><a class="dropdown-item" href="#">Hard Weapons</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
<form class="d-flex" method="get"> <form class="d-flex" method="get">
<input class="form-control me-2" type="search" placeholder="Поиск" name="search" value=""> <input asp-for="ProductsModel" type="search" placeholder="Поиск" name="search" value="">
<button class="btn btn-outline-success" type="submit"><i class="fas fa-search"></i></button> <button class="btn btn-outline-success" type="submit"><i class="fas fa-search"></i></button>
</form> </form>
<div class="form-group ms-3"> <div class="form-group ms-3">
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<input type="range" step="1000" min="0" max="10000" value="50000" class="custom-range me-2" id="priceFrom"> <input type="range" step="1000" min="0" max="10000" value="" class="custom-range me-2" id="priceFrom">
<label for="priceFrom">От: <span id="priceLabelFrom">50 000</span> руб.</label> <label for="priceFrom">От: <span id="priceLabelFrom">50 000</span> руб.</label>
</div> </div>
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<input type="range" step="1000" min="0" max="100000" value="50000" class="custom-range me-2" id="priceTo"> <input type="range" step="1000" min="0" max="100000" value="" class="custom-range me-2" id="priceTo">
<label for="priceTo">До: <span id="priceLabelTo">50 000</span> руб.</label> <label for="priceTo">До: <span id="priceLabelTo">50 000</span> руб.</label>
</div> </div>
</div> </div>
@ -44,18 +44,23 @@
</nav> </nav>
@* КАРТОЧКИ ТОВАРОВ *@ @* КАРТОЧКИ ТОВАРОВ *@
<div class="row row-cols-1 row-cols-md-3 g-6"> <div id="Row">
@foreach (var weapon in @Model.ProductsModel) <div class="row row-cols-1 row-cols-md-3 g-5">
{ @foreach (var weapon in @Model.ProductsModel)
<div class="card"> {
<img src="@Model.GetMediaByProduct(weapon)[0].Location" class="card-img-top" alt="@weapon.Name"> <div class="col mb-4">
<div class="card-body"> <div class="card h-100">
<h5 class="card-title">@weapon.Name</h5> <img src="data:image/png;base64,@Convert.ToBase64String(Model.GetMediaByProduct(weapon))" class="card-img-top" alt="@weapon.Name">
<p class="card-text">Цена: >@weapon.Price руб.</p> <div class="card-body">
<a href="#" class="btn btn-primary">В корзину</a> <h5 class="card-title">@weapon.Name</h5>
<p class="card-text">Цена: @weapon.Price руб.</p>
<a href="#" class="btn btn-primary">В корзину</a>
<a href="#" class="btn btn-secondary">Просмотр</a>
</div>
</div>
</div> </div>
</div> }
} </div>
</div> </div>
@section Scripts { @section Scripts {

View File

@ -1,3 +1,4 @@
using Contracts.SearchModels;
using Contracts.ViewModels; using Contracts.ViewModels;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -9,17 +10,27 @@ namespace WebApp.Pages
public class IndexModel : PageModel public class IndexModel : PageModel
{ {
public List<ProductViewModel> ProductsModel { get; set; } public List<ProductViewModel> ProductsModel { get; set; }
public Dictionary<ProductViewModel, List<MediaFileViewModel>> MediaByProductsModel { get; set; } public Dictionary<Guid, List<MediaFileViewModel>> MediaByProductsModel { get; set; }
public void OnGet() public void OnGet(double? pricefrom, double? priceto, string? search)
{ {
ProductsModel = APIClient.GetRequest<List<ProductViewModel>>($"Product/GetFullList"); string request = "Product/GetList";
MediaByProductsModel = APIClient.GetRequest<Dictionary<ProductViewModel, List<MediaFileViewModel>>>($"MediaFile/GetByProducts?"); if (!string.IsNullOrEmpty(search))
request += $"?search={search}";
if (pricefrom != null)
request += $"?pricefrom={pricefrom}";
if (priceto != null)
request += $"?priceto={priceto}";
ProductsModel = APIClient.GetRequest<List<ProductViewModel>>(request);
MediaByProductsModel = APIClient.GetRequest<Dictionary<Guid, List<MediaFileViewModel>>>($"MediaFile/GetByProducts?");
} }
public List<MediaFileViewModel> GetMediaByProduct(ProductViewModel productModel) public byte[] GetMediaByProduct(ProductViewModel productModel)
{ {
MediaByProductsModel.TryGetValue(productModel, out List<MediaFileViewModel> models); MediaByProductsModel.TryGetValue(productModel.Id, out List<MediaFileViewModel> models);
return models; return models[0].Image;
} }
} }
} }

View File

@ -19,4 +19,10 @@ html {
body { body {
margin-bottom: 60px; margin-bottom: 60px;
}
.card-img-top {
height: 300px;
width: 100%;
object-fit: cover;
} }

View File

@ -20,14 +20,14 @@ namespace WinFormsApp
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IMediaFileLogic _mediafileLogic; private readonly IMediaFileLogic _mediafileLogic;
private readonly IProductLogic _productLogic; private readonly IProductLogic _productLogic;
private string? _filename; private byte[]? _image;
public FormMediaFiles(ILogger<FormMediaFiles> logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic) public FormMediaFiles(ILogger<FormMediaFiles> logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_mediafileLogic = mediaFileLogic; _mediafileLogic = mediaFileLogic;
_productLogic = productLogic; _productLogic = productLogic;
_filename = null; _image = null;
} }
private void LoadData() private void LoadData()
@ -51,23 +51,30 @@ namespace WinFormsApp
ProductId = (Guid?)comboBoxProduct.SelectedValue ?? Guid.Empty, ProductId = (Guid?)comboBoxProduct.SelectedValue ?? Guid.Empty,
}); });
panelFiles.Controls.Clear(); panelFiles.Controls.Clear();
foreach (var item in list) if (list.Count != 0)
{ {
var imageBox = new PictureBox(); foreach (var item in list)
imageBox.Dock = DockStyle.Top; {
imageBox.Image = new Bitmap(item.Location);
imageBox.Width = groupBox1.Width; var imageBox = new PictureBox();
panelFiles.Controls.Add(imageBox); imageBox.Dock = DockStyle.Top;
imageBox.SizeMode = PictureBoxSizeMode.Zoom; using (var ms = new MemoryStream(item.Image))
imageBox.Height = 400; {
imageBox.BorderStyle = BorderStyle.FixedSingle; Image image = Image.FromStream(ms);
imageBox.Image = image;
var imageLabel = new Label(); }
imageLabel.Text = item.Name; imageBox.Width = groupBox1.Width;
imageLabel.Dock = DockStyle.Top; panelFiles.Controls.Add(imageBox);
imageLabel.TextAlign = ContentAlignment.MiddleCenter; imageBox.SizeMode = PictureBoxSizeMode.Zoom;
panelFiles.Controls.Add(imageLabel); imageBox.Height = 400;
panelFiles.Refresh(); 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) 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() _mediafileLogic.Create(new MediaFileBindingModel()
{ {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
Name = System.IO.Path.GetFileNameWithoutExtension(_filename), Image = _image,
Location = _filename,
ProductId = (Guid)comboBoxProduct.SelectedValue, ProductId = (Guid)comboBoxProduct.SelectedValue,
}); });
dataGridView.Update();
panelFiles.Refresh();
} }
} }
private void buttonSelectFile_Click(object sender, EventArgs e) 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"; dialog.Filter = "Image Files(*.jpg; *.png; *.jpeg; *.gif; *.bmp)|*.jpg;*.png;*.jpeg;*.gif;*.bmp";
if (dialog.ShowDialog() == DialogResult.OK) if (dialog.ShowDialog() == DialogResult.OK)
{ {
_filename = dialog.FileName; using (var fs = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read))
labelFile.Text = System.IO.Path.GetFileName(_filename); {
_image = new byte[fs.Length];
fs.Read(_image, 0, (int)fs.Length);
}
labelFile.Text = Path.GetFileName(dialog.FileName);
} }
} }