public MainWindow()
 {
     wallet    = new CurrencyRepo();
     vmWallet  = new ViewModelCreateCurrencyRepo(wallet);
     vmWallet2 = new ViewModelCurrencyRepo(wallet);
     InitializeComponent();
     UserControlCurrencyRepo       ucCR  = new UserControlCurrencyRepo(vmWallet2);
     UserControlCreateCurrencyRepo ucCCR = new UserControlCreateCurrencyRepo(vmWallet);
 }
示例#2
0
 public USCurrencyRepoTests()
 {
     repo       = new CurrencyRepo();
     penny      = new Penny();
     nickel     = new Nickel();
     dime       = new Dime();
     quarter    = new Quarter();
     dollarCoin = new DollarCoin();
 }
        public string Path = "currencyRepo";//default path appears in bin debug

        public ViewModelRepo(CurrencyRepo repo)
        {
            this.repo = repo;

            this.Add  = new ViewModelRepoCommand(ExecuteCommandAdd, CanExecuteCommandAdd);
            this.Save = new ViewModelRepoCommand(ExecuteCommandSave, CanExecuteCommandSave);
            this.Load = new ViewModelRepoCommand(ExecuteCommandLoad, CanExecuteCommandLoad);
            this.New  = new ViewModelRepoCommand(ExecuteCommandNew, CanExecuteCommandNew);
        }
示例#4
0
 public MainWindow()
 {
     InitializeComponent();
     repo = new CurrencyRepo()
     {
         Coins = new List <ICoin> {
             new Penny()
         }
     };
 }
        private void ButtonClear_Click(object sender, RoutedEventArgs e)
        {
            repo = new CurrencyRepo();

            ViewModelRepo    = new ViewModelCreateCurrencyRepo(repo);
            this.DataContext = ViewModelRepo;
            string value = Convert.ToString(repo.TotalValue());

            labelRepoValueDisplay.Content = "$" + value;
        }
示例#6
0
        private void ExecuteCommandGetChange(object parameter)
        {
            //Get the repo of the change created for amount given
            CurrencyRepo tempRepo = (CurrencyRepo)CurrencyRepo.CreateChange(Amount);

            //set the list of coins to the list of coins in the temp repo
            Coins = tempRepo.Coins;
            //notify the change in the list
            RaisePropertyChanged("Coins");
        }
        public ActionResult SaveRepo([FromServices] CurrencyRepo repo)
        {
            IFormatter formatter = new BinaryFormatter();
            string     docPath   = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            Stream     stream    = new FileStream(Path.Combine(docPath, "Repo.txt"), FileMode.Create, FileAccess.Write);

            formatter.Serialize(stream, repo);
            stream.Close();
            return(RedirectToAction(nameof(Index)));
        }
        public void TestViewModelConstructor()
        {
            CurrencyRepo          repo = new CurrencyRepo();
            ViewModelMakeChangeUI vm   = new ViewModelMakeChangeUI(repo);

            ICommand saveCommand       = new ViewModelMakeChangeUICommand(vm.ExecuteCommandSave, vm.CanExecuteCommandSave);
            ICommand makeChangeCommand = new ViewModelMakeChangeUICommand(vm.ExecuteCommandMakeChange, vm.CanExecuteCommandMakeChange);


            Assert.AreEqual(repo, vm.makeChangeRepo);                              //they should be set to each other in the constructor
            Assert.AreEqual(makeChangeCommand.GetType(), vm.MakeChange.GetType()); //The assert without the get type fails and I can't for the life of me figure out why.
            Assert.AreEqual(saveCommand.GetType(), vm.Save.GetType());             //I tried casting them, but they still fail, so I at least can compare the type and make sure it's correct.
        }
 public ActionResult Delete(string id, IFormCollection collection, [FromServices] CurrencyRepo repo)
 {
     try
     {
         // TODO: Add delete logic here
         repo.RemoveCoin(repo.Coins.Where(c => c.Name == id).FirstOrDefault());
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
 private void ButtonSubmit_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         repo             = (CurrencyRepo)CurrencyRepo.CreateChange(Convert.ToDouble(txtAmount.Text));
         ViewModelRepo    = new ViewModelCurrencyRepo(repo);
         this.DataContext = ViewModelRepo;
     }
     catch
     {
         txtAmount.Text = "Enter Amound Here! (Only Numberic Characters Allowed!)";
     }
 }
        public void AmountTest()
        {
            //arrange
            CurrencyRepo          repo = new CurrencyRepo();
            ViewModelMakeChangeUI vm   = new ViewModelMakeChangeUI(repo);

            double defaultAmount;

            //act
            defaultAmount = vm.Amount;//default amount should be 0

            //assert
            Assert.AreEqual(0, defaultAmount);
        }
        public ActionResult Index(string sAmount, [FromServices] CurrencyRepo repo)
        {
            double dAmount;

            try
            {
                dAmount = Convert.ToDouble(sAmount);
            }
            catch
            {
                dAmount = 0;
            }
            repo.Coins = CurrencyRepo.CreateChange(dAmount).Coins;
            return(RedirectToAction(nameof(Index)));
        }
