/// <summary> /// Сохранение коллекции позиций входящих накладных /// </summary> /// <param name="incomingRows">Коллекция позиций входящих накладных</param> public void SaveRows(IEnumerable <IncomingWaybillRow> incomingRows) { var receiptWaybillRows = new List <ReceiptWaybillRow>(); var movementWaybillRows = new List <MovementWaybillRow>(); var changeOwnerWaybillRows = new List <ChangeOwnerWaybillRow>(); var returnFromClientWaybillRows = new List <ReturnFromClientWaybillRow>(); // приходы var receiptWaybillIds = incomingRows.Where(x => x.Type == WaybillType.ReceiptWaybill).Select(x => x.Id); if (receiptWaybillIds.Any()) { receiptWaybillRows = receiptWaybillRepository.GetRows(receiptWaybillIds).Values.ToList <ReceiptWaybillRow>(); ValidationUtils.Assert(receiptWaybillIds.Count() == receiptWaybillRows.Count, "Одна из позиций приходной накладной не найдена. Возможно, она была удалена."); } // перемещения var movementWaybillIds = incomingRows.Where(x => x.Type == WaybillType.MovementWaybill).Select(x => x.Id); if (movementWaybillIds.Any()) { movementWaybillRows = movementWaybillRepository.GetRows(movementWaybillIds).Values.ToList <MovementWaybillRow>(); ValidationUtils.Assert(movementWaybillIds.Count() == movementWaybillRows.Count, "Одна из позиций накладной перемещения не найдена. Возможно, она была удалена."); } // смены собственника var changeOwnerWaybillIds = incomingRows.Where(x => x.Type == WaybillType.ChangeOwnerWaybill).Select(x => x.Id); if (changeOwnerWaybillIds.Any()) { changeOwnerWaybillRows = changeOwnerWaybillRepository.GetRows(changeOwnerWaybillIds).Values.ToList <ChangeOwnerWaybillRow>(); ValidationUtils.Assert(changeOwnerWaybillIds.Count() == changeOwnerWaybillRows.Count, "Одна из позиций накладной смены собственника не найдена. Возможно, она была удалена."); } // возвраты от клиентов var returnFromClientWaybillIds = incomingRows.Where(x => x.Type == WaybillType.ReturnFromClientWaybill).Select(x => x.Id); if (returnFromClientWaybillIds.Any()) { returnFromClientWaybillRows = returnFromClientWaybillRepository.GetRows(returnFromClientWaybillIds).Values.ToList <ReturnFromClientWaybillRow>(); ValidationUtils.Assert(returnFromClientWaybillIds.Count() == returnFromClientWaybillRows.Count, "Одна из позиций накладной возврата от клиента не найдена. Возможно, она была удалена."); } // сохраняем приходы foreach (var rwr in receiptWaybillRows) { var incomingRow = incomingRows.Where(x => x.Id == rwr.Id).First(); rwr.SetOutgoingArticleCount(incomingRow.AcceptedCount, incomingRow.ShippedCount, incomingRow.FinallyMovedCount); rwr.UsageAsManualSourceCount = incomingRow.UsageAsManualSourceCount; receiptWaybillRepository.SaveRow(rwr); } // сохраняем перемещения foreach (var mwr in movementWaybillRows) { var incomingRow = incomingRows.Where(x => x.Id == mwr.Id).First(); mwr.SetOutgoingArticleCount(incomingRow.AcceptedCount, incomingRow.ShippedCount, incomingRow.FinallyMovedCount); mwr.UsageAsManualSourceCount = incomingRow.UsageAsManualSourceCount; movementWaybillRepository.SaveRow(mwr); } // сохраняем смены собственника foreach (var cowr in changeOwnerWaybillRows) { var incomingRow = incomingRows.Where(x => x.Id == cowr.Id).First(); cowr.SetOutgoingArticleCount(incomingRow.AcceptedCount, incomingRow.ShippedCount, incomingRow.FinallyMovedCount); cowr.UsageAsManualSourceCount = incomingRow.UsageAsManualSourceCount; changeOwnerWaybillRepository.SaveRow(cowr); } // сохраняем возвраты от клиентов foreach (var rfcwr in returnFromClientWaybillRows) { var incomingRow = incomingRows.Where(x => x.Id == rfcwr.Id).First(); rfcwr.SetOutgoingArticleCount(incomingRow.AcceptedCount, incomingRow.ShippedCount, incomingRow.FinallyMovedCount); rfcwr.UsageAsManualSourceCount = incomingRow.UsageAsManualSourceCount; returnFromClientWaybillRepository.SaveRow(rfcwr); } }