コード例 #1
0
ファイル: OrderService.cs プロジェクト: vebin/DapperContext
        public OrderLine CreateOrderDetail(Order order, Product product)
        {
            var line = new OrderLine
            {
                ProductID = product.ProductID,
                Quantity = 1,
                UnitPrice = product.UnitPrice.GetValueOrDefault(0)
            };

            order.Lines.Add(line);
            return line;
        }
コード例 #2
0
ファイル: OrderService.cs プロジェクト: vebin/DapperContext
        public OrderLine CreateOrderDetail(Order order, Product product, decimal price, short quantity, float discount)
        {
            var line = new OrderLine
            {
                ProductID = product.ProductID,
                Discount = discount,
                Quantity = quantity,
                UnitPrice = price
            };

            order.Lines.Add(line);
            return line;
        }
コード例 #3
0
ファイル: OrderService.cs プロジェクト: vebin/DapperContext
        public void SaveOrder(Order order)
        {
            using (var context = CreateContext())
            {
                using (var scope = context.CreateUnitOfWork())
                {
                    order.OrderID = context.Query<int>("" +
                        "INSERT INTO Orders (CustomerID, OrderDate) VALUES (@CustomerID, @OrderDate);" +
                        "SELECT CAST(SCOPE_IDENTITY() as int)",
                        new {order.CustomerID, OrderDate = order.OrderDate.Value}).Single();

                    foreach (var line in order.Lines)
                    {
                        line.OrderID = order.OrderID;
                        context.Execute("INSERT INTO [Order Details] (OrderID, ProductID, Discount, UnitPrice, Quantity) VALUES (@OrderID, @ProductID, @Discount, @UnitPrice, @Quantity)",
                        new { line.OrderID, line.ProductID, line.Discount, line.UnitPrice, line.Quantity });
                    }

                    scope.SaveChanges(); //And commit this unit of work
                }
            }
        }
コード例 #4
0
 public IEnumerable<OrderLine> GetOrderDetail(Order order)
 {
     return CreateContext().Query<OrderLine>("SELECT * FROM [Order Details] WHERE OrderID = @OrderID",
         new {order.OrderID});
 }