Koscheev.M. S. Lab work 3 Base #5

Closed
1maksim1 wants to merge 3 commits from Lab3_Base into Lab2_Base
2 changed files with 8 additions and 4 deletions
Showing only changes of commit d258735aae - Show all commits

View File

@ -68,7 +68,7 @@ namespace SoftwareInstallationDatabaseImplement.Models
var context = new SoftwareInstallationDatabase();
return new()
{
PackageName = context.Packages.FirstOrDefault(x => x.Id == PackageId)?.PackageName ?? string.Empty,
PackageName = Package?.PackageName ?? string.Empty,
PackageId = PackageId,
Count = Count,
Sum = Sum,

View File

@ -1,4 +1,5 @@
using SoftwareInstallationContracts.BindingModels;
using Microsoft.EntityFrameworkCore;
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.SearchModels;
using SoftwareInstallationContracts.StoragesContracts;
using SoftwareInstallationContracts.ViewModels;
@ -28,7 +29,9 @@ namespace SoftwareInstallationDatabaseImplement.Implements
{
return null;
}
return context.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
return context.Orders
.Include(x => x.Package)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -41,6 +44,7 @@ namespace SoftwareInstallationDatabaseImplement.Implements
{
using var context = new SoftwareInstallationDatabase();
return context.Orders
.Include(x => x.Package)
.Select(x => x.GetViewModel)
.ToList();
}
@ -61,7 +65,7 @@ namespace SoftwareInstallationDatabaseImplement.Implements
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new SoftwareInstallationDatabase();
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
var order = context.Orders.Include(x => x.Package).FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;