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); } }); }
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(); }
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()); }
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); }); }