Exemplo n.º 1
0
        public void CashBack(Label a, Label b, int c)
        {
            int           x             = Convert.ToInt32(a.Content);
            int           y             = Convert.ToInt32(b.Content);
            var           moneyMachine  = db.MachineWallets;
            MachineWallet walletMachine = moneyMachine.Find(c);
            int           k             = walletMachine.CoinValue;

            while (sum >= k)
            {
                if (x != 0)
                {
                    x   -= 1;
                    y   += 1;
                    sum -= k;
                }
                else
                {
                    break;
                }
            }
            a.Content   = $"{x}";
            b.Content   = $"{y}";
            Sum.Content = $"{sum}";
            var         moneyBuyer  = db.BuyerWallets;
            BuyerWallet walletBuyer = moneyBuyer.Find(c);

            walletBuyer.Quantity   = y;
            walletMachine.Quantity = x;
            db.SaveChanges();
        }
Exemplo n.º 2
0
 public void Deposit(Label a, Label b, int IdWallet)
 {
     if (Convert.ToInt32(a.Content) == 0)
     {
         MessageBox.Show("Купюры этого номинала у Вас закончились.");
     }
     else
     {                                                                                          //Метод переноса купюр
         var           moneyMachine  = db.MachineWallets;
         MachineWallet walletMachine = moneyMachine.Find(IdWallet);
         sum        += walletMachine.CoinValue;
         Sum.Content = $"{sum}";
         WalletChange(a, b, IdWallet);
     }
 }
Exemplo n.º 3
0
        public MainWindow()
        {
            InitializeComponent();
            db = new VendingMachineContext();



            Sum.Content = $"{sum}";

            // Загрузка из БД в форму.

            var           moneyMachine  = db.MachineWallets;
            MachineWallet walletMachine = moneyMachine.Find(1);

            Machine1.Content  = $"{walletMachine.Quantity}";
            walletMachine     = moneyMachine.Find(2);
            Machine2.Content  = $"{walletMachine.Quantity}";                                           // Кошелёк автомата
            walletMachine     = moneyMachine.Find(3);
            Machine5.Content  = $"{walletMachine.Quantity}";
            walletMachine     = moneyMachine.Find(4);
            Machine10.Content = $"{walletMachine.Quantity}";

            var         moneyBuyer  = db.BuyerWallets;
            BuyerWallet walletBuyer = moneyBuyer.Find(1);

            Buyer1.Content  = $"{walletBuyer.Quantity}";
            walletBuyer     = moneyBuyer.Find(2);
            Buyer2.Content  = $"{walletBuyer.Quantity}";                                                    // Кошелёк пользователя
            walletBuyer     = moneyBuyer.Find(3);
            Buyer5.Content  = $"{walletBuyer.Quantity}";
            walletBuyer     = moneyBuyer.Find(4);
            Buyer10.Content = $"{walletBuyer.Quantity}";

            var            products = db.VendingMachines;
            VendingMachine product  = products.Find(1);

            Label1.Content            = $"{product.Product}, {product.Price}руб.";
            TeaPortion.Content        = $"{product.Quantity}";
            product                   = products.Find(2);
            Label2.Content            = $"{product.Product}, {product.Price}руб.";
            CoffeePortion.Content     = $"{product.Quantity}";                                            // Количество продуктов
            product                   = products.Find(3);
            Label3.Content            = $"{product.Product}, {product.Price}руб.";
            CoffeeMilkPortion.Content = $"{product.Quantity}";
            product                   = products.Find(4);
            Label4.Content            = $"{product.Product}, {product.Price}руб.";
            JuicePortion.Content      = $"{product.Quantity}";
        }
Exemplo n.º 4
0
        public void WalletChange(Label a, Label b, int c)
        {
            int x = Convert.ToInt32(a.Content) - 1;
            int y = Convert.ToInt32(b.Content) + 1;

            a.Content = $"{x}";
            b.Content = $"{y}";
            var         moneyBuyer  = db.BuyerWallets;
            BuyerWallet walletBuyer = moneyBuyer.Find(c);

            walletBuyer.Quantity = x;
            var           money  = db.MachineWallets;
            MachineWallet wallet = money.Find(c);

            wallet.Quantity = y;
            db.SaveChanges();
        }
Exemplo n.º 5
0
 public ProductsService(IProductsRepository productsRepository, UserWallet userWallet, MachineWallet machineWallet)
 {
     this._productsRepository = productsRepository;
     this._userWallet         = userWallet;
     this._machineWallet      = machineWallet;
 }
Exemplo n.º 6
0
 public MachineWalletService(MachineWallet machineWallet) : base(machineWallet)
 {
 }
Exemplo n.º 7
0
 public void Setup()
 {
     _userWallet    = new UserWallet();
     _machineWallet = new MachineWallet();
 }
        protected override void Seed(VendingMachineContext db)
        {
            VendingMachine vm1 = new VendingMachine
            {
                Price    = 13,
                Product  = "Чай",
                Quantity = 10
            };

            VendingMachine vm2 = new VendingMachine
            {
                Price    = 18,
                Product  = "Кофе",
                Quantity = 20
            };

            VendingMachine vm3 = new VendingMachine
            {
                Price    = 21,
                Product  = "Кофе с молоком",
                Quantity = 20
            };

            VendingMachine vm4 = new VendingMachine
            {
                Price    = 35,
                Product  = "Сок",
                Quantity = 15
            };

            db.VendingMachines.Add(vm1);
            db.VendingMachines.Add(vm2);
            db.VendingMachines.Add(vm3);
            db.VendingMachines.Add(vm4);

            BuyerWallet bw1 = new BuyerWallet()
            {
                CoinValue = 1,
                Quantity  = 10
            };

            BuyerWallet bw2 = new BuyerWallet()
            {
                CoinValue = 2,
                Quantity  = 30
            };

            BuyerWallet bw3 = new BuyerWallet()
            {
                CoinValue = 5,
                Quantity  = 20
            };

            BuyerWallet bw4 = new BuyerWallet()
            {
                CoinValue = 10,
                Quantity  = 15
            };

            db.BuyerWallets.Add(bw1);
            db.BuyerWallets.Add(bw2);
            db.BuyerWallets.Add(bw3);
            db.BuyerWallets.Add(bw4);

            MachineWallet mw1 = new MachineWallet()
            {
                CoinValue = 1,
                Quantity  = 100
            };

            MachineWallet mw2 = new MachineWallet()
            {
                CoinValue = 2,
                Quantity  = 100
            };

            MachineWallet mw3 = new MachineWallet()
            {
                CoinValue = 5,
                Quantity  = 100
            };

            MachineWallet mw4 = new MachineWallet()
            {
                CoinValue = 10,
                Quantity  = 100
            };

            db.MachineWallets.Add(mw1);
            db.MachineWallets.Add(mw2);
            db.MachineWallets.Add(mw3);
            db.MachineWallets.Add(mw4);

            db.SaveChanges();
        }