public void AddOrUpdateWorkIngredient(WorkIngredientModel workIngredient) { var workIngredientEntity = new WorkIngredientEntity() { Id = workIngredient.Id, Name = workIngredient.Name, Count = workIngredient.Count, Quantities = workIngredient.Quantities, CodeIngredient = workIngredient.CodeIngredient }; _veterokCompanyContext.WorkIngredients.AddOrUpdate(workIngredientEntity); Save(); }
public WorkIngredientModel GetWorkIngredient(int code) { var workIngredientEntity = _veterokCompanyContext.WorkIngredients.FirstOrDefault(x => x.CodeIngredient == code); var workIngredient = new WorkIngredientModel() { Id = workIngredientEntity.Id, Name = workIngredientEntity.Name, Count = workIngredientEntity.Count, Quantities = workIngredientEntity.Quantities, CodeIngredient = workIngredientEntity.CodeIngredient }; return(workIngredient); }
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); } }
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); }