Esempio n. 1
0
        private void CalculateMoneyChange(decimal number, decimal quotient, int position, Guid moneyChangeId)
        {
            if (quotient >= 1)
            {
                MoneyChange moneySearch = new MoneyChange();
                moneySearch.MoneyChangeId = moneyChangeId;
                moneySearch.CurrencyId    = currencyList[position].CurrencyId;
                moneySearch.CurrencyValue = currencyList[position].CurrencyValue;
                moneySearch.Quantity      = Convert.ToInt16(quotient);
                moneySearch.Number        = this.Number;

                moneySearch.AddMoneyChange();


                moneyChangeList.Add(moneySearch);

                number -= (quotient * currencyList[position].CurrencyValue);
            }
            decimal remainder = number % currencyList[position].CurrencyValue;

            if (remainder > 0)
            {
                GetIntegers(number, position + 1, moneyChangeId);
            }
        }
        /// <summary>
        /// Gets all the money changes done in the past
        /// </summary>
        /// <returns>List of all the money searches</returns>
        public List <MoneyChange> GetAllMoneyChanges()
        {
            this.Error = "";
            List <MoneyChange> result = new List <MoneyChange>();

            try
            {
                MoneyChange moneySearch = new MoneyChange();
                result = moneySearch.GetAllMoneyChanges();
            }
            catch (Exception ex)
            {
                this.Error = ex.Message;
            }

            return(result);
        }
        /// <summary>
        /// Gets the money change based on a number provided and the currencies available in the db
        /// </summary>
        /// <param name="number">Number to return change in English currency</param>
        /// <returns>List of currencies and quantities used to return change stored in MoneyChange objects</returns>
        public List <MoneyChange> GetMoneyChange(decimal number)
        {
            this.Error = "";
            List <MoneyChange> result = new List <MoneyChange>();

            try
            {
                //get the list of currencies from the database
                CurrencyController currencyController = new CurrencyController();
                List <Currency>    currencyList       = currencyController.GetAllCurrenciesFromList();
                MoneyChange        moneySearch        = new MoneyChange();
                result = moneySearch.GetMoneyChange(number, currencyList);
            }
            catch (Exception ex)
            {
                this.Error = ex.Message;
            }
            return(result);
        }
Esempio n. 4
0
        public List <MoneyChange> GetAllMoneyChanges()
        {
            List <MoneyChange> listAllMoneyChanges = new List <MoneyChange>();

            model = new MoneyModel();
            foreach (MoneyEntities.MoneyChange dbMoneyChange in model.MoneyChange.ToList())
            {
                MoneyChange moneyChange = new MoneyChange();
                moneyChange.Id            = dbMoneyChange.Id;
                moneyChange.MoneyChangeId = dbMoneyChange.MoneyChangeId ?? new Guid();
                moneyChange.CurrencyId    = Convert.ToInt16(dbMoneyChange.CurrencyId);
                moneyChange.CurrencyValue = Convert.ToDecimal(dbMoneyChange.CurrencyValue);
                moneyChange.Quantity      = Convert.ToInt16(dbMoneyChange.Quantity);
                moneyChange.RequestedTime = Convert.ToDateTime(dbMoneyChange.RequestedTime);
                moneyChange.Number        = Convert.ToDecimal(dbMoneyChange.Number);
                listAllMoneyChanges.Add(moneyChange);
            }

            return(listAllMoneyChanges);
        }