This commit is contained in:
goblinrf 2024-05-11 23:56:38 +04:00
parent c2bdb40a32
commit e2d10d9bf1
7 changed files with 130 additions and 19 deletions

View File

@ -6,6 +6,6 @@
<add key="PopHost" value="pop.gmail.com" /> <add key="PopHost" value="pop.gmail.com" />
<add key="PopPort" value="995" /> <add key="PopPort" value="995" />
<add key="MailLogin" value="labwork07pass@gmail.com" /> <add key="MailLogin" value="labwork07pass@gmail.com" />
<add key="MailPassword" value="passlab07" /> <add key="MailPassword" value="acmn jtsg xrgz dccw" />
</appSettings> </appSettings>
</configuration> </configuration>

View File

@ -10,16 +10,15 @@ namespace DinerDataBaseImplement.Implements
{ {
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
{ {
if (string.IsNullOrEmpty(model.MessageId))
{
return null;
}
using var context = new DinerDatabase(); using var context = new DinerDatabase();
if (model.MessageId != null)
{
return context.Messages return context.Messages
.FirstOrDefault(x => (x.MessageId == model.MessageId)) .FirstOrDefault(x => (x.MessageId == model.MessageId))
?.GetViewModel; ?.GetViewModel;
}
return null;
} }
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model) public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
@ -45,9 +44,9 @@ namespace DinerDataBaseImplement.Implements
{ {
using var context = new DinerDatabase(); 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; return null;
} }

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace DinerDataBaseImplement.Migrations namespace DinerDataBaseImplement.Migrations
{ {
[DbContext(typeof(DinerDatabase))] [DbContext(typeof(DinerDatabase))]
[Migration("20240429190440_InitialCreate")] [Migration("20240511192321_InitialCreate")]
partial class InitialCreate partial class InitialCreate
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -97,6 +97,36 @@ namespace DinerDataBaseImplement.Migrations
b.ToTable("Implementers"); b.ToTable("Implementers");
}); });
modelBuilder.Entity("DinerDataBaseImplement.Models.MessageInfo", b =>
{
b.Property<string>("MessageId")
.HasColumnType("nvarchar(450)");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("ClientId")
.HasColumnType("int");
b.Property<DateTime>("DateDelivery")
.HasColumnType("datetime2");
b.Property<string>("SenderName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("Messages");
});
modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b => modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -186,6 +216,15 @@ namespace DinerDataBaseImplement.Migrations
b.ToTable("SnackComponents"); 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 => modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b =>
{ {
b.HasOne("DinerDataBaseImplement.Models.Client", "Client") b.HasOne("DinerDataBaseImplement.Models.Client", "Client")
@ -232,6 +271,8 @@ namespace DinerDataBaseImplement.Migrations
modelBuilder.Entity("DinerDataBaseImplement.Models.Client", b => modelBuilder.Entity("DinerDataBaseImplement.Models.Client", b =>
{ {
b.Navigation("MessageInfos");
b.Navigation("Orders"); b.Navigation("Orders");
}); });

View File

@ -70,6 +70,27 @@ namespace DinerDataBaseImplement.Migrations
table.PrimaryKey("PK_Snacks", x => x.Id); table.PrimaryKey("PK_Snacks", x => x.Id);
}); });
migrationBuilder.CreateTable(
name: "Messages",
columns: table => new
{
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: true),
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
Body = table.Column<string>(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( migrationBuilder.CreateTable(
name: "Orders", name: "Orders",
columns: table => new columns: table => new
@ -134,6 +155,11 @@ namespace DinerDataBaseImplement.Migrations
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateIndex(
name: "IX_Messages_ClientId",
table: "Messages",
column: "ClientId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId", name: "IX_Orders_ClientId",
table: "Orders", table: "Orders",
@ -163,6 +189,9 @@ namespace DinerDataBaseImplement.Migrations
/// <inheritdoc /> /// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.DropTable(
name: "Messages");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Orders"); name: "Orders");

View File

@ -94,6 +94,36 @@ namespace DinerDataBaseImplement.Migrations
b.ToTable("Implementers"); b.ToTable("Implementers");
}); });
modelBuilder.Entity("DinerDataBaseImplement.Models.MessageInfo", b =>
{
b.Property<string>("MessageId")
.HasColumnType("nvarchar(450)");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("ClientId")
.HasColumnType("int");
b.Property<DateTime>("DateDelivery")
.HasColumnType("datetime2");
b.Property<string>("SenderName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("Messages");
});
modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b => modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -183,6 +213,15 @@ namespace DinerDataBaseImplement.Migrations
b.ToTable("SnackComponents"); 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 => modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b =>
{ {
b.HasOne("DinerDataBaseImplement.Models.Client", "Client") b.HasOne("DinerDataBaseImplement.Models.Client", "Client")
@ -229,6 +268,8 @@ namespace DinerDataBaseImplement.Migrations
modelBuilder.Entity("DinerDataBaseImplement.Models.Client", b => modelBuilder.Entity("DinerDataBaseImplement.Models.Client", b =>
{ {
b.Navigation("MessageInfos");
b.Navigation("Orders"); b.Navigation("Orders");
}); });

View File

@ -17,21 +17,21 @@ namespace DinerDataBaseImplement.Models
public int? ClientId { get; set; } public int? ClientId { get; set; }
[Required]
public string SenderName { get; set; } = string.Empty; public string SenderName { get; set; } = string.Empty;
[Required]
public DateTime DateDelivery { get; set; } = DateTime.Now; public DateTime DateDelivery { get; set; } = DateTime.Now;
[Required]
public string Subject { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty;
[Required]
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
public virtual Client? Client { get; set; } public virtual Client? Client { get; set; }
public static MessageInfo? Create(MessageInfoBindingModel model) public static MessageInfo? Create(DinerDatabase context, MessageInfoBindingModel model)
{ {
if (model == null) if (model == null)
{ {
@ -42,6 +42,7 @@ namespace DinerDataBaseImplement.Models
{ {
MessageId = model.MessageId, MessageId = model.MessageId,
ClientId = model.ClientId, ClientId = model.ClientId,
Client = context.Clients.FirstOrDefault(x => x.Email == model.SenderName),
SenderName = model.SenderName, SenderName = model.SenderName,
Body = model.Body, Body = model.Body,
DateDelivery = model.DateDelivery, DateDelivery = model.DateDelivery,

View File

@ -11,5 +11,5 @@
"PopHost": "pop.gmail.com", "PopHost": "pop.gmail.com",
"PopPort": "995", "PopPort": "995",
"MailLogin": "labwork07pass@gmail.com", "MailLogin": "labwork07pass@gmail.com",
"MailPassword": "passlab07" "MailPassword": "acmn jtsg xrgz dccw"
} }