Ejemplo n.º 1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (productDataGridView.CurrentRow == null)
            {
                validMessageLabel.Text    = ConstantName.ValidProductMessage;
                validMessageLabel.Visible = true;
            }
            else if (nameTextBox.Text == String.Empty)
            {
                validMessageLabel.Text    = ConstantName.ValidNameMessage;
                validMessageLabel.Visible = true;
            }
            else
            {
                var product        = productDataGridView.CurrentRow.DataBoundItem as ProductModel;
                var quantitiesType = quantitiesTypeDictionary.First(x => x.Value == quantitiesComboBox.Text).Key;

                var ingredient = new IngredientModel()
                {
                    Id             = Convert.ToInt32(idIngredientLabel.Text),
                    Name           = nameTextBox.Text,
                    Count          = countNumericUpDown.Value,
                    Quantities     = quantitiesType,
                    IdProduct      = product.Id,
                    CodeIngredient = (int)codeIngredientNumericUpDown.Value
                };

                _ingredientRepository.AddOrUpdateIngredient(ingredient);
                UpdateIngredientGrid();
                validMessageLabel.Visible = false;

                if (_workIngredientRepository.GetWorkIngredientsList().All(x => x.Name != ingredient.Name))
                {
                    var workIngredient = new WorkIngredientModel()
                    {
                        Name           = ingredient.Name,
                        Count          = ConstantName.MinValue,
                        Quantities     = quantitiesComboBox.Text,
                        CodeIngredient = ingredient.CodeIngredient
                    };
                    _workIngredientRepository.AddOrUpdateWorkIngredient(workIngredient);
                }

                MessageBox.Show(ConstantName.SucessfulSaveMessage, ConstantName.Attention);
            }
        }
Ejemplo n.º 2
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            var idIngredient = int.Parse(idIngredientLabel.Text);
            var ingredient   = new WorkIngredientModel();

            if (idIngredient != ConstantName.MinValue)
            {
                ingredient = _workIngredientRepository.GetWorkIngredientsList().FirstOrDefault(x => x.Id == idIngredient);
            }
            else
            {
                ingredient = ingredientDataGridView.CurrentRow.DataBoundItem as WorkIngredientModel;
            }
            ingredient.Count += countNumericUpDown.Value;
            _workIngredientRepository.AddOrUpdateWorkIngredient(ingredient);
            InitializeGrid();
            MessageBox.Show(ConstantName.SucessfulAddMessage, ConstantName.Attention);
        }