public async Task <IActionResult> UpdateData(int?periodId, int?saleId = null) { List <MLFSSale> sales = new List <MLFSSale>(); if (saleId == null) { if (periodId == null) { return(NotFound()); } MLFSReportingPeriod period = await _periodData.GetPeriodById((int)periodId); if (period == null) { return(NotFound()); } sales = await _salesData.GetSales(period); } else { MLFSSale soleSale = await _salesData.GetSaleById((int)saleId); sales.Add(soleSale); } for (int i = 0; i < sales.Count; i++) { MLFSSale sale = sales[i]; //only interested in clients which haven't been updated already or where we are forcing a particular line //if (saleId != null || (sale.EstimatedOtherIncome == 0)) //{ Console.WriteLine("Client: " + sale.ClientId + ":" + sale.Client + ":" + i.ToString()); MLFSClient client = await _clientData.GetClient(sale.ClientId); List <MLFSIncome> income = await _incomeData.GetIncome(client); sale.AddClientData(client, income); _salesData.Update(sale); //} } return(Ok()); }
public void AddClientDataTest() { //arrange MLFSSale sale = new MLFSSale() { Id = 1, ClientId = "IOB123", ClientName = "John", NetAmount = 100, VAT = 20, PlanReference = "IOP123" }; MLFSClient client = new MLFSClient() { Name = "John", PrimaryID = "IOB123", CreatedOn = DateTime.Now.AddYears(-1) }; client.Plans.Add(new MLFSPlan() { PrimaryID = "IOP123", Provider = "XYZ Limited", ContributionsToDate = 10000, CurrentValuation = 11000, IsPreExistingClient = true }); client.Fees.Add(new MLFSFee() { PrimaryID = "IOF123", FeePercentage = (decimal)0.1, IsRecurring = true, Plan = client.Plans.FirstOrDefault() }); client.Plans.Add(new MLFSPlan() { PrimaryID = "IOP987", Provider = "XYZ Limited", ContributionsToDate = 200000, CurrentValuation = 220000 }); client.Fees.Add(new MLFSFee() { PrimaryID = "IOF987", FeePercentage = (decimal)0.1, IsRecurring = true, Plan = new MLFSPlan() { PrimaryID = "IOP987", Provider = "XYZ Limited", ContributionsToDate = 200000, CurrentValuation = 220000 } }); List <MLFSIncome> income = new List <MLFSIncome>(); //to do test income handling //act sale.AddClientData(client, income); //assert Assert.AreEqual("XYZ Limited", sale.ProviderName, "Provider name not updated"); Assert.AreEqual(false, sale.IsNew, "IsNew not set correctly"); Assert.AreEqual(11000, sale.Investment, "Investment incorrect"); Assert.AreEqual((decimal)0.1, sale.OnGoingPercentage, "Percentage incorrect"); Assert.AreEqual((decimal)22000, sale.EstimatedOtherIncome, "Other income not calculated correctly"); }