当前位置: 首页>>代码示例>>C#>>正文


C# UnitOfWork.BeginTransaction方法代码示例

本文整理汇总了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());
                }
            }
开发者ID:pars87,项目名称:Catel,代码行数:9,代码来源:UnitOfWorkFacts.cs

示例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();
        }
开发者ID:kamchung322,项目名称:Namwah,代码行数:35,代码来源:ProdRoute_View.cs

示例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();
        }
开发者ID:kamchung322,项目名称:Namwah,代码行数:31,代码来源:frmDataImport.cs

示例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);
        }
开发者ID:abalkany,项目名称:nexient-net-orgchart-webapi,代码行数:26,代码来源:DepartmentController.cs

示例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();
        }
开发者ID:kamchung322,项目名称:Namwah,代码行数:34,代码来源:frmSubConfirmIQC.cs

示例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);
        }
开发者ID:qstream-inactive,项目名称:ENTech-Store,代码行数:8,代码来源:UnitOfWorkTest.cs

示例7: GetAllEmployees

        public IHttpActionResult GetAllEmployees()
        {
            using (var uow = new UnitOfWork())
            {
                uow.BeginTransaction();
                var employees = _employeeRepository.GetAllEmployees();
                var ret = Json(employees);

                return ret;
            }
        }
开发者ID:abalkany,项目名称:nexient-net-orgchart-webapi,代码行数:11,代码来源:EmployeeController.cs

示例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();
            }
        }
开发者ID:abalkany,项目名称:nexient-net-orgchart-webapi,代码行数:13,代码来源:JobTitleController.cs

示例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);
                }
            }
开发者ID:pars87,项目名称:Catel,代码行数:15,代码来源:UnitOfWorkFacts.cs

示例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();
            }
        }
开发者ID:abalkany,项目名称:nexient-net-orgchart-webapi,代码行数:16,代码来源:JobTitleController.cs

示例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();
        }
开发者ID:kamchung322,项目名称:Namwah,代码行数:18,代码来源:SubItem_View.cs

示例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);
            }
        }
开发者ID:abalkany,项目名称:nexient-net-orgchart-webapi,代码行数:19,代码来源:DepartmentController.cs

示例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();
                    }
                }
            }
        }
开发者ID:tishansoft,项目名称:Asp.net-AngularJS-Example,代码行数:42,代码来源:UnitOfWorkTests.cs

示例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();
            }
        }
开发者ID:kamchung322,项目名称:Namwah,代码行数:20,代码来源:SubItemMonthly_View.cs

示例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;
            }
        }
开发者ID:abalkany,项目名称:nexient-net-orgchart-webapi,代码行数:20,代码来源:JobTitleController.cs


注:本文中的UnitOfWork.BeginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。