示例#13
0
 //constructor
 public CurrencyExchangeWPF(CurrencyRepo change)
 {
     //set the repo object to passed in repo
     repo = change;
     //intialize the commands
     GetChange = new WPFExchangeCommand(ExecuteCommandGetChange, CanExecuteCommandGetChange);
     Save      = new WPFExchangeCommand(ExecuteCommandSave, CanExecuteCommandSave);
     //if the repo has already been edited then update the view
     if (repo.Coins.Count > 0)
     {
         Amount = repo.TotalValue();
         RaisePropertyChanged("Amount");
         RaisePropertyChanged("Coins");
     }
 }
        public ActionResult LoadRepo([FromServices] CurrencyRepo repo)
        {
            IFormatter   formatter = new BinaryFormatter();
            string       docPath   = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            Stream       stream    = new FileStream(Path.Combine(docPath, "Repo.txt"), FileMode.Open, FileAccess.Read);
            CurrencyRepo temp      = (CurrencyRepo)formatter.Deserialize(stream);

            stream.Close();
            //makes sure that the coins are added to the global repo so that the other window/view model can
            //see the coins add in this window
            repo.Coins = temp.Coins;
            //reduce the number of coins when the repo is loaded
            repo.ReduceCoins();
            return(RedirectToAction(nameof(Index)));
        }
 private void ButtonLoad_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         repo             = repo.LoadRepo();
         ViewModelRepo    = new ViewModelCreateCurrencyRepo(repo.LoadRepo());
         this.DataContext = ViewModelRepo;
         string value = Convert.ToString(repo.TotalValue());
         labelRepoValueDisplay.Content = "$" + value;
     }
     catch (Exception w)
     {
         // Failed to load
     }
 }
        public void TestCoinsInRepo()
        {
            CurrencyRepo  repo = new CurrencyRepo();
            ViewModelRepo vm   = new ViewModelRepo(repo);

            string defaultCoinsMessage = vm.CoinsInRepo;

            ICoin penny = new Penny();

            vm.repo.AddCoin(penny);

            string CoinMessageAfterPennyAdded = vm.CoinsInRepo;

            Assert.AreEqual("Repo has 0 coins. COINS:", defaultCoinsMessage);
            Assert.AreEqual("Repo has 1 coins. COINS:\n" + penny.GetType(), CoinMessageAfterPennyAdded);
        }
