Putilin P. A. Lab work 3 Hard #14

Closed
Pavel wants to merge 7 commits from Lab3Hard into Lab2Hard
2 changed files with 11 additions and 6 deletions
Showing only changes of commit fe31f3d034 - Show all commits

View File

@ -1,8 +1,10 @@
using PrecastConcretePlantContracts.BindingModels;
using Microsoft.EntityFrameworkCore;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Enums;
using PrecastConcretePlantDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
namespace PrecastConcretePlantDatabaseImplement.Models
@ -30,6 +32,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models
public Reinforced Reinforced { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
@ -69,7 +72,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models
var context = new PrecastConcretePlantDatabase();
return new()
{
ReinforcedName = context.Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty,
ReinforcedName = Reinforced?.ReinforcedName ?? string.Empty,
ReinforcedId = ReinforcedId,
Count = Count,
Sum = Sum,

View File

@ -1,4 +1,5 @@
using PrecastConcretePlantContracts.BindingModels;
using Microsoft.EntityFrameworkCore;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContract;
using PrecastConcretePlantContracts.ViewModels;
@ -16,7 +17,7 @@ namespace PrecastConcretePlantDatabaseImplement
{
return null;
}
return context.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
return context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -29,6 +30,7 @@ namespace PrecastConcretePlantDatabaseImplement
{
using var context = new PrecastConcretePlantDatabase();
return context.Orders
.Include(x => x.Reinforced)
.Select(x => x.GetViewModel)
.ToList();
}
@ -49,7 +51,7 @@ namespace PrecastConcretePlantDatabaseImplement
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new PrecastConcretePlantDatabase();
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
var order = context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
@ -62,7 +64,7 @@ namespace PrecastConcretePlantDatabaseImplement
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new PrecastConcretePlantDatabase();
var element = context.Orders.FirstOrDefault(x => x.Id == model.Id);
var element = context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);