private Order CreateClientOrder(Order basketOrder, IEnumerable <OrderPosition> orderPositions, DbTransaction dbTran) { // Создаём клиентский заказ var order = _orderProcessor.CreateClientOrder(basketOrder, orderPositions, dbTran); // Привязываем к новому заказу позиции из корзины var orderPositionsWithChildren = orderPositions .Union( orderPositions.SelectMany(op => op.ChildOrderPositions)); foreach (var orderPosition in orderPositionsWithChildren) { _orderPositionProcessor.UpdateOrderPosition(orderPosition, order.Id, dbTran); } // Привязываем к новому заказу позиции ИМ-ов var positionIms = orderPositionsWithChildren .Where(op => op.PositionIm != null) .Select(op => op.PositionIm); foreach (var positionIm in positionIms) { // Меняем заказ и статус позиции ИМ-а на "Вёрстка" _positionImProcessor.UpdatePositionIm(positionIm, order.Id, maketStatusId: 3, dbTran); } var orderImTypeIds = positionIms .GroupBy(pims => pims.PositionImType.OrderImType.Id) .Select(g => g.Key) .ToList(); foreach (var orderImTypeId in orderImTypeIds) { // Создаём ИМ нового заказа var orderIm = _orderImProcessor.CreateOrderIm(order.Id, orderImTypeId, _orderImProcessor.ProcessOrderImStatus, dbTran); // Если ИМ заказа корзины больше не нужен - удаляем его var basketOrderIm = _orderImProcessor.GetOrderIm(basketOrder.Id, orderImTypeId); if (_orderImProcessor.NeedDeleteOrderIm(basketOrderIm)) { _orderImProcessor.DeleteOrderIm(basketOrderIm, dbTran); } } // Обновляем заказ-корзину _orderProcessor.UpdateOrder(basketOrder.Id, dbTran); return(order); }
public void CreatePositionIm(int businessUnitId, int orderId, int orderPositionId, OrderPositionData opd, DbTransaction dbTran) { Action <int, int, DbTransaction> setOrderIm = (orderId, orderImTypeId, dbTran) => { var orderIm = _orderImProcessor.GetOrderIm(orderId, orderImTypeId); if (orderIm == null) { _orderImProcessor.CreateOrderIm(orderId, orderImTypeId, null, dbTran); } }; if (opd.StringData != null) { var positionIm = _positionImFactory.Create(orderId, orderPositionId, positionImTypeId: 1); _repository.SetPositionIm(positionIm, newTaskFile: false, newMaketFile: false, isActual: true, dbTran); _stringProcessor.CreateFullString(businessUnitId, opd.ClientId, orderPositionId, opd.StringData, dbTran); setOrderIm(orderId, 1, dbTran); } if (opd.ModuleData != null) { var positionIm = _positionImFactory.Create(orderId, orderPositionId, positionImTypeId: 2); positionIm = _repository.SetPositionIm(positionIm, newTaskFile: true, newMaketFile: false, isActual: true, dbTran); _moduleProcessor.CreateModule(opd.ClientId, businessUnitId, orderPositionId, dbTran); var bytes = Base64ToBytesConverter.Convert(opd.ModuleData.Base64String); var taskFileDate = (DateTime)positionIm.TaskFileDate; _moduleMaketProcessor.CreateSampleImage(orderPositionId, bytes, "ImgTask", taskFileDate); _moduleMaketProcessor.CreateModuleGraphics(orderPositionId, bytes, opd.ModuleData.Name); setOrderIm(orderId, 2, dbTran); } }