示例#1
0
 private void SetUpData()
 {
     _uow.TryExecuteTransaction(() =>
     {
         _uow.Repository <Article>().Add(new Article {
             Name = "Article01", Price = 100.00m
         });
         _uow.Repository <Customer>().Add(new Customer {
             Name = "Customer01"
         });
     });
 }
示例#2
0
        public void CreateOrder(CreateOrderDTO dto)
        {
            _uow.TryExecuteTransaction(() =>
            {
                var articlesFromDb = dto.ArticlesIds.Select(x => _uow.Repository <Article>().DeferredGet(x)).ToList();

                var order = new Order
                {
                    Customer = new Customer {
                        Id = dto.CustomerId
                    },
                    OrderDate = DateTime.UtcNow,
                    Articles  = articlesFromDb
                };

                order.PaymentTransaction = new PaymentTransaction
                {
                    TransactionCost = articlesFromDb.Sum(x => x.Price),
                    Order           = order
                };

                _uow.Repository <Order>().Add(order);
            });
        }