示例#17
0
        public void MakeChangeTests()
        {
            //Arrange
            CurrencyRepo changeOneQuatersOnHalfDollar, changeTwoDollars, changeOneDollarOneHalfDoller,
                         changeOneDimeOnePenny, changeOneNickelOnePenny, changeFourPennies;

            repo = new CurrencyRepo();

            //Act
            changeTwoDollars             = (CurrencyRepo)repo.CreateChange(2.0);
            changeOneDollarOneHalfDoller = (CurrencyRepo)repo.CreateChange(1.5);
            changeOneQuatersOnHalfDollar = (CurrencyRepo)repo.CreateChange(.75);

            changeOneDimeOnePenny   = (CurrencyRepo)repo.CreateChange(.11);
            changeOneNickelOnePenny = (CurrencyRepo)repo.CreateChange(.06);
            changeFourPennies       = (CurrencyRepo)repo.CreateChange(.04);


            //Assert
            Assert.AreEqual(changeTwoDollars.Coins.Count, 2);
            Assert.AreEqual(changeTwoDollars.Coins[0].GetType(), new DollarCoin().GetType());
            Assert.AreEqual(changeTwoDollars.Coins[1].GetType(), new DollarCoin().GetType());

            Assert.AreEqual(changeOneDollarOneHalfDoller.Coins.Count, 2);
            Assert.AreEqual(changeOneDollarOneHalfDoller.Coins[0].GetType(), new DollarCoin().GetType());
            Assert.AreEqual(changeOneDollarOneHalfDoller.Coins[1].GetType(), new HalfDollarCoin().GetType());


            Assert.AreEqual(changeOneQuatersOnHalfDollar.Coins.Count, 2);
            Assert.AreEqual(changeOneQuatersOnHalfDollar.Coins[0].GetType(), new HalfDollarCoin().GetType());
            Assert.AreEqual(changeOneQuatersOnHalfDollar.Coins[1].GetType(), new Quarter().GetType());

            Assert.AreEqual(changeOneDimeOnePenny.Coins.Count, 2);
            Assert.AreEqual(changeOneDimeOnePenny.Coins[0].GetType(), new Dime().GetType());
            Assert.AreEqual(changeOneDimeOnePenny.Coins[1].GetType(), new Penny().GetType());

            Assert.AreEqual(changeOneNickelOnePenny.Coins.Count, 2);
            Assert.AreEqual(changeOneNickelOnePenny.Coins[0].GetType(), new Nickel().GetType());
            Assert.AreEqual(changeOneNickelOnePenny.Coins[1].GetType(), new Penny().GetType());


            Assert.AreEqual(changeFourPennies.Coins.Count, 4);
            Assert.AreEqual(changeFourPennies.Coins[0].GetType(), new Penny().GetType());
            Assert.AreEqual(changeFourPennies.Coins[1].GetType(), new Penny().GetType());
            Assert.AreEqual(changeFourPennies.Coins[2].GetType(), new Penny().GetType());
            Assert.AreEqual(changeFourPennies.Coins[3].GetType(), new Penny().GetType());
        }
