public Guid?SaveAllNonPathedNominations(NonPathedDTO NonpathedNom) { bool isFly = false; Guid TransactionID = Guid.Empty; #region Save Receipt Noms try { foreach (var RecNom in NonpathedNom.ReceiptNoms) { isFly = false; ContractsDTO flyCon = new ContractsDTO(); Contract con = contractService.GetContractByContractNo(RecNom.ServiceRequesterContractCode, NonpathedNom.PipelineId); if (con == null) { isFly = true; if (RecNom.ServiceRequesterContractCode != null && RecNom.ServiceRequesterContractCode != "") { flyCon = AddContractOnFly(RecNom.ServiceRequesterContractCode, NonpathedNom.PipelineId, NonpathedNom.CompanyId, NonpathedNom.UserId.ToString(), RecNom.FuelPercentage); } //RecNom.FuelPercentage = flyCon.FuelPercentage; } //else //{ // RecNom.FuelPercentage = con.FuelPercentage; //} V4_Batch batch = null; if (RecNom.TransactionId != null) { batch = _batchRepo.GetByTransactionID((RecNom.TransactionId).Value); } if (batch != null) { // Batch Update TransactionID = batch.TransactionID; batch.FlowStartDate = RecNom.StartDateTime; batch.FlowEndDate = RecNom.EndDateTime; batch.CycleId = RecNom.CycleId; batch.NomTypeID = (int)NomType.NonPathed; batch.NomSubCycle = RecNom.NomSubCycle; _batchRepo.Update(batch); _batchRepo.SaveChages(); // Exists Nominations Remove List <V4_Nomination> storedNom = _nominationRepo.GetAllNomsByTransactionId(batch.TransactionID); if (storedNom != null && storedNom.Count > 0) { _nominationRepo.deleteAll(storedNom); } } else { // New Batch Create Random ran = new Random(); string path = Path.GetRandomFileName(); path = path.Replace(".", ""); batch = new V4_Batch(); batch.CreatedBy = NonpathedNom.UserId.ToString(); batch.CreatedDate = DateTime.Now; batch.CycleId = RecNom.CycleId; batch.Description = "Non-Pathed Receipt Nomination" + DateTime.Now.ToString(); batch.FlowEndDate = RecNom.EndDateTime; batch.FlowStartDate = RecNom.StartDateTime; batch.IsActive = true; batch.NomTypeID = (int)NomType.NonPathed; batch.PakageCheck = false; batch.PipelineID = NonpathedNom.PipelineId; batch.RankingCheck = false; batch.ReferenceNumber = ran.Next(999999999).ToString(); batch.ScheduleDate = DateTime.MaxValue; batch.ServiceRequester = NonpathedNom.ShipperDuns; batch.ShowZeroCheck = false; batch.ShowZeroDn = false; batch.ShowZeroUp = false; batch.StatusID = (int)NomStatus.Draft; batch.SubmitDate = DateTime.MaxValue; batch.TransactionSetControlNumber = path; batch.UpDnContractCheck = false; batch.UpDnPkgCheck = false; batch.NomSubCycle = RecNom.NomSubCycle; _batchRepo.Add(batch); _batchRepo.SaveChages(); TransactionID = batch.TransactionID; } var ttPathed = metadataTransactionTypeRepository.GetTTUsingIdentifier(RecNom.TransactionType, "NP", NonpathedNom.PipelineId); V4_Nomination nomRec = new V4_Nomination { TransactionID = batch.TransactionID, AssignIdentification = "", AssociatedContract = "", BidTransportationRate = "", BidupIndicator = "", CapacityTypeIndicator = "", ContractNumber = isFly ? flyCon.RequestNo : RecNom.ServiceRequesterContractCode, DealType = "", DeliveryLocationIdentifer = "", DeliveryLocationName = "", DeliveryLocationPropCode = "", DeliveryRank = "", DelQuantity = 0, DownstreamContractIdentifier = "", DownstreamIdentifier = "", DownstreamPackageId = "", DownstreamPropCode = "", DownstreamName = "", DownstreamRank = "", ExportDecleration = "", FuelPercentage = RecNom.FuelPercentage, ImbalancePeriod = "", MaxDeliveredQty = 0, MaxRateIndicator = "", NominationSubCycleIndicator = RecNom.NomSubCycle, NominationUserData1 = "", NominationUserData2 = "", NominatorTrackingId = NomTrackingID(9), PackageId = RecNom.PackageId, PackageId2 = "", PathRank = "", PathType = "NPR", ProcessingRightIndicator = "", receiptLocationPropCode = RecNom.ReceiptLocProp, ReceiptLocationName = RecNom.ReceiptLocName, ReceiptLocationIdentifier = RecNom.ReceiptLocId, ReceiptRank = RecNom.ReceiptRank, Route = "", ServiceProviderActivityCode = "", TransactionType = RecNom.TransactionType, TransactionTypeDesc = ttPathed != null ? ttPathed.Name : string.Empty, UnitOfMeasure = "BZ", UpstreamContractIdentifier = RecNom.UpstreamK, UpstreamIdentifier = RecNom.UpstreamId, UpstreamName = RecNom.UpstreamName, UpstreamPackageId = "", UpstreamPropCode = RecNom.UpstreamProp, UpstreamRank = "", Quantity = Convert.ToInt32(RecNom.ReceiptQty), QuantityTypeIndicator = "R" // For receipt }; _nominationRepo.Add(nomRec); _nominationRepo.SaveChages(); } } catch (Exception ex) { throw new Exception("Non-Pathed receive noms " + ex.Message + " innerEx:- " + ex.InnerException); } #endregion #region Save Delivery Noms try { foreach (var DeliveryNom in NonpathedNom.DeliveryNoms) { isFly = false; ContractsDTO flyCon = new ContractsDTO(); Contract con = contractService.GetContractByContractNo(DeliveryNom.ServiceRequesterContractCode, NonpathedNom.PipelineId); //contractService.GetAll().Where(a => a.RequestNo == nom.Contract && a.PipelineID == pathedNom.PipelineID).FirstOrDefault(); if (con == null) { isFly = true; if (DeliveryNom.ServiceRequesterContractCode != null && DeliveryNom.ServiceRequesterContractCode != "") { flyCon = AddContractOnFly(DeliveryNom.ServiceRequesterContractCode, NonpathedNom.PipelineId, NonpathedNom.CompanyId, NonpathedNom.UserId.ToString(), DeliveryNom.FuelPercentage); } //DeliveryNom.FuelPercentage = flyCon.FuelPercentage; } //else //{ // DeliveryNom.FuelPercentage = con.FuelPercentage; //} V4_Batch batch = null; if (DeliveryNom.TransactionId != null) { batch = _batchRepo.GetByTransactionID((DeliveryNom.TransactionId).Value); } if (batch != null) { // batch TransactionID = batch.TransactionID; batch.FlowStartDate = DeliveryNom.StartDateTime; batch.FlowEndDate = DeliveryNom.EndDateTime; batch.CycleId = DeliveryNom.CycleId; batch.NomTypeID = (int)NomType.NonPathed; batch.NomSubCycle = DeliveryNom.NomSubCycle; _batchRepo.Update(batch); _batchRepo.SaveChages(); // Exists Nomination Remove List <V4_Nomination> storedNom = _nominationRepo.GetAllNomsByTransactionId(batch.TransactionID); if (storedNom != null && storedNom.Count > 0) { _nominationRepo.deleteAll(storedNom); } } else { // New Batch Create Random ran = new Random(); string path = Path.GetRandomFileName(); path = path.Replace(".", ""); batch = new V4_Batch(); batch.CreatedBy = NonpathedNom.UserId.ToString(); batch.CreatedDate = DateTime.Now; batch.CycleId = DeliveryNom.CycleId; batch.Description = "Non-Pathed Receipt Nomination" + DateTime.Now.ToString(); batch.FlowEndDate = DeliveryNom.EndDateTime; batch.FlowStartDate = DeliveryNom.StartDateTime; batch.IsActive = true; batch.NomTypeID = (int)NomType.NonPathed; batch.PakageCheck = false; batch.PipelineID = NonpathedNom.PipelineId; batch.RankingCheck = false; batch.ReferenceNumber = ran.Next(999999999).ToString(); batch.ScheduleDate = DateTime.MaxValue; batch.ServiceRequester = NonpathedNom.ShipperDuns; batch.ShowZeroCheck = false; batch.ShowZeroDn = false; batch.ShowZeroUp = false; batch.StatusID = (int)NomStatus.Draft; batch.SubmitDate = DateTime.MaxValue; batch.TransactionSetControlNumber = path; batch.UpDnContractCheck = false; batch.UpDnPkgCheck = false; batch.NomSubCycle = DeliveryNom.NomSubCycle; _batchRepo.Add(batch); _batchRepo.SaveChages(); TransactionID = batch.TransactionID; } // Add Nomination var ttPathed = metadataTransactionTypeRepository.GetTTUsingIdentifier(DeliveryNom.TransactionType, "NP", NonpathedNom.PipelineId); V4_Nomination nomDel = new V4_Nomination { TransactionID = batch.TransactionID, AssignIdentification = "", AssociatedContract = "", BidTransportationRate = "", BidupIndicator = "", CapacityTypeIndicator = "", ContractNumber = isFly ? flyCon.RequestNo : DeliveryNom.ServiceRequesterContractCode, DealType = "", DeliveryLocationIdentifer = DeliveryNom.DeliveryLocId, DeliveryLocationName = DeliveryNom.DeliveryLocName, DeliveryLocationPropCode = DeliveryNom.DeliveryLocProp, DeliveryRank = DeliveryNom.DeliveryRank, DelQuantity = Convert.ToInt32(DeliveryNom.DeliveryQty), DownstreamContractIdentifier = DeliveryNom.DnstreamK, DownstreamIdentifier = DeliveryNom.DnstreamId, DownstreamName = DeliveryNom.DeliveryLocName, DownstreamPackageId = "", DownstreamPropCode = DeliveryNom.DnstreamProp, DownstreamRank = "", ExportDecleration = "", FuelPercentage = DeliveryNom.FuelPercentage, ImbalancePeriod = "", MaxDeliveredQty = 0, MaxRateIndicator = "", NominationSubCycleIndicator = DeliveryNom.NomSubCycle, NominationUserData1 = "", NominationUserData2 = "", NominatorTrackingId = NomTrackingID(9), PackageId = DeliveryNom.PackageId, PackageId2 = "", PathRank = "", PathType = "NPD", ProcessingRightIndicator = "", receiptLocationPropCode = "", ReceiptLocationName = "", ReceiptLocationIdentifier = "", ReceiptRank = "", Route = "", ServiceProviderActivityCode = "", TransactionType = DeliveryNom.TransactionType, TransactionTypeDesc = ttPathed != null ? ttPathed.Name : string.Empty, UnitOfMeasure = "BZ", UpstreamContractIdentifier = "", UpstreamIdentifier = "", UpstreamName = "", UpstreamPackageId = "", UpstreamPropCode = "", UpstreamRank = "", Quantity = 0, QuantityTypeIndicator = "D" }; _nominationRepo.Add(nomDel); _nominationRepo.SaveChages(); } } catch (Exception ex) { throw new Exception("Non-Pathed delivery noms " + ex.Message + " innerEx:- " + ex.InnerException);; } #endregion return(TransactionID); }
private Guid?SavePathedNomination(PathedDTO pathedNom, PathedNomDetailsDTO pathed) { Guid transactionId = new Guid(); try { ContractsDTO flyCon = new ContractsDTO(); Contract con = contractService.GetContractByContractNo(pathed.Contract, pathedNom.PipelineID); if (con == null) { flyCon = AddContractOnFly(pathed.Contract, pathedNom.PipelineID, pathedNom.companyId, pathedNom.ShipperID.ToString(), pathed.FuelPercentage); //pathed.FuelPercentage = flyCon.FuelPercentage; } //else { // pathed.FuelPercentage = con.FuelPercentage; //} Random ran = new Random(); string path = Path.GetRandomFileName(); path = path.Replace(".", ""); V4_Batch batch = new V4_Batch(); batch.CreatedBy = pathedNom.ShipperID.ToString(); batch.CreatedDate = DateTime.Now; batch.CycleId = pathed.CycleID; batch.Description = "Pathed Nomination" + DateTime.Now.ToString(); batch.FlowEndDate = pathed.EndDate; batch.FlowStartDate = pathed.StartDate; batch.NomSubCycle = pathed.NomSubCycle; batch.IsActive = true; //var nomType = PipelineTransactionTypeMapRepository.GetById(pathed.TransTypeMapId); //if (nomType==null || nomType.PathType=="P") // batch.NomTypeID = (int)NomType.Pathed; //else if (nomType.PathType == "NP") // batch.NomTypeID = (int)NomType.NonPathed; batch.NomTypeID = (int)NomType.Pathed; batch.PakageCheck = false; batch.PipelineID = pathedNom.PipelineID; batch.RankingCheck = false; batch.ReferenceNumber = ran.Next(999999999).ToString(); batch.ScheduleDate = DateTime.MaxValue; batch.ServiceRequester = pathedNom.DunsNo; batch.ShowZeroCheck = false; batch.ShowZeroDn = false; batch.ShowZeroUp = false; batch.StatusID = (int)NomStatus.Draft; batch.SubmitDate = DateTime.MaxValue; batch.TransactionSetControlNumber = path; batch.UpDnContractCheck = false; batch.UpDnPkgCheck = false; BatchRepository.Add(batch); BatchRepository.SaveChages(); //if (nomType == null || nomType.PathType == "P") //{ V4_Nomination nomination = new V4_Nomination(); nomination.AssignIdentification = pathed.AssocContract; nomination.AssociatedContract = pathed.ActCode; nomination.BidTransportationRate = pathed.BidTransportRate; nomination.BidupIndicator = pathed.BidUp; nomination.CapacityTypeIndicator = pathed.CapacityType; nomination.ContractNumber = !string.IsNullOrEmpty(flyCon.RequestNo) ? flyCon.RequestNo : pathed.Contract; nomination.DealType = pathed.DealType; nomination.DeliveryLocationIdentifer = pathed.DelLocID; nomination.DeliveryLocationName = pathed.DelLoc; nomination.DeliveryLocationPropCode = pathed.DelLocProp; nomination.DeliveryRank = pathed.DelRank; nomination.DelQuantity = string.IsNullOrEmpty(pathed.DelQuantity.ToString()) ? 0 : Convert.ToInt32(pathed.DelQuantity); nomination.DownstreamContractIdentifier = pathed.DownContract; nomination.DownstreamIdentifier = pathed.DownID; nomination.DownstreamName = pathed.DownName; nomination.DownstreamPackageId = pathed.DownPkgID; nomination.DownstreamPropCode = pathed.DownIDProp; nomination.DownstreamRank = pathed.DownRank; nomination.ExportDecleration = pathed.Export; nomination.FuelPercentage = pathed.FuelPercentage; //nomination.ImbalancePeriod= not in pathedDTO nomination.MaxRateIndicator = pathed.MaxRate; nomination.NominationSubCycleIndicator = pathed.NomSubCycle; nomination.NominationUserData1 = pathed.NomUserData1; nomination.NominationUserData2 = pathed.NomUserData2; nomination.NominatorTrackingId = NomTrackingID(9); nomination.PackageId = pathed.PkgID; //nomination.PathRank=pathed.p nomination.PathType = "P"; nomination.ProcessingRightIndicator = pathed.ProcessingRights; nomination.Quantity = string.IsNullOrEmpty(pathed.RecQty) ? 0 : Convert.ToInt32(pathed.RecQty); nomination.QuantityTypeIndicator = "R"; // By default value "Receipt" nomination.ReceiptLocationIdentifier = pathed.RecLocID; nomination.ReceiptLocationName = pathed.RecLocation; nomination.receiptLocationPropCode = pathed.RecLocProp; nomination.ReceiptRank = pathed.RecRank; //nomination.Route=pathed. nomination.ServiceProviderActivityCode = pathed.ActCode; //duplicate nomination.AssignIdentification nomination.TransactionID = batch.TransactionID; nomination.TransactionType = pathed.TransType; var ttPathed = metadataTransactionTypeRepository.GetTTUsingIdentifier(pathed.TransType, "P", pathedNom.PipelineID); if (ttPathed != null) { nomination.TransactionTypeDesc = ttPathed.Name; } else { nomination.TransactionTypeDesc = string.Empty; } nomination.UpstreamContractIdentifier = pathed.UpKContract; nomination.UpstreamIdentifier = pathed.UpID; nomination.UpstreamName = pathed.UpName; nomination.UpstreamPackageId = pathed.UpPkgID; nomination.UpstreamPropCode = pathed.UpIDProp; nomination.UpstreamRank = pathed.UpRank; nomination.UnitOfMeasure = "BZ"; NominationsRepository.Add(nomination); NominationsRepository.SaveChages(); transactionId = batch.TransactionID; //} //else if (nomType.PathType == "NP") //{ // var ttPathed = metadataTransactionTypeRepository.GetTTUsingIdentifier(pathed.TransType, "NP", pathedNom.PipelineID); // V4_Nomination nomRec= new V4_Nomination // { // TransactionID = batch.TransactionID, // AssignIdentification = "", // AssociatedContract = pathed.AssocContract, // BidTransportationRate = pathed.BidTransportRate, // BidupIndicator = pathed.BidUp, // CapacityTypeIndicator = pathed.CapacityType, // ContractNumber = pathed.Contract, // DealType = pathed.DealType, // DeliveryLocationIdentifer = "", // DeliveryLocationPropCode = "", // DeliveryRank = "", // DelQuantity = 0, // DownstreamContractIdentifier = "", // DownstreamIdentifier = "", // DownstreamPackageId = "", // DownstreamPropCode = "", // DownstreamRank = "", // ExportDecleration = pathed.Export, // FuelPercentage = pathed.FuelPercentage, // ImbalancePeriod = "", // MaxDeliveredQty = 0, // MaxRateIndicator = pathed.MaxRate, // NominationSubCycleIndicator = pathed.NomSubCycle, // NominationUserData1 = "", // NominationUserData2 = "", // NominatorTrackingId = NomTrackingID(9), // PackageId = pathed.PkgIDRec, // PackageId2 = "", // PathRank = "", // PathType = "NPR", // ProcessingRightIndicator = pathed.ProcessingRights, // receiptLocationPropCode = pathed.RecLocProp, // ReceiptLocationIdentifier = pathed.RecLocID, // ReceiptRank = pathed.RecRank, // Route = "", // ServiceProviderActivityCode = "", // TransactionType = pathed.TransType, // TransactionTypeDesc = (ttPathed!=null)?ttPathed.Name:string.Empty, // UnitOfMeasure = "BZ", // UpstreamContractIdentifier = pathed.UpKContract, // UpstreamIdentifier = pathed.UpID, // UpstreamPackageId = pathed.UpPkgID, // UpstreamPropCode = pathed.UpIDProp, // UpstreamRank = pathed.UpRank, // Quantity = string.IsNullOrEmpty(pathed.RecQty) ? 0 : Convert.ToInt32(pathed.RecQty), // QuantityTypeIndicator = "R" // }; // V4_Nomination nomDel = new V4_Nomination // { // TransactionID = batch.TransactionID, // AssignIdentification = "", // AssociatedContract = pathed.AssocContract, // BidTransportationRate = pathed.BidTransportRate, // BidupIndicator = pathed.BidUp, // CapacityTypeIndicator = pathed.CapacityType, // ContractNumber = pathed.Contract, // DealType = pathed.DealType, // DeliveryLocationIdentifer = pathed.DelLocID, // DeliveryLocationPropCode = pathed.DelLocProp, // DeliveryRank = pathed.DelRank, // DelQuantity = Convert.ToInt32(pathed.DelQuantity), // DownstreamContractIdentifier = pathed.DownContract, // DownstreamIdentifier = pathed.DownID, // DownstreamPackageId = pathed.DownPkgID, // DownstreamPropCode = pathed.DownIDProp, // DownstreamRank = pathed.DownRank, // ExportDecleration = pathed.Export, // FuelPercentage = pathed.FuelPercentage, // ImbalancePeriod = "", // MaxDeliveredQty = 0, // MaxRateIndicator = pathed.MaxRate, // NominationSubCycleIndicator = pathed.NomSubCycle, // NominationUserData1 = "", // NominationUserData2 = "", // NominatorTrackingId = NomTrackingID(9), // PackageId2 = "", // PackageId = pathed.PkgID, // PathRank = "", // PathType = "NPD", // ProcessingRightIndicator = pathed.ProcessingRights, // receiptLocationPropCode = "", // ReceiptLocationIdentifier = pathed.ProcessingRights, // ReceiptRank = "", // Route = "", // ServiceProviderActivityCode = pathed.ActCode, // TransactionType = pathed.TransType, // TransactionTypeDesc = ttPathed!=null ? ttPathed.Name : string.Empty, // UnitOfMeasure = "BZ", // UpstreamContractIdentifier = "", // UpstreamIdentifier = "", // UpstreamPackageId = "", // UpstreamPropCode = "", // UpstreamRank = "", // Quantity = 0, // QuantityTypeIndicator = "D" // }; // if (pathed.PathedHybridNonpathedType == 5 || pathed.PathedHybridNonpathedType == 7 || pathed.PathedHybridNonpathedType == 10) // { // NominationsRepository.Add(nomDel); // } // 5 7 10 delivery only // receipt only- 3,9, // both- 1,2,4,6,8 // else if (pathed.PathedHybridNonpathedType == 3 || pathed.PathedHybridNonpathedType == 9) // { // NominationsRepository.Add(nomRec); // } // else // { // NominationsRepository.Add(nomRec); // NominationsRepository.Add(nomDel); // } // NominationsRepository.SaveChages(); //} return(transactionId); } catch (Exception ex) { return(null); } }