финальные изменения

This commit is contained in:
sardq 2024-05-11 19:41:48 +04:00
parent 35b5df3d58
commit 840c1176d3
9 changed files with 107 additions and 104 deletions

View File

@ -17,9 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairFileImplement
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairDatabaseImplement", "PlumbingRepairDatabaseImplement\PlumbingRepairDatabaseImplement.csproj", "{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairClientApp", "..\..\PlumbingRepair 7 база\PlumbingRepairClientApp\PlumbingRepairClientApp.csproj", "{4F1E898C-449A-4A60-95D8-BC7818019644}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairClientApp", "..\..\PlumbingRepair 7 база\PlumbingRepairClientApp\PlumbingRepairClientApp.csproj", "{712EBB90-7365-4F29-B7C6-91E3F5157B0C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairRestApi", "..\..\PlumbingRepair 7 база\PlumbingRepairRestApi\PlumbingRepairRestApi.csproj", "{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairRestApi", "..\..\PlumbingRepair 7 база\PlumbingRepairRestApi\PlumbingRepairRestApi.csproj", "{6CCF4B9D-A4CC-4751-A471-19DAA710413B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -55,14 +55,14 @@ Global
{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Release|Any CPU.Build.0 = Release|Any CPU
{4F1E898C-449A-4A60-95D8-BC7818019644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F1E898C-449A-4A60-95D8-BC7818019644}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F1E898C-449A-4A60-95D8-BC7818019644}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F1E898C-449A-4A60-95D8-BC7818019644}.Release|Any CPU.Build.0 = Release|Any CPU
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Release|Any CPU.Build.0 = Release|Any CPU
{712EBB90-7365-4F29-B7C6-91E3F5157B0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{712EBB90-7365-4F29-B7C6-91E3F5157B0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{712EBB90-7365-4F29-B7C6-91E3F5157B0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{712EBB90-7365-4F29-B7C6-91E3F5157B0C}.Release|Any CPU.Build.0 = Release|Any CPU
{6CCF4B9D-A4CC-4751-A471-19DAA710413B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CCF4B9D-A4CC-4751-A471-19DAA710413B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CCF4B9D-A4CC-4751-A471-19DAA710413B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CCF4B9D-A4CC-4751-A471-19DAA710413B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -137,8 +137,8 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
mailModel = new MailSendInfoBindingModel
{
MailAddress = clientModel.Email,
Subject = $"Order №{orderModel.Id}",
Text = $"Your order №{orderModel.Id} by {orderModel.DateCreate} on {orderModel.Sum} was accepted!"
Subject = $"Заказ №{orderModel.Id}",
Text = $"Ваш заказ №{orderModel.Id} в {orderModel.DateCreate} на сумму {orderModel.Sum} был принят!"
};
}
else
@ -146,8 +146,8 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
mailModel = new MailSendInfoBindingModel
{
MailAddress = clientModel.Email,
Subject = $"Order №{orderModel.Id}",
Text = $"Order №{orderModel.Id} status was changed to {orderModel.Status}"
Subject = $"Заказ №{orderModel.Id}",
Text = $"Заказ №{orderModel.Id} статус изменен в {orderModel.Status}"
};
}

View File

@ -20,31 +20,33 @@ namespace PlumbingRepairDatabaseImplement.Implements
{
using var context = new PlumbingRepairDatabase();
return context.Messages
.Where(x => x.ClientId == model.ClientId)
.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
{
if (string.IsNullOrEmpty(model.MessageId))
return null;
using var context = new PlumbingRepairDatabase();
if (model.MessageId != null)
{
return context.Messages
.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel;
}
return null;
}
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
{
using var context = new PlumbingRepairDatabase();
model.ClientId = context.Clients.FirstOrDefault(x => x.Email.Equals(model.SenderName))?.Id;
var newMessageInfo = MessageInfo.Create(model);
if (newMessageInfo == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId)))
{
return null;
}
context.Messages.Add(newMessageInfo);
context.SaveChanges();
return newMessageInfo.GetViewModel;

View File

@ -24,26 +24,75 @@ namespace PlumbingRepairDatabaseImplement.Implements
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue && !model.ImplementerId.HasValue && !model.Status.HasValue)
if (!model.Id.HasValue)
{
return null;
}
using var context = new PlumbingRepairDatabase();
return context.Orders
if (model.Id.HasValue)
return AttachNames(context.Orders
.Include(x => x.Work)
.Include(x => x.Implementer)
.Include(x => x.Client)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel);
else if (model.ImplementerId.HasValue && model.Status.HasValue)
return AttachNames(context.Orders
.Include(x => x.Implementer)
.Include(x => x.Work)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)
|| (model.ImplementerId.HasValue && model.Status.HasValue && x.ImplementerId == model.ImplementerId && x.Status == model.Status))?
.GetViewModel;
.FirstOrDefault(x => model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId)
?.GetViewModel);
return null;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
using var context = new PlumbingRepairDatabase();
if (model.DateFrom.HasValue)
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue && !model.Status.HasValue)
{
return new();
}
if (model.Id.HasValue)
{
return context.Orders
.Include(x => x.Work)
.Include(x => x.Implementer)
.Include(x => x.Client)
.Where(x => x.Id == model.Id)
.Select(x => AttachNames(x.GetViewModel)).ToList();
}
if (model.Status.HasValue)
{
return context.Orders
.Include(x => x.Work)
.Include(x => x.Implementer)
.Include(x => x.Client)
.Where(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)
.Select(x => AttachNames(x.GetViewModel)).ToList();
}
if (model.ClientId.HasValue)
{
return context.Orders
.Include(x => x.Client)
.Include(x => x.Work)
.Include(x => x.Implementer)
.Where(x => x.ClientId == model.ClientId)
.Select(x => AttachNames(x.GetViewModel)).ToList();
}
if (model.ImplementerId.HasValue)
{
return context.Orders
.Include(x => x.Work)
.Include(x => x.Implementer)
.Include(x => x.Client)
.Where(x => x.ImplementerId == model.ImplementerId)
.Select(x => AttachNames(x.GetViewModel)).ToList();
}
if (model.DateFrom != null && model.DateTo != null)
{
return context.Orders
.Include(x => x.Work)
@ -53,18 +102,9 @@ namespace PlumbingRepairDatabaseImplement.Implements
&& (!model.ClientId.HasValue || x.ClientId == model.ClientId))
.Select(x => x.GetViewModel)
.ToList();
}
return context.Orders
.Include(x => x.Work)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => (model.Id.HasValue && x.Id == model.Id)
|| (model.ClientId.HasValue && x.ClientId == model.ClientId)
|| (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId)
|| (model.Status.HasValue && x.Status == model.Status))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<OrderViewModel> GetFullList()
@ -89,7 +129,7 @@ namespace PlumbingRepairDatabaseImplement.Implements
context.Orders.Add(newOrder);
context.SaveChanges();
return AttachNames(newOrder.GetViewModel);
return AttachNames(context.Orders.Include(x => x.Work).Include(x => x.Implementer).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel);
}
public OrderViewModel? Update(OrderBindingModel model)

