Esempio n. 1
0
        public void IngridientChange(IngridientModel ingridient)
        {
            if (SelectedIndex == -1)
            {
                return;
            }

            if (Mouse.LeftButton == MouseButtonState.Pressed)
            {
                foreach (DetailImportationItemViewModel item in ListDetailImportation)
                {
                    if (item.IngridientName.Equals(ingridient.Name))
                    {
                        item.Quantity++;
                        NotifyDetailImportationProperty();
                        return;
                    }
                }

                UnitModel unit = UnitModel.GetModelFromID(ingridient.UnitID);

                DetailImportationModel detail = new DetailImportationModel(DetailImportationModel.GenerateID(listDetailImportation.ListDetail), newImportation.ID, ingridient.ID, unit.ID, 1, ingridient.Price);
                listDetailImportation.Add(new DetailImportationItemViewModel(ingridient, unit, detail));

                NotifyDetailImportationProperty();
            }
        }
        private void SelectedIngridientChange(IngridientModel ingridient)
        {
            if (SelectedIndex == -1)
            {
                return;
            }

            if (Mouse.LeftButton == MouseButtonState.Pressed)
            {
                //Check if ingridient was chosen, then update quantity
                foreach (DetailImportationItemViewModel item in ListDetailImportation)
                {
                    if (item.IngridientName.Equals(ingridient.Name))
                    {
                        //update quantity
                        item.Quantity++;
                        NotifyDetaillImportationProperty();
                        return;
                    }
                }

                //Otherwise, create the importation
                // model related
                UnitModel unit = UnitModel.GetModelFromID(ingridient.UnitID);

                // Generate id for detaill importation
                DetailImportationModel detail = new DetailImportationModel(DetailImportationModel.GenerateID(listDetailImportation.ListDetail), newImportation.ID, ingridient.ID, unit.ID, 1, ingridient.Price);
                listDetailImportation.Add(new DetailImportationItemViewModel(ingridient, unit, detail));

                NotifyDetaillImportationProperty();
            }

            if (Mouse.RightButton == MouseButtonState.Pressed)
            {
                //Check if ingridient was chosen, then update quantity
                foreach (DetailImportationItemViewModel item in ListDetailImportation)
                {
                    if (item.IngridientName.Equals(ingridient.Name))
                    {
                        //update quantity
                        item.Quantity--;
                        if (item.Quantity == 0)
                        {
                            RemoveItem(item);
                        }
                        NotifyDetaillImportationProperty();
                        return;
                    }
                }
            }
        }