/// <summary> /// Returns a combination that define how the amount could be splitted in the minimun total quantity of all types. /// </summary> /// <param name="amount">Te amount to evalute</param> /// <returns> /// The calculated combination /// </returns> public Combination GetSmallestCombination(decimal amount) { var record = new Record { Amount = amount }; var result = new Combination(); if (amount < 0 || amount > 1000) { return(result); } foreach (var money in Configuration.AllMoneyValues) { if (money.Amount > amount) { continue; } result.Add( decimal.ToInt32(amount / money.Amount), money); amount = amount % money.Amount; } try { record.Combination = result.ToString(); _dataService.Store(record); } catch (Exception e) { // ignore it // error should be logged or managed in a differnt way } return(result); }