Пример #1
0
        static void Main()
        {
            Console.WriteLine("Select currency: £ = 1, $ = 2");

            ICurrency currency = CurrencySelector.CurrencySelect(Console.ReadLine());

            if (currency != null)
            {
                Console.WriteLine("What is the till's float?");

                if (int.TryParse(Console.ReadLine(), out int cashFloat))
                {
                    currency = CurrencyCalc.SetFloat(cashFloat, currency);
                }

                foreach (int denomination in currency.Denominations)
                {
                    Console.WriteLine(currency.SpecifiedCurrency + denomination);

                    if (int.TryParse(Console.ReadLine(), out int numberOfdenominations))
                    {
                        currency = CurrencyCalc.CalculateCurrency(numberOfdenominations, denomination, currency);
                    }
                }

                currency = CurrencyCalc.CalculateBankingTotal(currency);

                Console.WriteLine("Total cash in the till: " + currency.SpecifiedCurrency + currency.CashTotal);
                Console.WriteLine("Total Amount of cash to be banked: " + currency.SpecifiedCurrency + currency.BankingTotal);
            }
            else
            {
                Console.WriteLine("No Valid currency selected");
            }
        }
Пример #2
0
        public async Task <ResponseHelper <TransHelper> > GetTransactionsBySku(string sku)
        {
            var response = new ResponseHelper <TransHelper>();

            try
            {
                CurrencyCalc            cC             = new CurrencyCalc();
                double                  totalAmount    = 0;
                List <TransactionModel> listTransFinal = new List <TransactionModel>();
                List <string>           listCoins      = new List <string>();
                //API
                Get();

                //FILE
                var listRate = await _repositoryRateFile.Read();

                var listTransaction = await _repositoryTransFile.Read();

                var listTransBySku = listTransaction.Where(x => x.Sku == sku);
                var listFrom       = listRate.Select(x => x.From); //FROM
                var listTo         = listRate.Select(y => y.To);   //TO
                var listFull       = listFrom.Union(listTo).Distinct();

                foreach (var item in listFull)
                {
                    listCoins.Add(item);
                }
                cC.AddCoin(listCoins);
                foreach (var item in listRate)
                {
                    cC.AddWay(item.From, item.To, Convert.ToSingle(item.Rate));
                }

                foreach (var item in listTransBySku)
                {
                    TransactionModel tran = new TransactionModel
                    {
                        Currency = "EUR",
                        Sku      = item.Sku
                    };
                    var num      = Convert.ToSingle(item.Amount);
                    var dijkstra = cC.Dijkstra("EUR", item.Currency, listFull.Count());
                    tran.Amount  = Math.Round((num * dijkstra), 2);
                    totalAmount += (num * dijkstra);
                    listTransFinal.Add(tran);
                }
                TransHelper finalResponse = new TransHelper
                {
                    TotalAmount = Math.Round(totalAmount, 2),
                    Current     = "€",
                    ListTrans   = listTransFinal
                };
                response.ResponseH = new ResultHelper
                {
                    Result  = ResultMsg.OK,
                    ErrText = ""
                };
                response.DataH = finalResponse;
                return(await Task.FromResult(response));
            }
            catch (Exception ex)
            {
                response.ResponseH.Result  = ResultMsg.Exception;
                response.ResponseH.ErrText = ex.Message;
                _logger.LogWarning(DateTime.Now.ToString() + "[" + nameof(TransactionsService) + "]-[" + nameof(GetTransactionsBySku) + "]: " + ex.Message, ex);
                return(await Task.FromResult(response));
            }
        }