public async Task <IActionResult> Post(Example example)
        {
            // Use UnitOfWork Default DbSession
            UnitOfWork.BeginTransaction();
            await UnitOfWork.Use <IExampleRepo>().InsertExampleAsync(example);

            UnitOfWork.SaveChanges();
            UnitOfWork.Commit();

            // Use another DbSession
            // Equal to: UnitOfWork.CreateDbSession().BeginTransaction();
            var session = UnitOfWork.CreateDbSession();

            UnitOfWork.BeginTransaction(session);

            example.Id = 0;
            await UnitOfWork.Use <IExampleRepo>(session).InsertExampleAsync(example);

            // Equal to: session.SaveChanges();
            UnitOfWork.SaveChanges(session);

            // Equal to: session.Rollback();
            UnitOfWork.Rollback(session);

            return(NoContent());
        }
예제 #2
0
        /// <summary>
        /// 添加客户集合
        /// </summary>
        private List <Customer> AddCustomers()
        {
            var customers = Customer.CreateCustomers();

            _customerRepository.Add(customers);
            _unitOfWork.Commit();
            _unitOfWork.ClearCache();
            return(customers);
        }
예제 #3
0
        public void TestAdd()
        {
            Guid id    = Guid.NewGuid();
            var  order = new Order(id)
            {
                Name = "Name", Code = "Code"
            };

            _orderRepository.Add(order);
            _unitOfWork.Commit();

            var result = _orderRepository.Single(t => t.Id == id);

            Assert.Equal(id, result.Id);
        }
예제 #4
0
        public IActionResult Index(string id)
        {
            var customer = new Customer();

            customer.Init();
            customer.Balance = 18.52M;
            customer.Name    = Id.ObjectId().Substring(0, 18);
            _customerRepository.Add(customer);

            var order = new Order();

            order.Code = "code";
            order.Name = "a";
            order.Init();
            _orderRepository.Add(order);

            _unitOfWork.Commit();
            return(View());
        }
예제 #5
0
        public void TestAdd()
        {
            int id    = _random.Next(999999999);
            var order = new Product(id)
            {
                Name = "Name", Code = "Code"
            };

            order.ProductType = new ProductType("Type", new List <ProductProperty>()
            {
                new ProductProperty("A", "1"), new ProductProperty("B", "2")
            });
            _productRepository.Add(order);
            _unitOfWork.Commit();

            Product result = _productRepository.GetById(id);

            Assert.Equal(id, result.Id);
            Assert.Equal("Type", result.ProductType.Name);
            Assert.Equal("2", result.ProductType.Properties.ToList()[1].Value);
        }