示例#18
0
        //deserialize and load a repo from a file
        private void ExecuteCommandLoad(object parameter)
        {
            IFormatter   formatter = new BinaryFormatter();
            Stream       stream    = new FileStream(@"...\Repo.txt", FileMode.Open, FileAccess.Read);
            CurrencyRepo temp      = (CurrencyRepo)formatter.Deserialize(stream);

            stream.Close();
            //makes sure that the coins are added to the global repo so that the other window/view model can
            //see the coins add in this window
            foreach (ICoin c in temp.Coins)
            {
                repo.AddCoin(c);
            }
            //reduce the number of coins when the repo is loaded
            repo.ReduceCoins();
            RaisePropertyChanged("TotalAmount");
        }
        public void TestRepoConstructor()
        {
            //arrange
            CurrencyRepo  repo = new CurrencyRepo();
            ViewModelRepo vm   = new ViewModelRepo(repo);

            //act
            ICommand addCommand  = new ViewModelRepoCommand(vm.ExecuteCommandAdd, vm.CanExecuteCommandAdd);
            ICommand saveCommand = new ViewModelRepoCommand(vm.ExecuteCommandSave, vm.CanExecuteCommandSave);
            ICommand loadCommand = new ViewModelRepoCommand(vm.ExecuteCommandLoad, vm.CanExecuteCommandLoad);
            ICommand newCommand  = new ViewModelRepoCommand(vm.ExecuteCommandNew, vm.CanExecuteCommandNew);

            Assert.AreEqual(repo, vm.repo);                          //they should be set to each other in the constructor
            Assert.AreEqual(addCommand.GetType(), vm.Add.GetType()); //these don't assert are equal and they return the same value of the same type, so instead I compare type
            Assert.AreEqual(saveCommand.GetType(), vm.Save.GetType());
            Assert.AreEqual(loadCommand.GetType(), vm.Load.GetType());
            Assert.AreEqual(newCommand.GetType(), vm.New.GetType());
            //assert
        }
        public void CoinsInRepoTest()
        {
            //arrange
            CurrencyRepo          repo = new CurrencyRepo();
            ViewModelMakeChangeUI vm   = new ViewModelMakeChangeUI(repo);

            string defaultCoinsInRepoMessage;
            string coinsInRepoAfterMakingChange;
            string aboutMessageAfterMakingChange;

            //act
            defaultCoinsInRepoMessage = vm.CoinsInRepo;                           //should return the empty message

            vm.makeChangeRepo = (CurrencyRepo)vm.makeChangeRepo.MakeChange(1.36); //need to figure out how to pass that in!

            coinsInRepoAfterMakingChange  = vm.CoinsInRepo;                       //should equal the about message
            aboutMessageAfterMakingChange = vm.makeChangeRepo.About();

            //assert
            Assert.AreEqual("Repo has 0 coins. COINS:", defaultCoinsInRepoMessage);
            Assert.AreEqual(aboutMessageAfterMakingChange, coinsInRepoAfterMakingChange);
        }
        public ActionResult Add(string id, IFormCollection collection, [FromServices] CurrencyRepo repo)
        {
            try
            {
                string selectedValue = Request.Form["selectedCoinToAdd"];
                switch (selectedValue)
                {
                case "Penny":
                    repo.AddCoin(new Penny());
                    break;

                case "Nickel":
                    repo.AddCoin(new Nickel());
                    break;

                case "Dime":
                    repo.AddCoin(new Dime());
                    break;

                case "Quarter":
                    repo.AddCoin(new Quarter());
                    break;

                case "Half Dollar":
                    repo.AddCoin(new HalfDollar());
                    break;

                case "Dollar Coin":
                    repo.AddCoin(new DollarCoin());
                    break;
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
示例#22
0
 //Create a new repo
 private void ExecuteCommandNewRepo(object parameter)
 {
     repo = new CurrencyRepo();
     RaisePropertyChanged("TotalAmount");
 }
 public ViewModelCreateCurrencyRepo(CurrencyRepo wallet)
 {
     this.wallet = wallet;
 }
 // GET: Repo/Details/5
 public ActionResult Details(int id, [FromServices] CurrencyRepo repo)
 {
     return(View(repo.Coins[id]));
 }
 // GET: Repo/Delete/5
 public ActionResult Delete(string id, [FromServices] CurrencyRepo repo)
 {
     return(View((USCoin)repo.Coins.Find(c => c.Name == id)));
 }
 public ActionResult NewRepo([FromServices] CurrencyRepo repo)
 {
     repo.Coins = new List <ICoin>();
     return(RedirectToAction(nameof(Index)));
 }
 public ViewModelMakeChangeUI(CurrencyRepo repo)
 {
     this.makeChangeRepo = repo;
     this.MakeChange     = new ViewModelMakeChangeUICommand(ExecuteCommandMakeChange, CanExecuteCommandMakeChange);
     this.Save           = new ViewModelMakeChangeUICommand(ExecuteCommandSave, CanExecuteCommandSave);
 }
示例#28
0
        public List <PaymentGateWay> GetPayGateWay(string BN)
        {
            try
            {
                // get Some data from DB like Currency and pos
                PayLinkDB             DB = new PayLinkDB();
                SalesRulesManager     ServiceChargeManager = new SalesRulesManager();
                string                pos;
                List <string>         gates           = new List <string>();
                List <PaymentGateWay> paymentGateWays = new List <PaymentGateWay>();
                //    SalesRuleGateway salesRule = new SalesRuleGateway();
                SalesRules salesRule = new SalesRules();
                var        criterais = DB.GetDataForGatewayDA(BN);
                //call selected Gateway
                //basecurr
                var BaseCur = ConfigurationSettings.AppSettings["BaseCur"];
                // exchangeRate
                CurrencyRepo currencyManager = new CurrencyRepo();

                double ExcahngeRate        = currencyManager.GetEveryDayCurrenciesConversion(BaseCur, criterais.Curr, criterais.searchData.sID, DateTime.Now).Result.Customer_Sell_Rate;
                double ExcahngeRateForBase = currencyManager.GetEveryDayCurrenciesConversion(criterais.Curr, BaseCur, criterais.searchData.sID, DateTime.Now).Result.Customer_Sell_Rate;

                if (criterais.Curr != null & criterais.pos != null)
                {
                    gates = GateWays.GetPaymentGatewaysAsync(criterais.Curr).Result;
                    if (gates.Count == 0)
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
                // call sales Rules
                salesRule = GateWays.GetSaleRuleForGateAsync(criterais.pos).Result;

                if (salesRule.MarkupList.Count == 0)
                {
                    foreach (var item in gates)
                    {
                        PaymentGateWay gateWay = new PaymentGateWay();
                        gateWay.paymentMethod = item;
                        gateWay.currency      = criterais.Curr;
                        gateWay.amount        = 0;

                        paymentGateWays.Add(gateWay);
                    }
                    return(paymentGateWays);
                }
                ServiceChargeManager.FillPaySaleRules(salesRule);

                ServiceChargeManager.PrepareSearchCriteriaDic(criterais.searchData);

                foreach (var item in gates)
                {
                    ServiceChargeManager.SetResultCriteriaForpay(criterais.HotelName, criterais.HotelStars, criterais.cost
                                                                 * ExcahngeRateForBase, criterais.Pid, item);
                    //AppliedSalesRule AppliedMarkup = ServiceChargeManager.ApplySalesRules("Markup");
                    AppliedSalesRule AppliedMarkup = ServiceChargeManager.ApplyMarkupForPayGateway();
                    PaymentGateWay   gateWay       = new PaymentGateWay();
                    gateWay.paymentMethod = item;
                    gateWay.currency      = criterais.Curr;
                    if (gateWay.currency.ToLower() == "kwd")
                    {
                        gateWay.amount = Math.Round(AppliedMarkup.Value * ExcahngeRate, 3);
                    }

                    gateWay.amount = Math.Round(AppliedMarkup.Value * ExcahngeRate, 2);


                    paymentGateWays.Add(gateWay);
                }
                return(paymentGateWays);

                ///    AppliedSalesRule AppliedDiscount = ServiceChargeManager.ApplySalesRules("Discount");
                // map

                /*  foreach (var item in salesRule.MarkupList)
                 * {
                 *    foreach (var gate in item.CriteriaList)
                 *    {
                 *        foreach (var g in gates)
                 *        {
                 *
                 *
                 *            if (g.ToLower() == gate.value.ToLower())
                 *            {
                 *                PaymentGateWay gateWay = new PaymentGateWay();
                 *                gateWay.paymentMethod = g;
                 *                gateWay.currency = BaseCur;
                 *              gateWay.amount = item.commAmount;
                 *                gateWay.exchangeRate = ExcahngeRate;
                 *                paymentGateWays.Add(gateWay);
                 *            }
                 *        }
                 *    }
                 * }*/
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
 public void ExecuteCommandMakeChange(object parameter)
 {
     makeChangeRepo = (CurrencyRepo)makeChangeRepo.MakeChange(Amount);//need to figure out how to pass that in!
     RaisePropertyChanged("CoinsInRepo");
 }
示例#30
0
 public WindowMakeChange(CurrencyRepo repo)
 {
     this.repo = repo;
     InitializeComponent();
 }