Доделал
This commit is contained in:
parent
7f831ad75d
commit
95899c05ee
@ -20,6 +20,7 @@ namespace MotorPlantDatabaseImplement.Models
|
|||||||
public DateTime? DateImplement { get; private set; }
|
public DateTime? DateImplement { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int EngineId { get; private set; }
|
public int EngineId { get; private set; }
|
||||||
|
public virtual Engine Engine { get; private set; }
|
||||||
|
|
||||||
public static Order? Create(OrderBindingModel model)
|
public static Order? Create(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -58,6 +59,7 @@ namespace MotorPlantDatabaseImplement.Models
|
|||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
Id = Id,
|
Id = Id,
|
||||||
|
EngineName = Engine.EngineName
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using MotorPlantContracts.BindingModels;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
using MotorPlantContracts.SearchModels;
|
using MotorPlantContracts.SearchModels;
|
||||||
using MotorPlantContracts.StoragesContracts;
|
using MotorPlantContracts.StoragesContracts;
|
||||||
using MotorPlantContracts.ViewModels;
|
using MotorPlantContracts.ViewModels;
|
||||||
@ -11,21 +12,21 @@ namespace MotorPlantDatabaseImplement.Implements
|
|||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new MotorPlantDataBase();
|
using var context = new MotorPlantDataBase();
|
||||||
return context.Orders
|
return context.Orders.Include(x => x.Engine).Select(x => x.GetViewModel).ToList();
|
||||||
.Select(x => AccessEngineStorage(x.GetViewModel))
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue)
|
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new MotorPlantDataBase();
|
using var context = new MotorPlantDataBase();
|
||||||
return context.Orders
|
if (model.DateFrom.HasValue)
|
||||||
.Where(x => x.Id == model.Id)
|
{
|
||||||
.Select(x => AccessEngineStorage(x.GetViewModel))
|
return context.Orders.Include(x => x.Engine).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList();
|
||||||
.ToList();
|
}
|
||||||
|
return context.Orders.Where(x => x.Id == model.Id).Include(x => x.Engine)
|
||||||
|
.Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
@ -34,7 +35,7 @@ namespace MotorPlantDatabaseImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new MotorPlantDataBase();
|
using var context = new MotorPlantDataBase();
|
||||||
return AccessEngineStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
|
return context.Orders.Include(x => x.Engine).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -46,7 +47,7 @@ namespace MotorPlantDatabaseImplement.Implements
|
|||||||
using var context = new MotorPlantDataBase();
|
using var context = new MotorPlantDataBase();
|
||||||
context.Orders.Add(newOrder);
|
context.Orders.Add(newOrder);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return AccessEngineStorage(newOrder.GetViewModel);
|
return context.Orders.Include(x => x.Engine).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -59,7 +60,7 @@ namespace MotorPlantDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
order.Update(model);
|
order.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return AccessEngineStorage(order.GetViewModel);
|
return context.Orders.Include(x => x.Engine).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -70,7 +71,7 @@ namespace MotorPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return AccessEngineStorage(element.GetViewModel);
|
return element.GetViewModel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user