Пример #1
0
        private static int? ImportUnderlyingFund(CookieCollection cookies, C5_10tblDealOrigination blueAssetInDeal, int targetDealId, int fundID, DealDetailModel deepBlueDealDetail, out string errorMsg)
        {
            errorMsg = string.Empty;
            int? underlyingFundId = null;
            // This is a UF
            // Find the corresponding Underlying Fund from DeepBlue
            List<DeepBlue.Models.Deal.UnderlyingFundListModel> underlyingFunds = UnderlyingFundImport.GetUnderlyingFunds(cookies);
            DeepBlue.Models.Deal.UnderlyingFundListModel uf = underlyingFunds.Where(x => x.FundName.Equals(blueAssetInDeal.Fund, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            if (uf == null) {
                // Try to create UF. Technically the code should not reach here, but i think when I imported the funds, the funds having an "&" were not encoded,
                // so they didnt get imported. So in case that happens, import those here
                underlyingFundId = UnderlyingFundImport.ImportUnderlyingFund(cookies, blueAssetInDeal.Fund);
                if (!underlyingFundId.HasValue) {
                    // This should not happen, as the assumption is that we have already imported all the underlying funds
                    errorMsg = "Unable to find AMB fund from DeepBlue:" + blueAssetInDeal.Fund;
                    Util.WriteError(errorMsg);
                    messageLog.AppendLine(errorMsg);
                }
                else {
                    uf = new UnderlyingFundListModel() { UnderlyingFundId = underlyingFundId.Value };
                }
            }

            if (uf != null) {
                DealUnderlyingFundModel existingUF = deepBlueDealDetail.DealUnderlyingFunds.Where(x => x.UnderlyingFundId == uf.UnderlyingFundId).FirstOrDefault();
                if (existingUF == null) {
                    // Find the corresponding deal from deepBlue
                    string resp = string.Empty;
                    underlyingFundId = CreateDealUnderlyingFund(cookies, blueAssetInDeal, targetDealId, uf.UnderlyingFundId, fundID, out resp);
                    if (underlyingFundId.HasValue) {
                        string newEntry = "New UF in Deal:" + underlyingFundId;
                        Util.WriteNewEntry(newEntry);
                        messageLog.AppendLine(newEntry);
                    }
                    errorMsg = resp;
                }
                else {
                    string msg = existingUF.UnderlyingFundId + " already exists for Deal:" + targetDealId;
                    Util.WriteWarning(msg);
                    messageLog.AppendLine(msg);
                    underlyingFundId = 0;
                }
            }
            return underlyingFundId;
        }
Пример #2
0
 private static List<KeyValuePair<C5_11tblDealOriginationDirects, string>> ImportUnderlyingDirect(CookieCollection cookies, BlueEntities context, C5_10tblDealOrigination blueAssetInDeal, int targetDealId, DealDetailModel deepBlueDealDetail, int fundID)
 {
     List<KeyValuePair<C5_11tblDealOriginationDirects, string>> failedDirects = new List<KeyValuePair<C5_11tblDealOriginationDirects, string>>();
     // This is a direct
     //string issuerName = blueAsset.Fund;
     List<C5_11tblDealOriginationDirects> blueSecurities = context.C5_11tblDealOriginationDirects.Where(x => x.Direct.Equals(blueAssetInDeal.Fund, StringComparison.OrdinalIgnoreCase)).Where(x => x.DealNo == blueAssetInDeal.DealNo).ToList();
     if (blueSecurities.Count > 0) {
         foreach (C5_11tblDealOriginationDirects blueSecurity in blueSecurities) {
             // Equity from blue
             C4_20tblStockTable blueStock = context.C4_20tblStockTable.Where(x => x.StockSymbol.Equals(blueSecurity.StockSymbol, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
             // Find the direct corresponding to the security
             List<AutoCompleteListExtend> equitiesAndFIs = GetDeepBlueEquitiesAndFIs(cookies);
             string searchLabel = string.Format("{0}>>Equity>>{1}", blueStock.Company, blueStock.StockSymbol);
             AutoCompleteListExtend equity = equitiesAndFIs.Where(x => x.otherid == (int)DeepBlue.Models.Deal.Enums.SecurityType.Equity).Where(x => x.value.Equals(blueStock.Company, StringComparison.OrdinalIgnoreCase)).Where(x => x.label.Equals(searchLabel, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
             if (equity == null) {
                 string errorMsg = "Unable to find an equity with issuer:" + blueStock.Company + ", and label:" + searchLabel;
                 Util.WriteError(errorMsg);
                 failedDirects.Add(new KeyValuePair<C5_11tblDealOriginationDirects, string>(blueSecurity, errorMsg));
             }
             else {
                 // Create a DealUnderlyingDirect record
                 string resp = string.Empty;
                 // Make sure the direct/FI is already not part of the deal
                 DealUnderlyingDirectModel direct = deepBlueDealDetail.DealUnderlyingDirects.Where(x => x.SecurityId == equity.otherid2).Where(x => x.SecurityTypeId == (int)DeepBlue.Models.Deal.Enums.SecurityType.Equity).FirstOrDefault();
                 if (direct == null) {
                     int? dealUnderlyingDirectId = CreateDealUnderlyingDirect(cookies, blueSecurity, blueAssetInDeal, targetDealId, equity.otherid2, equity.id, fundID, out resp);
                     if (!dealUnderlyingDirectId.HasValue || dealUnderlyingDirectId.Value <= 0) {
                         string errorMsg = string.Format("Unable to import underlying direct {0}, response from server:{1}", blueSecurity.Direct, resp);
                         Util.WriteError(errorMsg);
                         failedDirects.Add(new KeyValuePair<C5_11tblDealOriginationDirects, string>(blueSecurity, errorMsg));
                     }
                     else {
                         string newEntry = "New DealUnderlyingDirectID:" + dealUnderlyingDirectId;
                         Util.WriteNewEntry(newEntry);
                         messageLog.AppendLine(newEntry);
                     }
                 }
                 else {
                     Util.Log(direct.SecurityId + " is already part of this deal.");
                 }
             }
         }
     }
     else {
         string warningMsg = string.Format("C5_10tblDealOrigination.Fund(which is direct): {0} doesnt have any securities (no records in C5_11tblDealOriginationDirects. C5_11tblDealOriginationDirects.Where(x => x.Direct.Equals(blueAssetInDeal.Fund)).Where(x => x.DealNo == blueAssetInDeal.DealNo) yielded NO results) ", blueAssetInDeal.Fund);
         Util.WriteWarning(warningMsg);
         messageLog.AppendLine(warningMsg);
     }
     return failedDirects;
 }
Пример #3
0
        private static int? CreateDealUnderlyingFund(CookieCollection cookies, C5_10tblDealOrigination blueAsset, int dealId, int underlyingFundId, int fundID, out string resp)
        {
            int? dealUnderlyingtFundID = null;
            resp = string.Empty;
            DealUnderlyingFundModel model = new DealUnderlyingFundModel();
            // The UI asks for the following fields
            model.DealId = dealId;
            model.UnderlyingFundId = underlyingFundId;
            model.FundId = fundID;
            if (blueAsset.FundNAV <= 0) {
                model.FundNAV = 1.0m;
            }
            else {
                model.FundNAV = blueAsset.FundNAV;
            }
            if (blueAsset.CapitalCommitment <= 0) {
                model.CommittedAmount = 1.0m;
            }
            else {
                model.CommittedAmount = blueAsset.CapitalCommitment;
            }

            if(blueAsset.EffectiveDate.HasValue)
                model.EffectiveDate = blueAsset.EffectiveDate;

            if (blueAsset.RecordDate.HasValue)
                model.RecordDate = blueAsset.RecordDate.Value.Date;

            // optional fields
            model.GrossPurchasePrice = blueAsset.GrossPurchasePrice;
            model.UnfundedAmount = blueAsset.AmountUnfunded;

            NameValueCollection formValues = HttpWebRequestUtil.SetUpForm(model, string.Empty, string.Empty);

            // Send the request
            string url = HttpWebRequestUtil.GetUrl("Deal/CreateDealUnderlyingFund");
            byte[] postData = System.Text.Encoding.ASCII.GetBytes(HttpWebRequestUtil.ToFormValue(formValues));
            HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, postData, true, cookies);
            if (response.StatusCode == System.Net.HttpStatusCode.OK) {
                using (Stream receiveStream = response.GetResponseStream()) {
                    // Pipes the stream to a higher level stream reader with the required encoding format.
                    using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {
                        resp = readStream.ReadToEnd();
                        dealUnderlyingtFundID = HttpWebRequestUtil.GetNewKeyFromResponse(resp);
                        response.Close();
                        readStream.Close();
                    }
                }

            }
            return dealUnderlyingtFundID;
        }
Пример #4
0
        private static int? CreateDealUnderlyingDirect(CookieCollection cookies, C5_11tblDealOriginationDirects security, C5_10tblDealOrigination direct, int dealId, int underlyingDirectId, int issuerId, int fundID, out string resp)
        {
            int? dealUnderlyingtDirectID = null;
            resp = string.Empty;
            DealUnderlyingDirectModel model = new DealUnderlyingDirectModel();
            // The UI asks for the following fields
            model.DealId = dealId;
            // model.DealUnderlyingDirectId = underlyingDirectId;
            model.SecurityId = underlyingDirectId;
            model.SecurityTypeId = (int)DeepBlue.Models.Deal.Enums.SecurityType.Equity;
            // TODO: why is the required? We already have the SecurityID, and the issuer can be fetched from the security id
            model.IssuerId = issuerId;
            // TODO: why is this required? may be cos we are using the same screen for creating and updating deal. So probly FundId is required when creating
            model.FundId = fundID;
            // Number Of Shares
            model.NumberOfShares = (int)security.NShares;
            // Purchase Price
            if (security.PurchasePrice.HasValue && security.PurchasePrice.Value > 0) {
                model.PurchasePrice = (decimal)security.PurchasePrice;
            }
            else {
                model.PurchasePrice = 1.0m;
            }

            // FMV
            if (security.FairMarketValue.HasValue && security.FairMarketValue.Value > 0) {
                model.FMV = (decimal)security.FairMarketValue;
            }
            else {
                model.FMV = 1.0m;
            }

            // Tax cost basis per share
            if (security.TaxCostBasis.HasValue && security.TaxCostBasis.Value > 0) {
                model.TaxCostBase = (decimal)security.TaxCostBasis;
            }
            else {
                model.TaxCostBase = 1.0m;
            }
            // Tax cost date
            if (security.TaxCostDate.HasValue)
                model.TaxCostDate = security.TaxCostDate.Value.Date;
            // Record Date
            if (direct.RecordDate.HasValue)
                model.RecordDate = direct.RecordDate.Value.Date;

            NameValueCollection formValues = HttpWebRequestUtil.SetUpForm(model, string.Empty, string.Empty);

            // Send the request
            string url = HttpWebRequestUtil.GetUrl("Deal/CreateDealUnderlyingDirect");
            byte[] postData = System.Text.Encoding.ASCII.GetBytes(HttpWebRequestUtil.ToFormValue(formValues));
            HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, postData, true, cookies);
            if (response.StatusCode == System.Net.HttpStatusCode.OK) {
                using (Stream receiveStream = response.GetResponseStream()) {
                    // Pipes the stream to a higher level stream reader with the required encoding format.
                    using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {
                        resp = readStream.ReadToEnd();
                        dealUnderlyingtDirectID = HttpWebRequestUtil.GetNewKeyFromResponse(resp);
                        response.Close();
                        readStream.Close();
                    }
                }
            }
            return dealUnderlyingtDirectID;
        }
Пример #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the C5_10tblDealOrigination EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToC5_10tblDealOrigination(C5_10tblDealOrigination c5_10tblDealOrigination)
 {
     base.AddObject("C5_10tblDealOrigination", c5_10tblDealOrigination);
 }
Пример #6
0
 /// <summary>
 /// Create a new C5_10tblDealOrigination object.
 /// </summary>
 /// <param name="amberbrookFundNo">Initial value of the AmberbrookFundNo property.</param>
 /// <param name="dealNo">Initial value of the DealNo property.</param>
 /// <param name="fundNo">Initial value of the FundNo property.</param>
 /// <param name="fund">Initial value of the Fund property.</param>
 /// <param name="valueDate">Initial value of the ValueDate property.</param>
 /// <param name="fundNAV">Initial value of the FundNAV property.</param>
 /// <param name="capitalCommitment">Initial value of the CapitalCommitment property.</param>
 /// <param name="amountUnfunded">Initial value of the AmountUnfunded property.</param>
 /// <param name="sSMA_TimeStamp">Initial value of the SSMA_TimeStamp property.</param>
 public static C5_10tblDealOrigination CreateC5_10tblDealOrigination(global::System.String amberbrookFundNo, global::System.Int32 dealNo, global::System.Int32 fundNo, global::System.String fund, global::System.DateTime valueDate, global::System.Decimal fundNAV, global::System.Decimal capitalCommitment, global::System.Decimal amountUnfunded, global::System.Byte[] sSMA_TimeStamp)
 {
     C5_10tblDealOrigination c5_10tblDealOrigination = new C5_10tblDealOrigination();
     c5_10tblDealOrigination.AmberbrookFundNo = amberbrookFundNo;
     c5_10tblDealOrigination.DealNo = dealNo;
     c5_10tblDealOrigination.FundNo = fundNo;
     c5_10tblDealOrigination.Fund = fund;
     c5_10tblDealOrigination.ValueDate = valueDate;
     c5_10tblDealOrigination.FundNAV = fundNAV;
     c5_10tblDealOrigination.CapitalCommitment = capitalCommitment;
     c5_10tblDealOrigination.AmountUnfunded = amountUnfunded;
     c5_10tblDealOrigination.SSMA_TimeStamp = sSMA_TimeStamp;
     return c5_10tblDealOrigination;
 }