@{
diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs
index 9cb9ac0..88f9432 100644
--- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs
+++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs
@@ -16,6 +16,8 @@ namespace FurnitureAssemblyDatabaseImplement
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql("Host=localhost;Database=FurnitureAssemblyDatabaseFull;Username=postgres;Password=postgres");
+ AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
+ AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
}
base.OnConfiguring(optionsBuilder);
diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs
index 520c7a0..0de7a1f 100644
--- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs
+++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs
@@ -29,38 +29,49 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
public ClientViewModel? GetElement(ClientSearchModel model)
{
- if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
- {
- return null;
- }
using var context = new FurnitureAssemblyDatabase();
- return context.Clients.FirstOrDefault(x =>
- (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) ||
- (model.Id.HasValue && x.Id == model.Id))
- ?.GetViewModel;
- }
+ if (model.Id.HasValue)
+ {
+ return context.Clients
+ .Include(x => x.Orders)
+ .FirstOrDefault(x => x.Id == model.Id)
+ ?.GetViewModel;
+ }
+
+ if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
+ {
+ return context.Clients
+ .Include(x => x.Orders)
+ .FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))
+ ?.GetViewModel;
+ }
+
+ if (!string.IsNullOrEmpty(model.Email))
+ return context.Clients
+ .FirstOrDefault(x => x.Email == model.Email)
+ ?.GetViewModel;
+
+ return null;
+ }
public List
GetFilteredList(ClientSearchModel model)
{
- if (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password))
+ if (string.IsNullOrEmpty(model.Email))
{
return new();
}
- using var context = new FurnitureAssemblyDatabase();
- return context.Clients
- .Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))
- .Select(x => x.GetViewModel)
- .ToList();
- }
+ using var context = new FurnitureAssemblyDatabase();
+
+ return context.Clients
+ .Where(x => x.Email.Contains(model.Email))
+ .Select(x => x.GetViewModel).ToList();
+ }
public List GetFullList()
{
using var context = new FurnitureAssemblyDatabase();
- return context.Clients
- .Select(x => x.GetViewModel)
- .ToList();
+ return context.Clients.Select(x => x.GetViewModel).ToList();
}
-
public ClientViewModel? Insert(ClientBindingModel model)
{
var newClient = Client.Create(model);
@@ -73,7 +84,6 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
context.SaveChanges();
return newClient.GetViewModel;
}
-
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new FurnitureAssemblyDatabase();
diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.Designer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.Designer.cs
new file mode 100644
index 0000000..8742fda
--- /dev/null
+++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.Designer.cs
@@ -0,0 +1,298 @@
+//
+using System;
+using FurnitureAssemblyDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace FurnitureAssemblyDatabaseImplement.Migrations
+{
+ [DbContext(typeof(FurnitureAssemblyDatabase))]
+ [Migration("20240516134544_lab07")]
+ partial class lab07
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("FurnitureName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Price")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.ToTable("Furnitures");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.Property("FurnitureId")
+ .HasColumnType("integer");
+
+ b.Property("WorkpieceId")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("FurnitureId");
+
+ b.HasIndex("WorkpieceId");
+
+ b.ToTable("FurnitureWorkpieces");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Qualification")
+ .HasColumnType("integer");
+
+ b.Property("WorkExperience")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b =>
+ {
+ b.Property("MessageId")
+ .HasColumnType("text");
+
+ b.Property("Body")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("ClientId")
+ .HasColumnType("integer");
+
+ b.Property("DateDelivery")
+ .HasColumnType("timestamp without time zone");
+
+ b.Property("SenderName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Subject")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("MessageId");
+
+ b.HasIndex("ClientId");
+
+ b.ToTable("Messages");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ClientId")
+ .HasColumnType("integer");
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.Property("DateCreate")
+ .HasColumnType("timestamp without time zone");
+
+ b.Property("DateImplement")
+ .HasColumnType("timestamp without time zone");
+
+ b.Property("FurnitureId")
+ .HasColumnType("integer");
+
+ b.Property("ImplementerId")
+ .HasColumnType("integer");
+
+ b.Property("Status")
+ .HasColumnType("integer");
+
+ b.Property("Sum")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("FurnitureId");
+
+ b.HasIndex("ImplementerId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Cost")
+ .HasColumnType("double precision");
+
+ b.Property("WorkpieceName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Workpieces");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b =>
+ {
+ b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
+ .WithMany("Workpieces")
+ .HasForeignKey("FurnitureId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Workpiece", "Workpiece")
+ .WithMany("FurnitureWorkpieces")
+ .HasForeignKey("WorkpieceId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Furniture");
+
+ b.Navigation("Workpiece");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b =>
+ {
+ b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client")
+ .WithMany("Messages")
+ .HasForeignKey("ClientId");
+
+ b.Navigation("Client");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client")
+ .WithMany("Orders")
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
+ .WithMany("Orders")
+ .HasForeignKey("FurnitureId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
+ b.Navigation("Client");
+
+ b.Navigation("Furniture");
+
+ b.Navigation("Implementer");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b =>
+ {
+ b.Navigation("Messages");
+
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
+ {
+ b.Navigation("Orders");
+
+ b.Navigation("Workpieces");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b =>
+ {
+ b.Navigation("FurnitureWorkpieces");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.cs
new file mode 100644
index 0000000..b864723
--- /dev/null
+++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240516134544_lab07.cs
@@ -0,0 +1,69 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace FurnitureAssemblyDatabaseImplement.Migrations
+{
+ ///
+ public partial class lab07 : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AlterColumn(
+ name: "DateImplement",
+ table: "Orders",
+ type: "timestamp without time zone",
+ nullable: true,
+ oldClrType: typeof(DateTime),
+ oldType: "timestamp with time zone",
+ oldNullable: true);
+
+ migrationBuilder.AlterColumn(
+ name: "DateCreate",
+ table: "Orders",
+ type: "timestamp without time zone",
+ nullable: false,
+ oldClrType: typeof(DateTime),
+ oldType: "timestamp with time zone");
+
+ migrationBuilder.AlterColumn(
+ name: "DateDelivery",
+ table: "Messages",
+ type: "timestamp without time zone",
+ nullable: false,
+ oldClrType: typeof(DateTime),
+ oldType: "timestamp with time zone");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AlterColumn(
+ name: "DateImplement",
+ table: "Orders",
+ type: "timestamp with time zone",
+ nullable: true,
+ oldClrType: typeof(DateTime),
+ oldType: "timestamp without time zone",
+ oldNullable: true);
+
+ migrationBuilder.AlterColumn(
+ name: "DateCreate",
+ table: "Orders",
+ type: "timestamp with time zone",
+ nullable: false,
+ oldClrType: typeof(DateTime),
+ oldType: "timestamp without time zone");
+
+ migrationBuilder.AlterColumn(
+ name: "DateDelivery",
+ table: "Messages",
+ type: "timestamp with time zone",
+ nullable: false,
+ oldClrType: typeof(DateTime),
+ oldType: "timestamp without time zone");
+ }
+ }
+}
diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs
index 5a2d1e1..7fbd3fd 100644
--- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs
+++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs
@@ -133,7 +133,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
.HasColumnType("integer");
b.Property("DateDelivery")
- .HasColumnType("timestamp with time zone");
+ .HasColumnType("timestamp without time zone");
b.Property("SenderName")
.IsRequired()
@@ -165,10 +165,10 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
.HasColumnType("integer");
b.Property("DateCreate")
- .HasColumnType("timestamp with time zone");
+ .HasColumnType("timestamp without time zone");
b.Property("DateImplement")
- .HasColumnType("timestamp with time zone");
+ .HasColumnType("timestamp without time zone");
b.Property("FurnitureId")
.HasColumnType("integer");
@@ -235,7 +235,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b =>
{
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client")
- .WithMany()
+ .WithMany("Messages")
.HasForeignKey("ClientId");
b.Navigation("Client");
@@ -244,7 +244,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
{
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client")
- .WithMany()
+ .WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -266,6 +266,13 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
b.Navigation("Implementer");
});
+ modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b =>
+ {
+ b.Navigation("Messages");
+
+ b.Navigation("Orders");
+ });
+
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
{
b.Navigation("Orders");
diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs
index c7a5157..2f8a9ec 100644
--- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs
+++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs
@@ -4,6 +4,7 @@ using FurnitureAssemblyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -19,6 +20,10 @@ namespace FurnitureAssemblyDatabaseImplement.Models
public string Email { get; private set; } = string.Empty;
[Required]
public string Password { get; private set; } = string.Empty;
+ [ForeignKey("ClientId")]
+ public virtual List Orders { get; set; } = new();
+ [ForeignKey("ClientId")]
+ public virtual List Messages { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
@@ -26,6 +31,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models
{
return null;
}
+
return new Client()
{
Id = model.Id,
@@ -34,16 +40,6 @@ namespace FurnitureAssemblyDatabaseImplement.Models
Password = model.Password
};
}
- public static Client Create(ClientViewModel model)
- {
- return new Client
- {
- Id = model.Id,
- ClientFIO = model.ClientFIO,
- Email = model.Email,
- Password = model.Password
- };
- }
public void Update(ClientBindingModel model)
{
if (model == null)
diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json b/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json
index 7013aed..023ce10 100644
--- a/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json
+++ b/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json
@@ -7,10 +7,10 @@
},
"AllowedHosts": "*",
- "SmtpClientHost": "smtp.beget.com",
- "SmtpClientPort": "465",
- "PopHost": "pop.beget.com",
+ "SmtpClientHost": "smtp.gmail.com",
+ "SmtpClientPort": "587",
+ "PopHost": "pop.gmail.com",
"PopPort": "995",
- "MailLogin": "",
- "MailPassword": "Fa0d*HzV"
+ "MailLogin": "@gmail.com",
+ "MailPassword": "gsmp yceu sztw iqid"
}