PIbd-22. Safiulova K.N. LabWork_05_base #9

Closed
safiulova.k wants to merge 16 commits from LabWork_05 into LabWork_04
Showing only changes of commit 187dfbd01e - Show all commits

View File

@ -14,14 +14,13 @@ namespace AircraftPlantDatabaseImplement.Implements
using var context = new AircraftPlantDatabase();
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue && !model.ClientId.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
{
return new();
}
@ -30,23 +29,12 @@ namespace AircraftPlantDatabaseImplement.Implements
{
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ClientId.HasValue)
{
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
@ -61,23 +49,24 @@ namespace AircraftPlantDatabaseImplement.Implements
using var context = new AircraftPlantDatabase();
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
using var context = new AircraftPlantDatabase();
var newOrder = Order.Create(context, model);
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
using var context = new AircraftPlantDatabase();
context.Orders.Add(newOrder);
context.SaveChanges();
return newOrder.GetViewModel;
return context.Orders
.Include(x => x.Plane)
.FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
@ -88,21 +77,27 @@ namespace AircraftPlantDatabaseImplement.Implements
{
return null;
}
order.Update(model);
context.SaveChanges();
return order.GetViewModel;
return context.Orders
.Include(x => x.Plane)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new AircraftPlantDatabase();
var element = context.Orders.FirstOrDefault(x => x.Id == model.Id);
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
var deletedElement = context.Orders
.Include(x => x.Plane)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
return deletedElement;
}
return null;
}