Esempio n. 1
0
        private Guid?UpdatePathedNomination(PathedDTO pathedNom)
        {
            try
            {
                bool isFly         = false;
                Guid TransactionID = Guid.Empty;
                foreach (var nom in pathedNom.PathedNomsList)
                {
                    isFly = false;
                    V4_Batch batch = BatchRepository.GetByTransactionID(nom.TransactionId);
                    if (batch != null)
                    {
                        ContractsDTO flyCon = new ContractsDTO();
                        // Contract con = contractService.GetContractByContractNo(nom.Contract, pathedNom.PipelineID);
                        //if (con == null)
                        //{
                        //    isFly = true;
                        //    flyCon = AddContractOnFly(nom.Contract, pathedNom.PipelineID, pathedNom.companyId, pathedNom.ShipperID.ToString(),nom.FuelPercentage);
                        //   // nom.FuelPercentage = flyCon.FuelPercentage;
                        //}
                        //else
                        //{
                        //   // nom.FuelPercentage = con.FuelPercentage;
                        //}
                        TransactionID       = batch.TransactionID;
                        batch.FlowStartDate = nom.StartDate;
                        batch.FlowEndDate   = nom.EndDate;
                        batch.CycleId       = nom.CycleID;
                        batch.NomTypeID     = (int)NomType.Pathed;
                        batch.NomSubCycle   = nom.NomSubCycle;
                        batch.CreatedBy     = pathedNom.ShipperID.ToString();
                        BatchRepository.Update(batch);
                        BatchRepository.SaveChages();

                        List <V4_Nomination> storedNom = NominationsRepository.GetAllNomsByTransactionId(batch.TransactionID);
                        if (storedNom != null && storedNom.Count > 0)
                        {
                            NominationsRepository.deleteAll(storedNom);
                        }
                        V4_Nomination nomination = new V4_Nomination();
                        nomination.AssignIdentification  = nom.AssocContract;
                        nomination.AssociatedContract    = nom.ActCode;
                        nomination.BidTransportationRate = nom.BidTransportRate;
                        nomination.BidupIndicator        = nom.BidUp;
                        nomination.CapacityTypeIndicator = nom.CapacityType;
                        // nomination.ContractNumber = !string.IsNullOrEmpty(flyCon.RequestNo) ? flyCon.RequestNo : nom.Contract;
                        nomination.ContractNumber               = nom.Contract;
                        nomination.DealType                     = nom.DealType;
                        nomination.DeliveryLocationIdentifer    = nom.DelLocID;
                        nomination.DeliveryLocationName         = nom.DelLoc;
                        nomination.DeliveryLocationPropCode     = nom.DelLocProp;
                        nomination.DeliveryRank                 = nom.DelRank;
                        nomination.DelQuantity                  = string.IsNullOrEmpty(nom.DelQuantity.ToString()) ? 0 : Convert.ToInt32(nom.DelQuantity);
                        nomination.DownstreamContractIdentifier = nom.DownContract;
                        nomination.DownstreamIdentifier         = nom.DownID;
                        nomination.DownstreamName               = nom.DownName;
                        nomination.DownstreamPackageId          = nom.DownPkgID;
                        nomination.DownstreamPropCode           = nom.DownIDProp;
                        nomination.DownstreamRank               = nom.DownRank;
                        nomination.ExportDecleration            = nom.Export;
                        nomination.FuelPercentage               = nom.FuelPercentage;
                        //nomination.ImbalancePeriod= not in pathedDTO
                        nomination.MaxRateIndicator            = nom.MaxRate;
                        nomination.NominationSubCycleIndicator = nom.NomSubCycle;
                        nomination.NominationUserData1         = nom.NomUserData1;
                        nomination.NominationUserData2         = nom.NomUserData2;
                        nomination.NominatorTrackingId         = NomTrackingID(9);
                        nomination.PackageId = nom.PkgID;
                        nomination.PathType  = "P";
                        nomination.ProcessingRightIndicator = nom.ProcessingRights;
                        nomination.Quantity = string.IsNullOrEmpty(nom.RecQty) ? 0 : Convert.ToInt32(nom.RecQty);
                        nomination.QuantityTypeIndicator     = "R";    // by default value "Receipt"
                        nomination.ReceiptLocationIdentifier = nom.RecLocID;
                        nomination.ReceiptLocationName       = nom.RecLocation;
                        nomination.receiptLocationPropCode   = nom.RecLocProp;
                        nomination.ReceiptRank = nom.RecRank;
                        nomination.ServiceProviderActivityCode = nom.ActCode;    //duplicate nomination.AssignIdentification
                        nomination.TransactionID   = batch.TransactionID;
                        nomination.TransactionType = nom.TransType;
                        var ttPathed = metadataTransactionTypeRepository.GetTTUsingIdentifier(nom.TransType, "P", pathedNom.PipelineID);
                        nomination.TransactionTypeDesc        = ttPathed != null ? ttPathed.Name : string.Empty;
                        nomination.UpstreamContractIdentifier = nom.UpKContract;
                        nomination.UpstreamIdentifier         = nom.UpID;
                        nomination.UpstreamName      = nom.UpName;
                        nomination.UpstreamPackageId = nom.UpPkgID;
                        nomination.UpstreamPropCode  = nom.UpIDProp;
                        nomination.UpstreamRank      = nom.UpRank;
                        nomination.UnitOfMeasure     = "BZ";
                        NominationsRepository.Add(nomination);
                        NominationsRepository.SaveChages();
                    }
                    else
                    {
                        SavePathedNomination(pathedNom, nom);
                    }
                }
                return(TransactionID);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 2
0
        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.PipelineDuns);
                    if (con == null)
                    {
                        isFly = true;
                        if (RecNom.ServiceRequesterContractCode != null && RecNom.ServiceRequesterContractCode != "")
                        {
                            flyCon = AddContractOnFly(RecNom.ServiceRequesterContractCode, NonpathedNom.PipelineDuns, 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.PipelineDuns                = NonpathedNom.PipelineDuns;
                        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.PipelineDuns);
                    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.PipelineDuns); //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.PipelineDuns, 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.PipelineDuns                = NonpathedNom.PipelineDuns;
                        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.PipelineDuns);
                    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);
        }