コード例 #1
0
ファイル: OrderService.cs プロジェクト: neozhu/sqlhelper2
        public void CreateOrder(Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }
            if (!order.Lines.Any())
            {
                throw new ArgumentException("order.Lines");
            }

            order.OrderId     = NewOrderId();
            order.Status      = "newcreated";
            order.CreatedTime = DateTime.Now;

            DatabaseFactory.CreateDatabase("mall").ExecuteTransaction(db => {
                var orderRepo = new OrderRepo(db);
                orderRepo.Save(order);

                var orderLineRepo = new OrderLineRepo(db);
                foreach (var orderLine in order.Lines)
                {
                    orderLineRepo.Save(order.OrderId, orderLine);
                }
            });
        }
コード例 #2
0
ファイル: OrderRepo.cs プロジェクト: 18098924759/sqlhelper2
        public Order GetWithLinesByOrderId(string orderId)
        {
            var sql = @"select * from [Order] where OrderId = @orderId";
            return _Database.ExecuteDataReader(sql, new {orderId}, dr => {
                var order = Order.GetByDataReader(dr);

                var orderLineRepo = new OrderLineRepo(_Database);
                order.Lines = orderLineRepo.GetByOrderId(order.OrderId);

                return order;
            }).FirstOrDefault();
        }
コード例 #3
0
        public Order GetWithLinesByOrderId(string orderId)
        {
            var sql = @"select * from [Order] where OrderId = @orderId";

            return(_Database.ExecuteDataReader(sql, new { orderId }, dr => {
                var order = Order.GetByDataReader(dr);

                var orderLineRepo = new OrderLineRepo(_Database);
                order.Lines = orderLineRepo.GetByOrderId(order.OrderId);

                return order;
            }).FirstOrDefault());
        }
コード例 #4
0
        public void CreateOrder(Order order)
        {
            if (order == null)
                throw new ArgumentNullException("order");
            if (!order.Lines.Any())
                throw new ArgumentException("order.Lines");

            order.OrderId = NewOrderId();
            order.Status = "newcreated";
            order.CreatedTime = DateTime.Now;

            DatabaseFactory.CreateDatabase("mall").ExecuteTransaction(db => {
                var orderRepo = new OrderRepo(db);
                orderRepo.Save(order);

                var orderLineRepo = new OrderLineRepo(db);
                foreach (var orderLine in order.Lines)
                    orderLineRepo.Save(order.OrderId, orderLine);
            });
        }