Добавлены цельная транзакция при обновлении изделия
This commit is contained in:
parent
f2ca847c6b
commit
b2eb054e22
@ -47,6 +47,8 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
using var context = new ConfectioneryDatabase();
|
using var context = new ConfectioneryDatabase();
|
||||||
return context.Pastries
|
return context.Pastries
|
||||||
|
.Include(x => x.Components)
|
||||||
|
.ThenInclude(x => x.Component)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.Where(x => x.PastryName.Contains(model.PastryName))
|
.Where(x => x.PastryName.Contains(model.PastryName))
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -56,6 +58,8 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new ConfectioneryDatabase();
|
using var context = new ConfectioneryDatabase();
|
||||||
return context.Pastries
|
return context.Pastries
|
||||||
|
.Include(x => x.Components)
|
||||||
|
.ThenInclude(x => x.Component)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -71,13 +75,16 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
newPastry = context.Pastries.Add(newPastry).Entity;
|
newPastry = context.Pastries.Add(newPastry).Entity;
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
model.Id = newPastry.Id;
|
model.Id = newPastry.Id;
|
||||||
newPastry.UpdateComponents(context, model);
|
// newPastry.UpdateComponents(context, model);
|
||||||
return newPastry.GetViewModel;
|
return newPastry.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PastryViewModel? Update(PastryBindingModel model)
|
public PastryViewModel? Update(PastryBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new ConfectioneryDatabase();
|
using var context = new ConfectioneryDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
var pastry = context.Pastries.FirstOrDefault(x => x.Id == model.Id);
|
var pastry = context.Pastries.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (pastry == null)
|
if (pastry == null)
|
||||||
{
|
{
|
||||||
@ -87,7 +94,14 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
pastry.UpdateComponents(context, model);
|
pastry.UpdateComponents(context, model);
|
||||||
context.Update(pastry);
|
context.Update(pastry);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
return pastry.GetViewModel;
|
return pastry.GetViewModel;
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user