public async Task <Bebida> Create(Bebida bebida) { bebida.BebidaId = Guid.NewGuid(); await bebida.Validar <BebidaValidator, Bebida>(); await _bebidaRepository.Create(bebida); return(bebida); }
private void CadastraBebida() { try { if (string.IsNullOrEmpty(txtPreco.Text)) { throw new Exception("Informe o valor do produto"); } if (!string.IsNullOrEmpty(txtId.Text)) { _bebida = (Bebida)_produtoServico.PegarPorId(Convert.ToInt64(txtId.Text)); } else { _bebida = new Bebida(txtNome.Text, Convert.ToDouble(txtPreco.Text)); } _bebida.Nome = txtNome.Text; _bebida.ValorProduto = Convert.ToDouble(txtPreco.Text); if (cbTamanho.SelectedItem != null) { _bebida.Tamanho = (TamanhoEnum)cbTamanho.SelectedItem; } else { throw new Exception("Informe o tamanho do produto"); } if (cbTipo.SelectedItem != null) { _bebida.Tipo = (TipoProdutoEnum)cbTipo.SelectedItem; } _bebida.Validar(); } catch (Exception ex) { MessageBox.Show(ex.Message); DialogResult = DialogResult.None; } }