PIbd-23 Dyakonov R R Hard Lab work 3 #8

Closed
dyakonovr wants to merge 5 commits from lab3_hard into lab2_hard
3 changed files with 7 additions and 7 deletions
Showing only changes of commit a03f0c7e69 - Show all commits

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace SoftwareInstallationDatabaseImplement.Implements
{
@ -51,14 +52,14 @@ namespace SoftwareInstallationDatabaseImplement.Implements
using var context = new SoftwareInstallationDatabase();
return context.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
return context.Orders.Include(x => x.Package).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
}
public List<OrderViewModel> GetFullList()
{
using var context = new SoftwareInstallationDatabase();
return context.Orders.Select(x => x.GetViewModel).Select(x => GetPackageName(x)).ToList();
return context.Orders.Include(x => x.Package).Select(x => x.GetViewModel).ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)

View File

@ -66,6 +66,7 @@ namespace SoftwareInstallationDatabaseImplement.Models
{
Id = Id,
PackageId = PackageId,
PackageName = Package.PackageName,
Count = Count,
Sum = Sum,
Status = Status,

View File

@ -92,12 +92,10 @@ namespace SoftwareInstallationFileImplement.Implements
}
private OrderViewModel GetPackageName(OrderViewModel viewModel)
{
foreach (var package in source.Packages)
var package = source.Packages.FirstOrDefault(x => x.Id == viewModel.PackageId);
if (package != null)
{
if (package.Id == viewModel.PackageId)
{
viewModel.PackageName = package.PackageName;
}
viewModel.PackageName = package.PackageName;
}
return viewModel;
}