public void Process(GetLookupSourceItemsArgs args) { if (!args.Source.Contains(scapePrefix)) { return; } Item contextItem; // Only goes ahead if this is a Parameters Template if (args.Item.Template.BaseTemplates.Where(bt => bt.ID == BaseParameterTemplate).Any()) { // This whole block is to get Context Item string url = WebUtil.GetQueryString(); if (string.IsNullOrWhiteSpace(url)) { args.Source = String.Empty; return; } FieldEditorParameters parameters = null; try { parameters = FieldEditorOptions.Parse(new UrlString(url)).Parameters; } catch (Exception) { } if (parameters == null) { args.Source = String.Empty; return; } var currentItemId = parameters["contentitem"]; if (string.IsNullOrEmpty(currentItemId)) { args.Source = String.Empty; return; } ItemUri contentItemUri = new ItemUri(currentItemId); contextItem = Database.GetItem(contentItemUri); } else { contextItem = args.Item; } // Now to the custom (site-specific) parameters var sourceName = args.Source.Replace(scapePrefix, "").Trim(); args.Source = provider.GetSource(contextItem, sourceName); }
public Quote CreateQuote(string marketFilePath, string loanAmountString) { long loanAmount; if (!long.TryParse(loanAmountString, out loanAmount)) { throw new LoanAmountException("Please input an integer loan amount."); } var offers = _sourceProvider.GetSource(marketFilePath); if (loanAmount < 1000 || loanAmount > 15000 || loanAmount % 100 != 0) { throw new LoanAmountException( "Load request can only be of any £100 increment between £1000 and £15000 inclusive."); } if (offers.Sum(o => o.Available) < loanAmount) { throw new LoanAmountException("It is not possible to provide a quote at that time."); } var usableTotalAmount = 0L; var offersToUse = offers.TakeWhile(o => { var available = o.Available; usableTotalAmount += available; return(usableTotalAmount < loanAmount); }).ToList(); offersToUse.Add(offers[offersToUse.Count]); var sumAvailable = offersToUse.Sum(o => o.Available); var compoundRate = (from offer in offersToUse let weight = (double)offer.Available / sumAvailable select offer.Rate * weight).Sum(); compoundRate = Math.Round(compoundRate, 3); var finalRate = Math.Pow(compoundRate + 1, 3); var totalPayment = finalRate * loanAmount; var monthlyPayment = totalPayment / 36; return(new Quote { Rate = compoundRate, MonthlyRepayment = Math.Round(monthlyPayment, 2), RequestAmount = loanAmount, TotalRepayment = Math.Round(totalPayment, 2) }); }
/// <summary> /// Parses the strings taken from the <paramref name="provider"/> to URI objects. /// </summary> /// <param name="provider">Source provider.</param> /// <returns>Enumeration of URIs.</returns> public IEnumerable <Uri> ParseSource(ISourceProvider provider) { var resultList = new List <Uri>(); foreach (var item in provider.GetSource()) { Uri uri = Parse(item); if (uri == null) { continue; } resultList.Add(uri); } return(resultList); }
public void GiveSuchAQuoteWhenLoanAmountIs2100() { var filePath = string.Empty; var expectedQuote = new Quote { RequestAmount = 2100, Rate = 0.073, MonthlyRepayment = 72.06, TotalRepayment = 2594.29 }; _sourceProvider.GetSource(filePath).ReturnsForAnyArgs(_offers); _quoteProvider.CreateQuote(filePath, "2100").ShouldBeEqualTo(expectedQuote); _sourceProvider.Received(1).GetSource(filePath); }
public void ThrowSourceFileIoExceptionIfFilePathIsInvalid() { _target.GetSource(InvalidFilePath); }