protected async Task <Guid> ExecuteCreateAsync(T entity, NestedSetsEntity parentNode) { entity.LeftKey = parentNode.RightKey; entity.RightKey = parentNode.RightKey + 1; entity.Level = parentNode.Level + 1; Guid entityId; using (var transaction = _dbContainer.Database.BeginTransaction()) { try { await ExecutePreInsertSqlCommand(parentNode); entityId = await ExecuteInsertSqlCommand(entity); transaction.Commit(); return(entityId); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }
protected async Task ExecuteMoveAsync(T entity, NestedSetsEntity parentEntity) { if (parentEntity.LeftKey > entity.LeftKey && parentEntity.RightKey < entity.RightKey) { throw new ArgumentException(string.Format("Could move node {0} in child node {1} in {2} table.", entity.Id, parentEntity.Id, _tableName)); } using (var transaction = _dbContainer.Database.BeginTransaction()) { try { await ExecuteMoveSqlCommand(entity, parentEntity); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }