Esempio n. 1
0
 public void UpdateFields(VendingMachineEntities context)
 {
     UserSumm   = (int)context.GetSumCashOwner(User.Id).ToList().First();
     Balance    = (int)context.UserBalance.Where(x => x.cashOwnerId == User.Id).Select(y => y.balance).First();
     UserWallet = new ObservableCollection <MoneyViewModel>(context.GetWallet(User.Id).Select(p => new MoneyViewModel {
         IsButtonVisible = System.Windows.Visibility.Hidden, Name = p.name, Amount = p.amount, cashType = p.TypeCash
     }).ToList());
     AutomatWallet = new ObservableCollection <MoneyViewModel>(context.GetWallet(VendingMachine.Id).Select(p => new MoneyViewModel {
         IsButtonVisible = System.Windows.Visibility.Visible, Name = p.name, Amount = p.amount, cashType = p.TypeCash
     }).ToList());
     ProductsInAutomat = new ObservableCollection <ProductViewModel>(context.ProductRange.Select(x => new ProductViewModel {
         Name = x.name, Amount = x.amount, Price = x.price, Id = x.id
     }).ToList());
     UserBasket = new ObservableCollection <ProductViewModel>(context.ProductLatestSales().Select(x => new ProductViewModel {
         Name = x.name, Amount = x.amount, Price = x.price
     }).ToList());
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IDataService dataService)
        {
            _dataService = dataService;
            _dataService.GetData(
                (item, error) =>
            {
                if (error != null)
                {
                    // Report error here
                    return;
                }

                WelcomeTitle = item.Title;
            });
            using (VendingMachineEntities context = new VendingMachineEntities())
            {
                context.NewUserBasket();
                User           = new CashOwner("User", context.CashOwner.Where(x => x.name == "User").Select(y => y.id).FirstOrDefault());
                VendingMachine = new CashOwner("VendingMachine", context.CashOwner.Where(x => x.name == "VendingMachine").Select(y => y.id).FirstOrDefault());
                UpdateFields(context);
            }
        }