готово к сдаче

This commit is contained in:
maxnes3 2023-02-28 01:06:27 +04:00
parent f8e9e27f73
commit 77e1d7924f

View File

@ -65,27 +65,15 @@ namespace ComputersShopDataBaseImplement.Implements
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
{ {
var newOrder = Order.Create(model); var newOrder = Order.Create(model);
try if (newOrder == null)
{ {
if (newOrder == null) return null;
{
return null;
}
using var context = new ComputersShopDataBase();
context.Orders.Add(newOrder);
context.SaveChanges();
}
catch (DbUpdateException ex)
{
var innerException = ex.InnerException;
while (innerException != null)
{
Console.WriteLine(innerException.Message);
innerException = innerException.InnerException;
}
} }
using var context = new ComputersShopDataBase();
context.Orders.Add(newOrder);
context.SaveChanges();
return GetViewModel(newOrder); return GetViewModel(newOrder);
} }