public static void CopyFrom(this Order newOrder, Order oldOrder) { newOrder.CustomerNumber = oldOrder.CustomerNumber; newOrder.OrderDate = oldOrder.OrderDate; newOrder.DeliveryDate = oldOrder.DeliveryDate; newOrder.TotalPrice = oldOrder.TotalPrice; if (oldOrder.OrderPositions != null) { newOrder.OrderPositions = oldOrder.OrderPositions.Select(x => new OrderPosition { PositionNumber = x.PositionNumber, Pieces = x.Pieces, Text = x.Text, Price = x.Price, Total = x.Total }).ToList(); } }
public void AddOrder(Order order) { _orderRepository.Add(order); _unitOfWork.Commit(); }
public OrderModel ReOrder(int orderId) { var entity = _orderRepository.AllIncluding(x => x.OrderPositions).SingleOrDefault(x => x.ID == orderId); if (entity != null) { // Copy from the existing order and then set the order date to today var newOrder = new Order(); newOrder.CopyFrom(entity); newOrder.OrderDate = DateTime.Now; newOrder.DeliveryDate = null; _orderRepository.Add(newOrder); _unitOfWork.Commit(); var orderModel = new OrderModel { OrderId = newOrder.ID, OrderDate = newOrder.OrderDate, CustomerNumber = newOrder.CustomerNumber, DeliveryDate = newOrder.DeliveryDate, TotalPrice = newOrder.TotalPrice }; if (newOrder.OrderPositions != null) { orderModel.OrderPositions = new List<OrderPositionModel>(); foreach (var positionEntity in newOrder.OrderPositions) { var positionModel = new OrderPositionModel { OrderId = positionEntity.OrderID, PositionOrderId = positionEntity.ID, PositionNumber = positionEntity.PositionNumber, Pieces = positionEntity.Pieces, Text = positionEntity.Text, Price = positionEntity.Price, }; orderModel.OrderPositions.Add(positionModel); } } return orderModel; } return null; }
public int AddOrder(OrderModel orderModel) { if (orderModel.OrderPositions.Count < 1) return -1; var order = new Order { CustomerNumber = orderModel.CustomerNumber.Trim(), TotalPrice = orderModel.TotalPrice, DeliveryDate = orderModel.DeliveryDate, OrderDate = DateTime.Now }; foreach (var position in orderModel.OrderPositions) { var positionOrder = new OrderPosition { OrderID = order.ID, Pieces = position.Pieces != null ? position.Pieces.Trim() : null, PositionNumber = position.PositionNumber, Price = position.Price, Text = position.Text != null ? position.Text.Trim() : null, Total = position.Total }; order.TotalPrice += positionOrder.Total; order.OrderPositions.Add(positionOrder); } try { _orderBusinessService.AddOrder(order); } catch (Exception ex) { //TODO: throw; } return order.ID; }