public override void Setup() { base.Setup(); // Spin up mock repository and attach to controller MockService = new Mock<IUnderlyingFundCashDistributionService>(); DefaultUnderlyingFundCashDistribution = new DeepBlue.Models.Entity.UnderlyingFundCashDistribution(MockService.Object); MockService.Setup(x => x.SaveUnderlyingFundCashDistribution(It.IsAny<DeepBlue.Models.Entity.UnderlyingFundCashDistribution>())); }
public void SaveUnderlyingFundCashDistribution(UnderlyingFundCashDistribution underlyingFundCashDistribution) { using (DeepBlueEntities context = new DeepBlueEntities()) { if (underlyingFundCashDistribution.UnderlyingFundCashDistributionID == 0) { context.UnderlyingFundCashDistributions.AddObject(underlyingFundCashDistribution); } else { // Define an ObjectStateEntry and EntityKey for the current object. EntityKey key = default(EntityKey); object originalItem = null; key = context.CreateEntityKey("UnderlyingFundCashDistributions", underlyingFundCashDistribution); // Get the original item based on the entity key from the context // or from the database. if (context.TryGetObjectByKey(key, out originalItem)) { // Call the ApplyCurrentValues method to apply changes // from the updated item to the original version. context.ApplyCurrentValues(key.EntitySetName, underlyingFundCashDistribution); } } context.SaveChanges(); } }
/// <summary> /// Make sure that the Capital Distribution you are trying to make is valid /// </summary> private static bool SanityCheck(UnderlyingFundCashDistribution ufcd, out string resp) { StringBuilder sb = new StringBuilder(); resp = string.Empty; bool success = true; List<UnderlyingFundCashDistributionModel> ufs = GetUnderlyingFundCashDistributionList(ufcd.UnderlyingFundID); if (ufs.Count > 0) { // For Fund, UF UnderlyingFundCashDistributionModel ufInFund = ufs.Where(x => x.FundId == ufcd.FundID).FirstOrDefault(); if (ufInFund != null) { // loop through the deals and make sure they are there // A UF may be present in a Fund in many deals, so get all those foreach (CashDistribution cd in ufcd.CashDistributions) { ActivityDealModel mod = ufInFund.Deals.Where(x => x.DealId == cd.DealID).FirstOrDefault(); if (mod == null) { success = false; sb.Append(string.Format("could not find dealID: {0}, fundId: {1}, UFID: {2}", cd.DealID, ufcd.FundID, ufcd.UnderlyingFundID)); } } } else { success = false; sb.Append(string.Format("No UnderlyingFundCashDistributionModel found for FundId: {0}, UFID: {1} ", ufcd.FundID, ufcd.UnderlyingFundID)); } resp = sb.ToString(); if (!string.IsNullOrEmpty(resp)) { resp = "Sanity check failed for UF: " + ufcd.UnderlyingFundID + " " + resp; } } else { success = false; resp = "Sanity check failed for UF: " + ufcd.UnderlyingFundID + " No UnderlyingFundCashDistributionModel found"; Util.WriteSanityCheckFailed(ufcd.UnderlyingFundID.ToString()+","); } return success; }
private static bool? IsManualCashDistributionAlreadyCreated(CookieCollection cookies, UnderlyingFundCashDistribution cashDist, out string resp) { bool? alreadyExists = null; if (FindUnderlyingFundCashDistribution(cookies, cashDist) != null) { alreadyExists = true; } else { alreadyExists = false; } resp = string.Empty; return alreadyExists; /* resp = string.Empty; ReconcileSearchModel model = new ReconcileSearchModel(); // make the search criteria between start date and end date // currently we dont export the Received date, cos the server side code assigns the received date // when we create the cash distribution. so the following code will not work //if(cashDist.ReceivedDate.HasValue){ // model.StartDate = cashDist.ReceivedDate.Value.AddDays(-1); // model.EndDate = cashDist.ReceivedDate.Value.AddDays(1); //} model.FundId = cashDist.FundID; model.UnderlyingFundId = cashDist.UnderlyingFundID; model.ReconcileType = (int)DeepBlue.Models.Deal.Enums.ReconcileType.UnderlyingFundCashDistribution; NameValueCollection formValues = HttpWebRequestUtil.SetUpForm(model, string.Empty, string.Empty); // Send the request string url = HttpWebRequestUtil.GetUrl("Deal/ReconcileList"); byte[] postData = System.Text.Encoding.ASCII.GetBytes(HttpWebRequestUtil.ToFormValue(formValues)); HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, postData, true, Globals.CookieContainer); 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(); if (!string.IsNullOrEmpty(resp)) { JavaScriptSerializer js = new JavaScriptSerializer(); //List<ReconcileReportModel> reconciles = (List<ReconcileReportModel>)js.Deserialize(resp, typeof(List<ReconcileReportModel>)); //alreadyExists = reconciles.Where(x => x.Amount == cashDist.Amount).FirstOrDefault() != null; ReconcileResult reconcileResultModel = (ReconcileResult)js.Deserialize(resp, typeof(ReconcileResult)); List<ReconcileReportModel> reconciles = reconcileResultModel.Results; alreadyExists = reconciles.Where(x => x.Amount == cashDist.Amount).FirstOrDefault() != null; } else { } response.Close(); readStream.Close(); } } } return alreadyExists; */ }
private static UnderlyingFundCashDistribution GetCashDistributionFromBlue(C1_10tblDistToAmberbrookCash blueCashDist, decimal amount, BlueEntities context, CookieCollection cookies, out string resp) { resp = string.Empty; UnderlyingFundCashDistribution deepBlueCD = new UnderlyingFundCashDistribution(); C6_10AmberbrookFundInfo ambFundInfo = context.C6_10AmberbrookFundInfo.Where(x => x.AmberbrookFundNo == blueCashDist.AmberbrookFundNo).FirstOrDefault(); if (ambFundInfo != null) { Fund fund = FundImport.GetFund(ambFundInfo.AmberbrookFundName, cookies); if (fund != null) { deepBlueCD.FundID = fund.FundID; } else { resp = "Unable to find AMB Fund: " + ambFundInfo.AmberbrookFundName; return null; } } else { resp = "Unable to find AMB Fund#: " + blueCashDist.AmberbrookFundNo; return null; } List<DeepBlue.Models.Deal.UnderlyingFundListModel> underlyingFunds = GetUnderlyingFunds(cookies); DeepBlue.Models.Deal.UnderlyingFundListModel uf = underlyingFunds.Where(x => x.FundName == blueCashDist.Fund).FirstOrDefault(); if (uf != null) { deepBlueCD.UnderlyingFundID = uf.UnderlyingFundId; } else { resp = "Unable to find Underlying fund: " + blueCashDist.Fund; Util.WriteMissingUnderlyingFund(blueCashDist.Fund); Util.Log(resp); return null; } deepBlueCD.Amount = amount; // On the UI, this field is labelled Due Date if (blueCashDist.NoticeDate.HasValue) deepBlueCD.NoticeDate = blueCashDist.NoticeDate.Value.Date; // PRDCD is stored in the 1-30tblpostrecorddatetransactions table(Transaction type = cash distribution). so we assuming all the calls here are non-prdcc deepBlueCD.IsPostRecordDateTransaction = false; // We dont need to provider the value for Received date, as it is assigned on the server side (to DateTime.Now) // deepBlueCD.ReceivedDate = DateTime.Now; if (blueCashDist.ReceivedDate.HasValue) { deepBlueCD.ReceivedDate = blueCashDist.ReceivedDate.Value.Date; } else { deepBlueCD.ReceivedDate = (DateTime.Now).Date; } // This should be handled in the reconciliation #region reconconciliation if (blueCashDist.Received.HasValue) { deepBlueCD.IsReconciled = blueCashDist.Received.Value; } deepBlueCD.PaidON = blueCashDist.ReceivedDate; // Paid Date is not required // TODO: Find out which of Paid Date/Paid On is used for reconciliation // deepBlueCD.PaidDate; // deepBlueCD.ReconciliationMethod; #endregion // WARNING: What should the Cash distribution type should be (Cash Distribution/Deemed Distribution/Netted Distribution) // Cash Distribution deepBlueCD.CashDistributionTypeID = 1; return deepBlueCD; }
private static object FindUnderlyingFundCashDistribution(CookieCollection cookies, UnderlyingFundCashDistribution cashDist) { string resp = string.Empty; object ufCD = null; // Send the request string url = HttpWebRequestUtil.GetUrl("Deal/FindUnderlyingFundCashDistribution"); url += "?fundID=" + cashDist.FundID + "&amount=" + cashDist.Amount + "¬iceDate=" + cashDist.NoticeDate + "&underlyingFundID=" + cashDist.UnderlyingFundID; HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, null, false, cookies, false, HttpWebRequestUtil.JsonContentType); 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(); if (!string.IsNullOrEmpty(resp)) { JavaScriptSerializer js = new JavaScriptSerializer(); ufCD = (object)js.Deserialize(resp, typeof(object)); } else { } response.Close(); readStream.Close(); } } } return ufCD; }
private static void CreateManualCashDistribution(CookieCollection cookies, UnderlyingFundCashDistribution cashDist, out string resp) { resp = string.Empty; UnderlyingFundCashDistributionModel model = new UnderlyingFundCashDistributionModel(); model.FundId = cashDist.FundID; model.UnderlyingFundId = cashDist.UnderlyingFundID; model.CashDistributionTypeId = cashDist.CashDistributionTypeID; model.Amount = cashDist.Amount; if (cashDist.NoticeDate.HasValue) model.NoticeDate = cashDist.NoticeDate.Value.Date; if (cashDist.ReceivedDate.HasValue) model.ReceivedDate = cashDist.ReceivedDate.Value.Date; NameValueCollection formValues = HttpWebRequestUtil.SetUpForm(model, "0_", string.Empty); // This should be manual cash distribution formValues.Add("isManualCashDistribution", "true"); formValues.Add("TotalRows", "1"); if (cashDist.CashDistributions.Count > 0) { foreach (CashDistribution cd in cashDist.CashDistributions) { // underlyingFundCashDistribution.FundID.ToString() + "_" + dealUnderlyingFund.DealID.ToString() + "_" + "CallAmount" formValues.Add(string.Format("{0}_{1}_CallAmount", model.FundId, cd.DealID), cd.Amount.ToString()); } } // Send the request string url = HttpWebRequestUtil.GetUrl("Deal/CreateUnderlyingFundCashDistribution"); 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(); response.Close(); readStream.Close(); } } } }
private IEnumerable<ErrorInfo> Validate(UnderlyingFundCashDistribution underlyingFundCashDistribution) { return ValidationHelper.Validate(underlyingFundCashDistribution); }