本文整理汇总了C#中UnitOfWork.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.BeginTransaction方法的具体用法?C# UnitOfWork.BeginTransaction怎么用?C# UnitOfWork.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.BeginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThrowsInvalidOperationExceptionWhenCalledWhenAlreadyInTransaction
public void ThrowsInvalidOperationExceptionWhenCalledWhenAlreadyInTransaction()
{
using (var uow = new UnitOfWork<TestDbContextContainer>())
{
uow.BeginTransaction();
ExceptionTester.CallMethodAndExpectException<InvalidOperationException>(() => uow.BeginTransaction());
}
}
示例2: btnProdRouteAdjustQty_Execute
private void btnProdRouteAdjustQty_Execute(object sender, SimpleActionExecuteEventArgs e)
{
if (View.CurrentObject == null)
return;
ProdRoute prodRoute = (ProdRoute)View.CurrentObject;
float adjustQty = 0;
try
{
adjustQty = float.Parse(
Microsoft.VisualBasic.Interaction.InputBox(string.Format("请输入要调整的数量, 现时最多可调整的数量为{0}\n输入0则取消调整", prodRoute.WipQty + prodRoute.TotalAdjustQty), "调整的数量", "0", 0, 0));
if (adjustQty > prodRoute.WipQty + prodRoute.TotalAdjustQty)
{
XtraMessageBox.Show("输入调整数量大于可调整数 !!");
return;
}
}
catch
{
XtraMessageBox.Show("输入数量错误 !!");
return;
}
UnitOfWork uow = new UnitOfWork();
uow.BeginTransaction();
ProdRoute pRoute = uow.GetObjectByKey<ProdRoute>(prodRoute.Oid);
pRoute.TotalAdjustQty = adjustQty;
pRoute.UpdateTotalIOQty();
pRoute.Save();
uow.CommitChanges();
View.ObjectSpace.Refresh();
}
示例3: btnCancelPurchOrderQty_Click
private void btnCancelPurchOrderQty_Click(object sender, EventArgs e)
{
if (InitExcel("Sheet1") == false)
return;
UnitOfWork uow = new UnitOfWork();
int row = 3;
uow.BeginTransaction();
while (ExcelHelper.GetCellStringValue(xlSht, row, 1) != "")
{
string poNo = ExcelHelper.GetCellStringValue(xlSht, row, 1);
float cancelQty = ExcelHelper.GetCellFloatValue(xlSht, row, 2);
PurchOrderLine poLine = PurchOrderLine.Find(uow, poNo);
if (poLine != null)
{
if (poLine.BalQty >= cancelQty)
{
poLine.ChangeCancelQty(cancelQty);
poLine.Save();
xlSht.Cells[row, 3] = "ok";
}
}
row++;
}
xlWb.Save();
uow.CommitTransaction();
ReleaseExcel();
}
示例4: CreateDepartment
public HttpResponseMessage CreateDepartment(string name, int managerId, int parentDepartmentId)
{
int departmentId;
Department department = null;
using (var uow = new UnitOfWork())
{
_departmentRepository.SetSession(uow.Session);
uow.BeginTransaction();
departmentId = 0;
department = _departmentRepository.CreateDepartment(name);
if (department != null)
{
departmentId = department.DepartmentId;
_departmentRepository.UpdateDepartmentsParentDepartment(departmentId, parentDepartmentId);
_departmentRepository.UpdateDepartmentsManager(departmentId, managerId);
uow.Session.Flush();
uow.Commit();
}
}
return new HttpResponseMessage((department == null) ? HttpStatusCode.BadRequest : HttpStatusCode.OK);
}
示例5: btnConfirm_Click
private void btnConfirm_Click(object sender, EventArgs e)
{
UnitOfWork uow;
SubPurchOrderLine subPoLine;
if (poLine.NeedQty != float.Parse(txtOKQty.Text) + float.Parse(txtDefectQty.Text))
{
XtraMessageBox.Show("良品数 + 来料不良数 需要等于要求数量");
txtOKQty.Focus();
return;
}
if (float.Parse(txtDefectQty.Text) < 0 || float.Parse(txtOKQty.Text) < 0)
{
XtraMessageBox.Show("良品数 或 来料不良数 不能少于零");
txtOKQty.Focus();
return;
}
uow = new UnitOfWork();
uow.BeginTransaction();
subPoLine = uow.FindObject<SubPurchOrderLine>(new BinaryOperator("Oid", poLine.Oid));
subPoLine.OrderStatus = SubPurchOrderLine.PurchOrderStatus.Active;
subPoLine.Save();
// 若有来料不良, 即建立一个假生产单
if (float.Parse(txtDefectQty.Text) > 0)
{
CreateProdOrderEntry(uow);
}
uow.CommitChanges();
this.Close();
}
示例6: BeginTransaction_calls_DbContext_BeginTransaction
public void BeginTransaction_calls_DbContext_BeginTransaction()
{
var uow = new UnitOfWork(_dbContextFactoryMock.Object);
uow.BeginTransaction();
_dbContextMock.Verify(x => x.BeginTransaction(), Times.Once);
}
示例7: GetAllEmployees
public IHttpActionResult GetAllEmployees()
{
using (var uow = new UnitOfWork())
{
uow.BeginTransaction();
var employees = _employeeRepository.GetAllEmployees();
var ret = Json(employees);
return ret;
}
}
示例8: CreateJobTitle
public HttpResponseMessage CreateJobTitle(string id)
{
using (var uow = new UnitOfWork())
{
uow.BeginTransaction();
_jobTitleRepository.SetSession(uow.Session);
_jobTitleRepository.CreateJobTitle(id);
uow.Commit();
return MakeResponseMessage();
}
}
示例9: ReturnsTrueWhenInTransaction
public void ReturnsTrueWhenInTransaction()
{
using (var uow = new UnitOfWork<TestDbContextContainer>())
{
Assert.IsFalse(uow.IsInTransaction);
uow.BeginTransaction();
Assert.IsTrue(uow.IsInTransaction);
uow.CommitTransaction();
Assert.IsFalse(uow.IsInTransaction);
}
}
示例10: DeleteJobTitle
public HttpResponseMessage DeleteJobTitle(int id)
{
using (var uow = new UnitOfWork())
{
uow.BeginTransaction();
_jobTitleRepository.SetSession(uow.Session);
var ret = _jobTitleRepository.DeleteJobTitle(id);
if (ret == 0)
return MakeResponseMessage(HttpStatusCode.NotFound);
uow.Commit();
return MakeResponseMessage();
}
}
示例11: btnRecalSubItem_Execute
private void btnRecalSubItem_Execute(object sender, SimpleActionExecuteEventArgs e)
{
using (UnitOfWork uow = new UnitOfWork())
{
uow.BeginTransaction();
foreach (SubItem sItem in View.SelectedObjects)
{
SubItem subItem = uow.GetObjectByKey<SubItem>(sItem.Oid);
subItem.UpdateQty();
subItem.updateTimeStamp = false;
subItem.Save();
}
uow.CommitChanges();
}
View.Refresh();
}
示例12: DeleteDepartmentById
public IHttpActionResult DeleteDepartmentById(int id)
{
using (var uow = new UnitOfWork())
{
uow.BeginTransaction();
_departmentRepository.SetSession(uow.Session);
int numDeleted = _departmentRepository.DeleteDepartmentById(id);
try
{
uow.Commit();
}
catch (Exception)
{
numDeleted = 0;
}
return Json<bool>(numDeleted > 0);
}
}
示例13: UnitOfWork_Transaction_Test
public void UnitOfWork_Transaction_Test()
{
using(IDataContextAsync context = new NorthwindContext())
using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
{
using (IUnitOfWorkAsync unitOfWorkAsync = new UnitOfWork(context))
{
IRepositoryAsync<Customer> customerRepository = new Repository<Customer>(context, unitOfWork);
IService<Customer> customerService = new CustomerService(customerRepository, unitOfWorkAsync);
try
{
unitOfWork.BeginTransaction();
customerService.Insert(new Customer { CustomerID = "YODA", CompanyName = "SkyRanch", ObjectState = ObjectState.Added});
customerService.Insert(new Customer { CustomerID = "JEDI", CompanyName = "SkyRanch", ObjectState = ObjectState.Added});
var customer = customerService.Find("YODA");
Assert.AreSame(customer.CustomerID, "YODA");
customer = customerService.Find("JEDI");
Assert.AreSame(customer.CustomerID, "JEDI");
// save
var saveChangesAsync = unitOfWork.SaveChanges();
//Assert.AreSame(saveChangesAsync, 2);
// Will cause an exception, cannot insert customer with the same CustomerId (primary key constraint)
customerService.Insert(new Customer { CustomerID = "JEDI", CompanyName = "SkyRanch", ObjectState = ObjectState.Added });
//save
unitOfWork.SaveChanges();
unitOfWork.Commit();
}
catch (Exception e)
{
unitOfWork.Rollback();
}
}
}
}
示例14: btnRecalcSubItemMonthly_Execute
private void btnRecalcSubItemMonthly_Execute(object sender, SimpleActionExecuteEventArgs e)
{
if (View.CurrentObject == null)
return;
using (UnitOfWork uow = new UnitOfWork())
{
uow.BeginTransaction();
foreach (SubItemMonthly iMonthly in View.SelectedObjects)
{
SubItemMonthly itemMonthly = uow.GetObjectByKey<SubItemMonthly>(iMonthly.Oid);
itemMonthly.UpdateQty();
itemMonthly.Save();
}
uow.CommitChanges();
View.ObjectSpace.Refresh();
}
}
示例15: GetJobTitleFromId
public HttpResponseMessage GetJobTitleFromId(int id)
{
using (var uow = new UnitOfWork())
{
uow.BeginTransaction();
_jobTitleRepository.SetSession(uow.Session);
var jobTitle = _jobTitleRepository.GetJobTitleFromId(id);
if (jobTitle == null)
return MakeResponseMessage(HttpStatusCode.BadRequest);
var response = new HttpResponseMessage();
response.Headers.Location = new Uri(_indexUri);
response.Headers.Add("JobTitle", jobTitle.Description);
response.StatusCode = HttpStatusCode.OK;
return response;
}
}