Example #1
0
        private static int? CreateDealContact(CookieCollection cookies, C6_15tblAmberbrookDealInfo blueDeal, DealDetailModel deepBlueDealDetail, out string resp)
        {
            int? contactId = null;
            resp = string.Empty;

            DeepBlue.Models.Admin.EditDealContactModel model = new Models.Admin.EditDealContactModel();
            model.ContactName = blueDeal.AmberContactName;

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

            // Send the request
            string url = HttpWebRequestUtil.GetUrl("/Admin/UpdateDealContact");
            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();
                        contactId = HttpWebRequestUtil.GetNewKeyFromResponse(resp);
                        response.Close();
                        readStream.Close();
                    }
                }
            }

            return contactId;
        }
Example #2
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;
        }
Example #3
0
        private static int? UpdateDealWithContact(CookieCollection cookies, int contactID, DealDetailModel deepBlueDealDetail, out string resp)
        {
            int? dealId = null;
            resp = string.Empty;

            deepBlueDealDetail.ContactId = contactID;

            NameValueCollection formValues = HttpWebRequestUtil.SetUpForm(deepBlueDealDetail, string.Empty, string.Empty, new string[] { "SellerInfo", "DealExpenses", "DealUnderlyingFunds", "DealUnderlyingDirects" });

            // Send the request
            string url = HttpWebRequestUtil.GetUrl("/Deal/Create");
            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();
                        dealId = HttpWebRequestUtil.GetNewKeyFromResponse(resp);
                        response.Close();
                        readStream.Close();
                    }
                }
            }

            return dealId;
        }
Example #4
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;
 }
Example #5
0
        private static int? ImportDealSellerInfo(CookieCollection cookies, C6_15tblAmberbrookDealInfo blueDeal, DealDetailModel deepBlueDealDetail, out string resp)
        {
            int dealId = deepBlueDealDetail.DealId;
            int? sellerId = null;
            resp = string.Empty;
            string message = string.Empty;

            if (!deepBlueDealDetail.SellerContactId.HasValue) {
                if (!string.IsNullOrEmpty(blueDeal.SellerName)) {
                    DealSellerDetailModel model = new DealSellerDetailModel();
                    model.DealId = deepBlueDealDetail.DealId;
                    model.SellerName = blueDeal.SellerName;
                    model.ContactName = blueDeal.SellerCompany;
                    model.Phone = blueDeal.SellerPhone;
                    model.Email = blueDeal.SellerEmail;
                    model.Fax = blueDeal.SellerFax;
                    model.CompanyName = blueDeal.SellerCompany;
                    model.SellerTypeId = Globals.SellerTypes.Where(x => x.SellerType1.Equals(blueDeal.SellerType)).FirstOrDefault().SellerTypeID;

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

                    // Send the request
                    string url = HttpWebRequestUtil.GetUrl("/Deal/CreateSellerInfo");
                    string data = HttpWebRequestUtil.ToFormValue(formValues);
                    messageLog.AppendLine("Form data:" + data);
                    byte[] postData = System.Text.Encoding.ASCII.GetBytes(data);
                    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();
                                messageLog.AppendLine("Response: " + resp);
                                sellerId = HttpWebRequestUtil.GetNewKeyFromResponse(resp);
                                response.Close();
                                readStream.Close();
                            }
                        }
                    }
                }
                else {
                    message = "Blue Deal: " + blueDeal.DealName + " doesnt have a seller";
                    Util.Log(message);
                    return 0;
                }
            }
            else {
                sellerId = deepBlueDealDetail.SellerContactId;
                message = "Seller Contact already exists:" + sellerId;
                Util.WriteWarning(message);
                messageLog.AppendLine(message);
            }
            return sellerId;
        }
