private async Task GuardarProducto() { try { if (await _productoRepository.Add(_producto)) { var producto = await _productoRepository.Get(_producto.Nombre); var productoId = producto.OrderByDescending(i => i.Id).FirstOrDefault(p => p.Nombre == _producto.Nombre).Id; if (productoId > 0) { foreach (Ingrediente ing in _Ingredientes) { ing.ProductoId = productoId; await _ingredienteRepository.Add(ing); } foreach (Instruccion ins in _Instrucciones) { ins.ProductoId = productoId; await _instruccionRepository.Add(ins); } foreach (Imagen img in _Imagenes) { img.ProductoId = productoId; img.Nombre = _producto.Nombre + "_" + img.Nombre + ".jpg"; img.Url = Url + img.Nombre; if (await _imagenRepository.Add(img)) { img.Img.Save(img.Url); } } } MetroFramework.MetroMessageBox.Show(this, "Se Creo un producto nuevo"); } } catch (Exception ex) { Console.Write(ex.Message); } }
private async void BtnAgregar_Click(object sender, EventArgs e) { if (txtInstruccion.Text.Trim().Length > 0) { if (await _instruccionRepository.Add(new Instruccion { PasoDB = txtInstruccion.Text.Trim().ToUpper(), Paso = txtInstruccion.Text.Trim().ToUpper(), ProductoId = _productoId })) { MetroFramework.MetroMessageBox.Show(this, "Se Agrego una Instrunccion"); } else { MetroFramework.MetroMessageBox.Show(this, "Ocurrio un problema"); } await CargarInstrucciones(); } else { MetroFramework.MetroMessageBox.Show(this, "Agregar una Instruccion"); } }