небольшие фиксы

This commit is contained in:
Павел Сорокин 2023-03-10 11:11:14 +04:00
parent 235873dc7a
commit ed2f4e0e69

View File

@ -21,9 +21,13 @@ namespace ShipyardDataBaseImplement.Implements
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
var deletedElement = context.Orders
.Include(x => x.Ship)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
return deletedElement;
}
return null;
}
@ -36,6 +40,7 @@ namespace ShipyardDataBaseImplement.Implements
}
using var context = new ShipyardDataBase();
return context.Orders
.Include(x=>x.Ship)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
@ -48,19 +53,11 @@ namespace ShipyardDataBaseImplement.Implements
}
using var context = new ShipyardDataBase();
return context.Orders
.Include(x=>x.Ship)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
private static OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
using var context = new ShipyardDataBase();
var element = context.Ships
.FirstOrDefault(x => x.Id == order.ShipId);
viewModel.ShipName = element.ShipName;
return viewModel;
}
public List<OrderViewModel> GetFullList()
{
@ -81,7 +78,10 @@ namespace ShipyardDataBaseImplement.Implements
using var context = new ShipyardDataBase();
context.Orders.Add(newOrder);
context.SaveChanges();
return newOrder.GetViewModel;
return context.Orders
.Include(x => x.Ship)
.FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
@ -94,7 +94,10 @@ namespace ShipyardDataBaseImplement.Implements
}
order.Update(model);
context.SaveChanges();
return order.GetViewModel;
return context.Orders
.Include(x => x.Ship)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
}
}