Done
This commit is contained in:
parent
c2bdb40a32
commit
e2d10d9bf1
@ -6,6 +6,6 @@
|
||||
<add key="PopHost" value="pop.gmail.com" />
|
||||
<add key="PopPort" value="995" />
|
||||
<add key="MailLogin" value="labwork07pass@gmail.com" />
|
||||
<add key="MailPassword" value="passlab07" />
|
||||
<add key="MailPassword" value="acmn jtsg xrgz dccw" />
|
||||
</appSettings>
|
||||
</configuration>
|
@ -10,16 +10,15 @@ namespace DinerDataBaseImplement.Implements
|
||||
{
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.MessageId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new DinerDatabase();
|
||||
if (model.MessageId != null)
|
||||
{
|
||||
return context.Messages
|
||||
.FirstOrDefault(x => (x.MessageId == model.MessageId))
|
||||
?.GetViewModel;
|
||||
|
||||
return context.Messages
|
||||
.FirstOrDefault(x => (x.MessageId == model.MessageId))
|
||||
?.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> 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;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace DinerDataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(DinerDatabase))]
|
||||
[Migration("20240429190440_InitialCreate")]
|
||||
[Migration("20240511192321_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -97,6 +97,36 @@ namespace DinerDataBaseImplement.Migrations
|
||||
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 =>
|
||||
{
|
||||
b.Property<int>("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");
|
||||
});
|
||||
|
@ -70,6 +70,27 @@ namespace DinerDataBaseImplement.Migrations
|
||||
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(
|
||||
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
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Messages");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
@ -94,6 +94,36 @@ namespace DinerDataBaseImplement.Migrations
|
||||
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 =>
|
||||
{
|
||||
b.Property<int>("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");
|
||||
});
|
||||
|
||||
|
@ -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,
|
||||
|
@ -11,5 +11,5 @@
|
||||
"PopHost": "pop.gmail.com",
|
||||
"PopPort": "995",
|
||||
"MailLogin": "labwork07pass@gmail.com",
|
||||
"MailPassword": "passlab07"
|
||||
"MailPassword": "acmn jtsg xrgz dccw"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user