Exemple #1
0
        public void SaveChanges()
        {
            if (string.IsNullOrEmpty(NameOfSelectedDish))
            {
                MessageBox.Show("Name must not be empty", "Save Dish");
                return;
            }

            double price;
            bool   ok = ParsePrice(out price);

            if (!ok)
            {
                return;
            }

            string oldName = _selectedDish.Name, newName = NameOfSelectedDish;

            /*// TODO This does not find duplicate names!
             * if (IsDishNameInUse(newName, _selectedDish))
             * {
             *  MessageBox.Show($"Dish named {newName} already exists. Please write a different name.", "Save Dish");
             *  return;
             * }
             */

            int  index     = Dishes.IndexOf(SelectedDish);
            bool isRenamed = oldName != newName;

            _selectedDish.Name            = NameOfSelectedDish;
            _selectedDish.Description     = DescriptionOfSelectedDish;
            _selectedDish.Price           = price;
            _selectedDish.ContainsLactose = SelectedDishContainsLactose;
            _selectedDish.ContainsGluten  = SelectedDishContainsGluten;
            _selectedDish.ContainsFish    = SelectedDishContainsFish;

            DataAccess da = new DataAccess();

            da.ModifyDish(_selectedDish);

            if (isRenamed)
            {
                // Reload the list to force items update in ComboBox
                Dishes.Clear();
                Dishes.AddRange(TrimNames(new DataAccess().GetAllDishes()));

                NotifyOfPropertyChange(() => Dishes);
                NotifyOfPropertyChange(() => SelectedDish);
            }
            SelectedDishModified = false;
        }
Exemple #2
0
        /// <summary>
        /// Обновление списков сущностей.
        /// </summary>
        private void UpdateLists()
        {
            Dishes.Clear();
            Prepacks.Clear();
            Products.Clear();

            Shared.NHibernate.Environment.Session.Clear();

            var dishes = Repository.Get <Dish>();

            foreach (var dish in dishes)
            {
                dish.Update();
                dish.EntitySaved   += OnEntityChanged;
                dish.EntityDeleted += OnEntityChanged;
            }

            var prepacks = Repository.Get <Prepack>();

            foreach (var prepack in prepacks)
            {
                prepack.Update();
                prepack.EntitySaved   += OnEntityChanged;
                prepack.EntityDeleted += OnEntityChanged;
            }

            var products = Repository.Get <Product>();

            foreach (var product in products)
            {
                product.Update();
                product.EntitySaved   += OnEntityChanged;
                product.EntityDeleted += OnEntityChanged;
            }

            Dishes.AddRange(dishes.Select(x => new DishViewModel(x)));
            Prepacks.AddRange(prepacks.Select(x => new PrepackViewModel(x)));
            Products.AddRange(products.Select(x => new ProductViewModel(x)));
        }