Compare commits

..

2 Commits

19 changed files with 1205 additions and 89 deletions

View File

@ -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("Проверка модели медиа файла выдала ошибку.");
}

View File

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

View File

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

View File

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

View File

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

View File

@ -41,7 +41,7 @@ namespace DatabaseImplement.Implements
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();
}
@ -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();

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()
.HasColumnType("uuid");
b.Property<string>("Location")
b.Property<byte[]>("Image")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
.HasColumnType("bytea");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");

View File

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

View File

@ -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<MediaFileLogic> logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic)
{
_logger = logger;
_mediaFileLogic = mediaFileLogic;
@ -32,11 +35,11 @@ namespace RestAPI.Controllers
}
}
[HttpGet]
public Dictionary<ProductViewModel, List<MediaFileViewModel>> GetByProducts()
public Dictionary<Guid, List<MediaFileViewModel>> GetByProducts()
{
try
{
var dict = new Dictionary<ProductViewModel, List<MediaFileViewModel>>();
var dict = new Dictionary<Guid, List<MediaFileViewModel>>();
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;

View File

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

View File

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

View File

@ -15,27 +15,27 @@
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Категории
Category
</a>
@* МОЖНО РЕАЛИЗОВАТЬ ПОЗЖЕ *@
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">Пистолеты</a></li>
<li><a class="dropdown-item" href="#">Револьверы</a></li>
<li><a class="dropdown-item" href="#">Винтовки</a></li>
<li><a class="dropdown-item" href="#">Pistols</a></li>
<li><a class="dropdown-item" href="#">Rifles</a></li>
<li><a class="dropdown-item" href="#">Hard Weapons</a></li>
</ul>
</li>
</ul>
<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>
</form>
<div class="form-group ms-3">
<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>
</div>
<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>
</div>
</div>
@ -44,19 +44,24 @@
</nav>
@* КАРТОЧКИ ТОВАРОВ *@
<div class="row row-cols-1 row-cols-md-3 g-6">
<div id="Row">
<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 h-100">
<img src="data:image/png;base64,@Convert.ToBase64String(Model.GetMediaByProduct(weapon))" class="card-img-top" alt="@weapon.Name">
<div class="card-body">
<h5 class="card-title">@weapon.Name</h5>
<p class="card-text">Цена: >@weapon.Price руб.</p>
<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>
@section Scripts {
<script>

View File

@ -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<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");
MediaByProductsModel = APIClient.GetRequest<Dictionary<ProductViewModel, List<MediaFileViewModel>>>($"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<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);
return models;
MediaByProductsModel.TryGetValue(productModel.Id, out List<MediaFileViewModel> models);
return models[0].Image;
}
}
}

View File

@ -20,3 +20,9 @@ html {
body {
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 IMediaFileLogic _mediafileLogic;
private readonly IProductLogic _productLogic;
private string? _filename;
private byte[]? _image;
public FormMediaFiles(ILogger<FormMediaFiles> logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic)
{
InitializeComponent();
_logger = logger;
_mediafileLogic = mediaFileLogic;
_productLogic = productLogic;
_filename = null;
_image = null;
}
private void LoadData()
@ -51,11 +51,18 @@ namespace WinFormsApp
ProductId = (Guid?)comboBoxProduct.SelectedValue ?? Guid.Empty,
});
panelFiles.Controls.Clear();
if (list.Count != 0)
{
foreach (var item in list)
{
var imageBox = new PictureBox();
imageBox.Dock = DockStyle.Top;
imageBox.Image = new Bitmap(item.Location);
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;
@ -63,12 +70,12 @@ namespace WinFormsApp
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();
}
}
}
@ -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);
}
}