From e2d10d9bf1b2b9e7eede16fd222ffec682f34ea7 Mon Sep 17 00:00:00 2001 From: goblinrf Date: Sat, 11 May 2024 23:56:38 +0400 Subject: [PATCH] Done --- Diner/Diner/App.config | 2 +- .../Implements/MessageInfoStorage.cs | 21 +++++---- ... 20240511192321_InitialCreate.Designer.cs} | 43 ++++++++++++++++++- ...ate.cs => 20240511192321_InitialCreate.cs} | 29 +++++++++++++ .../Migrations/DinerDatabaseModelSnapshot.cs | 41 ++++++++++++++++++ .../Models/MessageInfo.cs | 11 ++--- Diner/DinerRestApi/appsettings.json | 2 +- 7 files changed, 130 insertions(+), 19 deletions(-) rename Diner/DinerDataBaseImplement/Migrations/{20240429190440_InitialCreate.Designer.cs => 20240511192321_InitialCreate.Designer.cs} (85%) rename Diner/DinerDataBaseImplement/Migrations/{20240429190440_InitialCreate.cs => 20240511192321_InitialCreate.cs} (85%) diff --git a/Diner/Diner/App.config b/Diner/Diner/App.config index 336f029..701ff1f 100644 --- a/Diner/Diner/App.config +++ b/Diner/Diner/App.config @@ -6,6 +6,6 @@ - + \ No newline at end of file diff --git a/Diner/DinerDataBaseImplement/Implements/MessageInfoStorage.cs b/Diner/DinerDataBaseImplement/Implements/MessageInfoStorage.cs index 63f0116..39639ff 100644 --- a/Diner/DinerDataBaseImplement/Implements/MessageInfoStorage.cs +++ b/Diner/DinerDataBaseImplement/Implements/MessageInfoStorage.cs @@ -10,16 +10,15 @@ namespace DinerDataBaseImplement.Implements { public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) { - if (string.IsNullOrEmpty(model.MessageId)) - { - return null; - } - using var context = new DinerDatabase(); - - return context.Messages - .FirstOrDefault(x => (x.MessageId == model.MessageId)) - ?.GetViewModel; + if (model.MessageId != null) + { + return context.Messages + .FirstOrDefault(x => (x.MessageId == model.MessageId)) + ?.GetViewModel; + + } + return null; } public List GetFilteredList(MessageInfoSearchModel model) @@ -45,9 +44,9 @@ namespace DinerDataBaseImplement.Implements { using var context = new DinerDatabase(); - var newMessage = MessageInfo.Create(model); + var newMessage = MessageInfo.Create(context, model); - if (newMessage == null) + if (newMessage == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId))) { return null; } diff --git a/Diner/DinerDataBaseImplement/Migrations/20240429190440_InitialCreate.Designer.cs b/Diner/DinerDataBaseImplement/Migrations/20240511192321_InitialCreate.Designer.cs similarity index 85% rename from Diner/DinerDataBaseImplement/Migrations/20240429190440_InitialCreate.Designer.cs rename to Diner/DinerDataBaseImplement/Migrations/20240511192321_InitialCreate.Designer.cs index 5e11665..f5bc534 100644 --- a/Diner/DinerDataBaseImplement/Migrations/20240429190440_InitialCreate.Designer.cs +++ b/Diner/DinerDataBaseImplement/Migrations/20240511192321_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace DinerDataBaseImplement.Migrations { [DbContext(typeof(DinerDatabase))] - [Migration("20240429190440_InitialCreate")] + [Migration("20240511192321_InitialCreate")] partial class InitialCreate { /// @@ -97,6 +97,36 @@ namespace DinerDataBaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("DinerDataBaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b => { b.Property("Id") @@ -186,6 +216,15 @@ namespace DinerDataBaseImplement.Migrations b.ToTable("SnackComponents"); }); + modelBuilder.Entity("DinerDataBaseImplement.Models.MessageInfo", b => + { + b.HasOne("DinerDataBaseImplement.Models.Client", "Client") + .WithMany("MessageInfos") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b => { b.HasOne("DinerDataBaseImplement.Models.Client", "Client") @@ -232,6 +271,8 @@ namespace DinerDataBaseImplement.Migrations modelBuilder.Entity("DinerDataBaseImplement.Models.Client", b => { + b.Navigation("MessageInfos"); + b.Navigation("Orders"); }); diff --git a/Diner/DinerDataBaseImplement/Migrations/20240429190440_InitialCreate.cs b/Diner/DinerDataBaseImplement/Migrations/20240511192321_InitialCreate.cs similarity index 85% rename from Diner/DinerDataBaseImplement/Migrations/20240429190440_InitialCreate.cs rename to Diner/DinerDataBaseImplement/Migrations/20240511192321_InitialCreate.cs index e567346..9988418 100644 --- a/Diner/DinerDataBaseImplement/Migrations/20240429190440_InitialCreate.cs +++ b/Diner/DinerDataBaseImplement/Migrations/20240511192321_InitialCreate.cs @@ -70,6 +70,27 @@ namespace DinerDataBaseImplement.Migrations table.PrimaryKey("PK_Snacks", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + ClientId = table.Column(type: "int", nullable: true), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + table.ForeignKey( + name: "FK_Messages_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + }); + migrationBuilder.CreateTable( name: "Orders", columns: table => new @@ -134,6 +155,11 @@ namespace DinerDataBaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ClientId", table: "Orders", @@ -163,6 +189,9 @@ namespace DinerDataBaseImplement.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "Messages"); + migrationBuilder.DropTable( name: "Orders"); diff --git a/Diner/DinerDataBaseImplement/Migrations/DinerDatabaseModelSnapshot.cs b/Diner/DinerDataBaseImplement/Migrations/DinerDatabaseModelSnapshot.cs index de70b97..39c88ff 100644 --- a/Diner/DinerDataBaseImplement/Migrations/DinerDatabaseModelSnapshot.cs +++ b/Diner/DinerDataBaseImplement/Migrations/DinerDatabaseModelSnapshot.cs @@ -94,6 +94,36 @@ namespace DinerDataBaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("DinerDataBaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b => { b.Property("Id") @@ -183,6 +213,15 @@ namespace DinerDataBaseImplement.Migrations b.ToTable("SnackComponents"); }); + modelBuilder.Entity("DinerDataBaseImplement.Models.MessageInfo", b => + { + b.HasOne("DinerDataBaseImplement.Models.Client", "Client") + .WithMany("MessageInfos") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b => { b.HasOne("DinerDataBaseImplement.Models.Client", "Client") @@ -229,6 +268,8 @@ namespace DinerDataBaseImplement.Migrations modelBuilder.Entity("DinerDataBaseImplement.Models.Client", b => { + b.Navigation("MessageInfos"); + b.Navigation("Orders"); }); diff --git a/Diner/DinerDataBaseImplement/Models/MessageInfo.cs b/Diner/DinerDataBaseImplement/Models/MessageInfo.cs index 1561811..db42cf7 100644 --- a/Diner/DinerDataBaseImplement/Models/MessageInfo.cs +++ b/Diner/DinerDataBaseImplement/Models/MessageInfo.cs @@ -17,21 +17,21 @@ namespace DinerDataBaseImplement.Models public int? ClientId { get; set; } - [Required] + public string SenderName { get; set; } = string.Empty; - [Required] + public DateTime DateDelivery { get; set; } = DateTime.Now; - [Required] + public string Subject { get; set; } = string.Empty; - [Required] + public string Body { get; set; } = string.Empty; public virtual Client? Client { get; set; } - public static MessageInfo? Create(MessageInfoBindingModel model) + public static MessageInfo? Create(DinerDatabase context, MessageInfoBindingModel model) { if (model == null) { @@ -42,6 +42,7 @@ namespace DinerDataBaseImplement.Models { MessageId = model.MessageId, ClientId = model.ClientId, + Client = context.Clients.FirstOrDefault(x => x.Email == model.SenderName), SenderName = model.SenderName, Body = model.Body, DateDelivery = model.DateDelivery, diff --git a/Diner/DinerRestApi/appsettings.json b/Diner/DinerRestApi/appsettings.json index e2bc0fe..030c1f5 100644 --- a/Diner/DinerRestApi/appsettings.json +++ b/Diner/DinerRestApi/appsettings.json @@ -11,5 +11,5 @@ "PopHost": "pop.gmail.com", "PopPort": "995", "MailLogin": "labwork07pass@gmail.com", - "MailPassword": "passlab07" + "MailPassword": "acmn jtsg xrgz dccw" }