View File

@ -12,7 +12,7 @@ using PlumbingRepairDatabaseImplement;
namespace PlumbingRepairDatabaseImplement.Migrations
{
[DbContext(typeof(PlumbingRepairDatabase))]
[Migration("20240503080749_InitCreate")]
[Migration("20240503110424_InitCreate")]
partial class InitCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -121,8 +121,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("Messages");
});
@ -215,15 +213,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.ToTable("WorkComponents");
});
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.MessageInfo", b =>
{
b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client")
.WithMany("Messages")
.HasForeignKey("ClientId");
b.Navigation("Client");
});
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
{
b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client")
@ -270,8 +259,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Client", b =>
{
b.Navigation("Messages");
b.Navigation("Orders");
});

View File

@ -54,20 +54,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations
table.PrimaryKey("PK_Implementers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Works",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
WorkName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Works", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Messages",
columns: table => new
@ -82,11 +68,20 @@ namespace PlumbingRepairDatabaseImplement.Migrations
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: "Works",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
WorkName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Works", x => x.Id);
});
migrationBuilder.CreateTable(
@ -153,11 +148,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Messages_ClientId",
table: "Messages",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",

View File

@ -119,8 +119,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("Messages");
});
@ -213,15 +211,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.ToTable("WorkComponents");
});
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.MessageInfo", b =>
{
b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client")
.WithMany("Messages")
.HasForeignKey("ClientId");
b.Navigation("Client");
});
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
{
b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client")
@ -268,8 +257,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Client", b =>
{
b.Navigation("Messages");
b.Navigation("Orders");
});

View File

@ -20,8 +20,6 @@ namespace PlumbingRepairDatabaseImplement.Models
[ForeignKey("ClientId")]
public virtual List<Order> Orders{ get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<MessageInfo> Messages { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{

View File

@ -19,7 +19,6 @@ namespace PlumbingRepairDatabaseImplement.Models
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)
{