コード例 #1
0
        public ClientMenuViewModel(User user, Reservation reservation, FastObservableCollection <OrderedDish> orderedDishes = null)
        {
            _user          = user;
            _reservation   = reservation;
            _rootViewModel = ViewModelManager.GetFirstOrDefaultInstance <MainWindowViewModel>();
            OrderedDishes.AutomaticallyDispatchChangeNotifications = true;
            // передаем в конструктор ссылку на собираемую коллекцию заказанных блюд
            _sumCalculator = new OrderedSumCalculator(OrderedDishes);

            AddCommand = new Command(OnAddCommandExecute);
            SelectionChangedCommand = new Command(OnSelectionChangedCommandExecute);
            DeleteCommand           = new Command(OnDeleteCommandExecute, OnDeleteCommandCanExecute);
            BackCommand             = new Command(OnBackCommandExecute);
            NextCommand             = new Command(OnNextCommandExecute, OnNextCommandCanExecute);

            RefreshDishesCollection();

            if (orderedDishes != null)
            {
                OrderedDishes = orderedDishes;
                TotalSum      = _sumCalculator.GetCurrentOrderedSum();
            }
            else
            {
                OrderedDishes.Clear();
            }
        }
コード例 #2
0
        private void RefreshOrdersWithReservationsCollection()
        {
            OrdersWithReservations.Clear();
            OrderedDishes.Clear();

            var userOrders = _unitOfWork.Orders.GetAll()
                             .Join(_unitOfWork.Reservations.GetAll(),
                                   order => order.ReservationId,
                                   reservation => reservation.Id,
                                   (o, r) => new OrderWithReservationInfo
            {
                OrderId   = o.Id,
                TableId   = r.TableId,
                UserId    = o.UserId,
                Day       = r.Day.ToLongDateString(),
                FirstTime = r.FirstTime.ToShortTimeString(),
                LastTime  = r.LastTime.ToShortTimeString()
            })
                             .Where(or => or.UserId == _user.Id);

            foreach (var us in userOrders)
            {
                OrdersWithReservations.Add(us);
            }
        }
コード例 #3
0
        private void OnSelectAnotherOrderCommandExecute()
        {
            if (SelectedOrderWithReservation != null)
            {
                OrderedDishes.Clear();
                // получаем все заказанные блюда
                var orderedDishes = _unitOfWork.OrderedDishes.GetAll()
                                    .Where(od => od.OrderId == SelectedOrderWithReservation.OrderId);

                // добавляем в коллекцию
                OrderedDishes.AddItems(orderedDishes);
                TotalSum = _orderedSumCalculator.GetCurrentOrderedSum();
            }
        }