public void Delete(int id) { _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} started"); using (var transaction = _repositories.BeginTransaction()) { try { var order = _repositories.Orders.Get(id); if (order == null) { throw new LogicException("There is no order with that parameters"); } var od = _repositories.OrderDetails.GetRange(id); if (od == null) { throw new LogicException("There is no order with that parameters"); } _repositories.OrderDetails.RemoveRange(od); _repositories.Orders.Remove(order); _repositories.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.RollBack(); throw ex; } } _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} finished"); }
public void Test() { using var transaction = _repositories.BeginTransaction(); try { //add //remove //delete _repositories.SaveChanges(); transaction.Commit(); } catch (System.Exception) { transaction.Rollback(); throw; } }