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; }
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; }
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 } } }
public IEnumerable<OrderLine> GetOrderDetail(Order order) { return CreateContext().Query<OrderLine>("SELECT * FROM [Order Details] WHERE OrderID = @OrderID", new {order.OrderID}); }