/// <summary> /// Сохранение коллекции позиций исходящих накладных /// </summary> /// <param name="outgoingRows">Коллекция позиций исходящих накладных</param> public void SaveRows(IEnumerable <OutgoingWaybillRow> outgoingRows) { if (!outgoingRows.Any()) { return; } var movementWaybillRows = new List <MovementWaybillRow>(); var changeOwnerWaybillRows = new List <ChangeOwnerWaybillRow>(); var writeoffWaybillRows = new List <WriteoffWaybillRow>(); var expenditureWaybillRows = new List <ExpenditureWaybillRow>(); // перемещения var movementWaybillIds = outgoingRows.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 = outgoingRows.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 writeoffWaybillIds = outgoingRows.Where(x => x.Type == WaybillType.WriteoffWaybill).Select(x => x.Id); if (writeoffWaybillIds.Any()) { writeoffWaybillRows = writeoffWaybillRepository.GetRows(writeoffWaybillIds).Values.ToList <WriteoffWaybillRow>(); ValidationUtils.Assert(writeoffWaybillIds.Count() == writeoffWaybillRows.Count, "Одна из позиций накладной списания не найдена. Возможно, она была удалена."); } // реализации var expenditureWaybillIds = outgoingRows.Where(x => x.Type == WaybillType.ExpenditureWaybill).Select(x => x.Id); if (expenditureWaybillIds.Any()) { expenditureWaybillRows = expenditureWaybillRepository.GetRows(expenditureWaybillIds).Values.ToList <ExpenditureWaybillRow>(); ValidationUtils.Assert(expenditureWaybillIds.Count() == expenditureWaybillRows.Count, "Одна из позиций накладной реализации не найдена. Возможно, она была удалена."); } // сохраняем перемещения foreach (var mwr in movementWaybillRows) { var outgoingRow = outgoingRows.Where(x => x.Id == mwr.Id).First(); mwr.OutgoingWaybillRowState = outgoingRow.State; movementWaybillRepository.SaveRow(mwr); } // сохраняем смены собственника foreach (var cowr in changeOwnerWaybillRows) { var outgoingRow = outgoingRows.Where(x => x.Id == cowr.Id).First(); cowr.OutgoingWaybillRowState = outgoingRow.State; changeOwnerWaybillRepository.SaveRow(cowr); } // сохраняем списания foreach (var wwr in writeoffWaybillRows) { var outgoingRow = outgoingRows.Where(x => x.Id == wwr.Id).First(); wwr.OutgoingWaybillRowState = outgoingRow.State; writeoffWaybillRepository.SaveRow(wwr); } // сохраняем реализации foreach (var ewr in expenditureWaybillRows) { var outgoingRow = outgoingRows.Where(x => x.Id == ewr.Id).First(); ewr.OutgoingWaybillRowState = outgoingRow.State; expenditureWaybillRepository.SaveRow(ewr); } }
/// <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); } }