Example #1
0
        public string GetReferencedBaselineId(Agreement agreement)
        {
            string ret = "";

            try
            {
                //based on the type of the agreement, we get the referenced Agreement

                if (agreement.GetType() == typeof(Proposal))
                {
                    var proposal = agreement as Proposal;

                    //Get request for Proposal
                    var rfps = _agreements.Where(a => a.Value.GetType() == typeof(RequestForProposal)).Select(a => a.Value as RequestForProposal).ToList();
                    var rfp  = rfps.FirstOrDefault(r => r.RequestForProposalId == proposal.ReferencedRfpId && r.BuyerId == proposal.BuyerId);
                    if (rfp != null)
                    {
                        ret = rfp.AgreementId;
                    }
                }
                else if (agreement.GetType() == typeof(PurchaseOrder))
                {
                    var purchaseOrder = agreement as PurchaseOrder;

                    //Get Proposals
                    var proposals = _agreements.Where(a => a.Value.GetType() == typeof(Proposal)).Select(a => a.Value as Proposal).ToList();
                    var proposal  = proposals.FirstOrDefault(p => p.ProposalId == purchaseOrder.ReferencedProposalId && p.SupplierId == purchaseOrder.SupplierId);
                    if (proposal != null)
                    {
                        ret = proposal.AgreementId;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, "Unexpected Error in GetReferencedBaselineId");
            }

            return(ret);
        }