Putilin P. A. Lab work 3 Hard #14
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user