本文整理汇总了C#中Castle.ActiveRecord.TransactionScope.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# TransactionScope.Flush方法的具体用法?C# TransactionScope.Flush怎么用?C# TransactionScope.Flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Castle.ActiveRecord.TransactionScope
的用法示例。
在下文中一共展示了TransactionScope.Flush方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_execute_SQL
public void Can_execute_SQL()
{
using (var transaction = new TransactionScope())
{
var user = repository.Save(new User {Email = "[email protected]", Name = "User1"});
transaction.Flush();
repository.ExecuteSql(string.Format("UPDATE User SET Email=\"[email protected]\"", user.Id));
transaction.Flush();
repository.Refresh(user);
Assert.AreEqual("[email protected]", user.Email);
}
}
示例2: UpdateConnections
public static void UpdateConnections(DataTable dt)
{
using (var transaction = new TransactionScope(TransactionMode.New))
{
foreach (DataRow row in dt.Rows)
{
int id;
if (Int32.TryParse(row[0].ToString(), out id))
{
var bw = Baseword.Find(id);
var flexions = new string[row.ItemArray.Count() - 1];
for (int i = 1; i < row.ItemArray.Count(); i++)
{
flexions[i - 1] = row.ItemArray[i].ToString();
}
bw.UpdateFlexions(flexions);
Console.Out.WriteLine(string.Format("{3}: Updated Baseword {0}/{1} with id:{2}",
dt.Rows.IndexOf(row), dt.Rows.Count, bw.Id,
DateTime.Now.ToString(CultureInfo.InvariantCulture)));
}
}
transaction.Flush();
transaction.VoteCommit();
}
}
示例3: DeleteConfirmed
public ActionResult DeleteConfirmed(string id)
{
var item = Model.User.Find (id);
using (var scope = new TransactionScope ()) {
foreach (var x in item.Privileges.ToList ()) {
x.Delete ();
}
scope.Flush ();
item.DeleteAndFlush ();
}
return RedirectToAction ("Index");
}
示例4: EditarFuncionario
/// <summary>
/// funcionalidade de edição de um registro de funcionario
/// </summary>
/// <param name="id"></param>
private void EditarFuncionario(int id)
{
//abre a transação
using (TransactionScope trans = new TransactionScope())
{
try
{
//consulta o funcionário pelo ID
Funcionario funcionario = Funcionario.FindByPrimaryKey(id);
//atribui os dados que estão na página
funcionario.Nome = Request.Form["ctl00$ContentPlaceHolder1$txtNome"]; //txtNome.Text.Trim();
funcionario.Endereco = Request.Form["ctl00$ContentPlaceHolder1$txtEndereco"]; //txtEndereco.Text.Trim();
funcionario.CPF = Request.Form["ctl00$ContentPlaceHolder1$txtCpf"]; //txtCpf.Text.Trim();
funcionario.RG = Request.Form["ctl00$ContentPlaceHolder1$txtRG"]; //txtRG.Text.Trim();
funcionario.Telefone = Request.Form["ctl00$ContentPlaceHolder1$txtTelefone"]; //txtTelefone.Text.Trim();
funcionario.DataNascimento = DateTime.Parse(Request.Form["ctl00$ContentPlaceHolder1$txtDataNascimento"]);
funcionario.DataAdmissao = DateTime.Parse(Request.Form["ctl00$ContentPlaceHolder1$txtDataContratacao"]);
funcionario.NumeroCarteiraTrabalho = Request.Form["ctl00$ContentPlaceHolder1$txtCarteiratrabalho"];// txtCarteiratrabalho.Text.Trim();
funcionario.Cargo = Request.Form["ctl00$ContentPlaceHolder1$txtCargo"];// txtCargo.Text.Trim();
//atualiza o funcionário
funcionario.UpdateAndFlush();
if (Request.Form["ctl00$ContentPlaceHolder1$txtSalario"].Trim() != string.Empty)
{
//verifica se tem salário e se houve alteração do valor
decimal valor = decimal.Parse(Request.Form["ctl00$ContentPlaceHolder1$txtSalario"]);
if (funcionario.SalarioVigente != null)
{
if (funcionario.SalarioVigente.Valor != valor)
{
//atribui o valor da salário
funcionario.SalarioVigente.FinalVigencia = DateTime.Today;
funcionario.SalarioVigente.Vigente = false;
//atualiza o registro
funcionario.SalarioVigente.UpdateAndFlush();
if (valor != 0)
{
Salario salario = new Salario();
salario.InicioVigencia = DateTime.Today;
salario.Vigente = true;
salario.Valor = valor;
salario.FuncionarioDoSalario = funcionario;
salario.CreateAndFlush();
}
}
}
}
else
{
if (funcionario.SalarioVigente != null)
{
funcionario.SalarioVigente.FinalVigencia = DateTime.Today;
funcionario.SalarioVigente.Vigente = false;
funcionario.SalarioVigente.UpdateAndFlush();
}
}
//commit da transação
trans.VoteCommit();
}
catch (Exception ex)
{
//rollback da transação
trans.VoteRollBack();
throw ex;
}
finally
{
trans.Flush();
}
}
}
示例5: CadastrarNovoFuncionario
/// <summary>
/// grava um novo registro de funcionário
/// </summary>
private void CadastrarNovoFuncionario()
{
//abre a transação
using (TransactionScope trans = new TransactionScope())
{
try
{
//atribui os dados da página para o registro de funcionário e salva no banco
Funcionario funcionario = new Funcionario();
funcionario.Nome = txtNome.Text.Trim();
funcionario.Endereco = txtEndereco.Text.Trim();
funcionario.CPF = txtCpf.Text.Trim();
funcionario.RG = txtRG.Text.Trim();
funcionario.Telefone = txtTelefone.Text.Trim();
funcionario.DataNascimento = DateTime.Parse(txtDataNascimento.Text.Trim());
funcionario.DataAdmissao = DateTime.Parse(txtDataContratacao.Text.Trim());
funcionario.NumeroCarteiraTrabalho = txtCarteiratrabalho.Text.Trim();
funcionario.Cargo = txtCargo.Text.Trim();
funcionario.CreateAndFlush();
if (txtSalario.Text.Trim() != string.Empty)
{
decimal valor = decimal.Parse(txtSalario.Text.Trim());
if (valor != 0)
{
//cria o registro do salário
Salario salario = new Salario();
salario.InicioVigencia = DateTime.Parse(txtDataContratacao.Text.Trim());
salario.Vigente = true;
salario.Valor = valor;
salario.FuncionarioDoSalario = funcionario;
salario.CreateAndFlush();
}
}
//commit da transação
trans.VoteCommit();
}
catch (Exception ex)
{
//rollback da transação
trans.VoteRollBack();
//sobe o erro para o método que o chamou, onde será gravado em um arquivo de texto
throw ex;
}
finally
{
//fecha a transasção
trans.Flush();
}
}
}
示例6: DeleteConfirmed
public ActionResult DeleteConfirmed(int id)
{
var item = Customer.Find (id);
try {
using (var scope = new TransactionScope ()) {
foreach (var discount in item.Discounts) {
discount.Delete ();
}
scope.Flush ();
item.DeleteAndFlush ();
}
return PartialView ("_DeleteSuccesful", item);
} catch (Exception) {
return PartialView ("DeleteUnsuccessful");
}
}
示例7: Create
public ActionResult Create(Product item)
{
item.Supplier = Supplier.TryFind (item.SupplierId);
if (!ModelState.IsValid) {
return PartialView ("_Create", item);
}
item.MinimumOrderQuantity = 1;
item.TaxRate = WebConfig.DefaultVAT;
item.IsTaxIncluded = WebConfig.IsTaxIncluded;
item.PriceType = WebConfig.DefaultPriceType;
item.Photo = WebConfig.DefaultPhotoFile;
using (var scope = new TransactionScope ()) {
item.Create ();
foreach (var l in PriceList.Queryable.ToList ()) {
var price = new ProductPrice {
Product = item,
List = l,
Value = WebConfig.DefaultPrice
};
price.Create ();
}
scope.Flush ();
}
return PartialView ("_CreateSuccesful", item);
}
示例8: ApplyPayment
public ActionResult ApplyPayment(SalesOrderPayment item)
{
var entity = new SalesOrderPayment {
SalesOrder = SalesOrder.TryFind (item.SalesOrder.Id),
Payment = CustomerPayment.TryFind (item.PaymentId),
Amount = item.Amount
};
var balance = entity.SalesOrder.Balance - GetRefunds (entity.SalesOrder.Id);
if (entity.Amount > entity.Payment.Balance) {
entity.Amount = entity.Payment.Balance;
}
balance -= entity.Amount;
using (var scope = new TransactionScope ()) {
if (balance <= 0) {
entity.SalesOrder.IsPaid = true;
entity.SalesOrder.Update ();
}
if (entity.Amount > 0) {
entity.Create ();
}
scope.Flush ();
}
return PartialView ("_ApplyPaymentSuccesful");
}
示例9: PhysicalCountAdjustmentConfirmed
public ActionResult PhysicalCountAdjustmentConfirmed(int id)
{
var entity = InventoryReceipt.Find (id);
string sql = @"SELECT s.product ProductId, s.lot_number LotNumber, s.expiration_date ExpirationDate, s.serial_number SerialNumber, SUM(s.quantity) Quantity
FROM lot_serial_tracking s
INNER JOIN inventory_receipt_detail d ON s.product = d.product
WHERE d.receipt = :id AND s.warehouse = :warehouse AND s.date < :date
GROUP BY s.product, s.lot_number, s.expiration_date, s.serial_number
HAVING SUM(s.quantity) <> 0";
var items = (IList<dynamic>) ActiveRecordMediator<Product>.Execute (delegate (ISession session, object instance) {
var query = session.CreateSQLQuery (sql);
query.AddScalar ("ProductId", NHibernateUtil.Int32);
query.AddScalar ("LotNumber", NHibernateUtil.String);
query.AddScalar ("ExpirationDate", NHibernateUtil.Date);
query.AddScalar ("SerialNumber", NHibernateUtil.String);
query.AddScalar ("Quantity", NHibernateUtil.Decimal);
query.SetInt32 ("id", entity.Id);
query.SetInt32 ("warehouse", entity.Warehouse.Id);
query.SetDateTime ("date", entity.ModificationTime);
return query.DynamicList ();
}, null);
using (var scope = new TransactionScope ()) {
var dt = entity.ModificationTime.AddMilliseconds (-1);
foreach (var x in items) {
var item = new LotSerialTracking {
Source = TransactionType.InventoryAdjustment,
Reference = entity.Id,
Date = dt,
Warehouse = entity.Warehouse,
Product = Product.Find (x.ProductId),
Quantity = -x.Quantity,
LotNumber = x.LotNumber,
ExpirationDate = x.ExpirationDate,
SerialNumber = x.SerialNumber
};
item.Create ();
}
scope.Flush ();
}
return RedirectToAction ("Receipts");
}