Bondarenko M.S. Lab Work 3 hard #13
@ -65,27 +65,15 @@ namespace ComputersShopDataBaseImplement.Implements
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var newOrder = Order.Create(model);
|
||||
try
|
||||
if (newOrder == null)
|
||||
{
|
||||
if (newOrder == 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;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new ComputersShopDataBase();
|
||||
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return GetViewModel(newOrder);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user