Example #6
0
        private static string ImportDealExpenses(CookieCollection cookies, BlueEntities context, C6_15tblAmberbrookDealInfo blueDeal, DealDetailModel deepBlueDealDetail)
        {
            int dealId = deepBlueDealDetail.DealId;
            StringBuilder sb = new StringBuilder();
            string message = string.Empty;
            if (deepBlueDealDetail.DealExpenses == null || deepBlueDealDetail.DealExpenses.Count == 0) {
                List<C6_40tblDealExpenses> blueDealExpenses = context.C6_40tblDealExpenses.Where(x => x.AmberbrookFundNo == blueDeal.AmberbrookFundNo).Where(x => x.AmberbrookDealNo == blueDeal.DealNo).ToList();
                if (blueDealExpenses.Count > 0) {
                    foreach (C6_40tblDealExpenses blueDealExpense in blueDealExpenses) {
                        string resp = string.Empty;
                        int? dealExpenseId = ImportDealExpense(cookies, blueDealExpense, dealId, out resp);
                        if (!dealExpenseId.HasValue) {
                            string error = "Failed to import deal expense for amb fund#:" + blueDealExpense.AmberbrookFundNo + " ,deal#:" + blueDealExpense.AmberbrookDealNo + ", error:" + resp;
                            // Util.WriteError(error);
                            sb.Append(error);
                        }
                        else {
                            message = "New DealExpenseID:" + dealExpenseId;
                            Util.WriteNewEntry(message);
                            messageLog.AppendLine(message);
                        }
                    }
                }
                else {
                    Util.Log("No deal expenses found to import..");
                }

            }
            else {
                message = "Deal:" + dealId + " already has deal expenses. Skipping Importing Deal Expenses";
                Util.WriteWarning(message);
                messageLog.AppendLine(message);
            }
            return sb.ToString();
        }
Example #7
0
 private static int? ImportDealContact(CookieCollection cookies, C6_15tblAmberbrookDealInfo blueDeal, DealDetailModel deepBlueDealDetail, out string resp)
 {
     int? contactId = null;
     resp = string.Empty;
     string message = string.Empty;
     if (!deepBlueDealDetail.ContactId.HasValue) {
         DealContactList dealContact = ContactsList.Where(c => c.ContactName == blueDeal.AmberContactName).FirstOrDefault();
         if (dealContact != null) {
             contactId = dealContact.ContactId;
             Util.Log("Found contact..");
         }
         else {
             contactId = CreateDealContact(cookies, blueDeal, deepBlueDealDetail, out resp);
             if (contactId.HasValue) {
                 message = "New Contact created:" + contactId + " for deal:" + deepBlueDealDetail.DealId;
                 Util.WriteNewEntry(message);
                 messageLog.AppendLine(message);
                 ContactsList.Add(new DealContactList { ContactName = blueDeal.AmberContactName, ContactId = contactId.Value });
             }
         }
         if (contactId.HasValue) {
             int? dealId = UpdateDealWithContact(cookies, contactId.Value, deepBlueDealDetail, out resp);
             if (!dealId.HasValue) {
                 resp = string.Format("Unable to update deal: {0} with contactId: {1}, Reason: {2}", dealId, contactId, resp);
             }
             else {
                 string success = string.Format("deal: {0} updated with contactId: {1}, DealContactID: {2}", deepBlueDealDetail.DealId, contactId, dealId);
                 Util.WriteNewEntry(success);
                 messageLog.AppendLine(success);
             }
         }
         //
     }
     else {
         contactId = deepBlueDealDetail.ContactId;
         message = "Contact already exists. ContactID:" + contactId;
         Console.Write(message);
     }
     return contactId;
 }
Example #8
0
        private static int? CreateNewDeal(CookieCollection cookies, C6_15tblAmberbrookDealInfo blueDeal, int fundID, int? purchaseTypeId, out string resp)
        {
            int? dealID = null;
            resp = string.Empty;
            // Deal/Create
            DealDetailModel model = new DealDetailModel();

            model.FundId = fundID;
            model.DealName = blueDeal.DealName;
            model.DealNumber = blueDeal.DealNo;
            if (purchaseTypeId.HasValue) {
                model.PurchaseTypeId = purchaseTypeId.Value;
            }
            model.IsPartnered = false;
            // GPP
            // NPP/
            // Total Costs
            // Syn
            // Syndicate
            // AmberBrook Contact Name
            // Seller Type DeepBlue has InvestorEntityType which has same values as SellerType. However, InvestorEntityType is on the Investor level
            // => Contact
            // Seller Name
            // Seller Company
            // Seller Phone
            // Seller Fax
            // Seller Email
            // Seller Comments
            // Comments
            // blueDeal.NAVAllocation

            // model.ContactId;
            // model.IsPartnered;
            // model.PartnerName;
            NameValueCollection formValues = HttpWebRequestUtil.SetUpForm(model, string.Empty, string.Empty);
            formValues.Remove("SellerInfo");
            formValues.Remove("DealExpenses");
            formValues.Remove("DealUnderlyingFunds");
            formValues.Remove("DealUnderlyingDirects");

            // Send the request
            string url = HttpWebRequestUtil.GetUrl("Deal/Create");
            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();
                        dealID = HttpWebRequestUtil.GetNewKeyFromResponse(resp);
                        response.Close();
                        readStream.Close();
                    }
                }

            }
            return dealID;
        }