public async Task <ActionResult <Pecuarista> > PostPecuarista(Pecuarista pecuarista) { _context.Pecuaristas.Add(pecuarista); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPecuarista", new { id = pecuarista.PecuaristaId }, pecuarista)); }
public void ValidarCompraGado() { CompraGadoValidar CompraGadoItemRep = new CompraGadoValidar(new CompraGadoRepository(new SistemaCompraGadoDGContexto())); CompraGado _CompraGado = new CompraGado(); List <CompraGadoItem> _Itens = new List <CompraGadoItem>(); SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository PecuaristaRep = new SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository(new SistemaCompraGadoDGContexto()); Pecuarista LstPecuarista = (Pecuarista)PecuaristaRep.GetAll().First(); AnimalRepository AnimalRep = new AnimalRepository(new SistemaCompraGadoDGContexto()); Animal LstAnimal = (Animal)AnimalRep.GetAll().First(); _CompraGado.ID = 205; _Itens.Add(new CompraGadoItem { AnimalID = LstAnimal.ID, CompraGadoID = _CompraGado.ID, Quantidade = "1.000" }); // _Itens.Add(new CompraGadoItem { AnimalID = LstAnimal.ID, CompraGadoID = _CompraGado.ID, Quantidade = "1.000" }); _CompraGado.DataEntrega = DateTime.Now; _CompraGado.PecuaristaID = LstPecuarista.ID; _CompraGado.CompraDadoItem = _Itens; CompraGadoItemRep.ValidarCompraGado(_CompraGado); }
public async Task <IActionResult> Edit(int id, [Bind("PecuaristaId,Nome")] Pecuarista pecuarista) { if (id != pecuarista.PecuaristaId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(pecuarista); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PecuaristaExists(pecuarista.PecuaristaId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(pecuarista)); }
public async Task <IHttpActionResult> PutPecuarista(int id, Pecuarista pecuarista) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pecuarista.Id) { return(BadRequest()); } db.Entry(pecuarista).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PecuaristaExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutPecurista(int id, Pecuarista pecuarista) { if (id != pecuarista.Id) { return(BadRequest()); } _context.Entry(pecuarista).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PecuaristaExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void InserirPecuaristaData() { SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository PecuaristaRep = new SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository(new SistemaCompraGadoDGContexto()); Pecuarista _Pecuarista = new Pecuarista(); _Pecuarista.Nome = "Teste 2"; PecuaristaRep.Add(_Pecuarista); }
public void AtualizaPecuaristaData() { SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository PecuaristaRep = new SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository(new SistemaCompraGadoDGContexto()); Pecuarista _Pecuarista = new Pecuarista(); Pecuarista LstPecuarista = (Pecuarista)PecuaristaRep.GetAll().First(); _Pecuarista.ID = LstPecuarista.ID; _Pecuarista.Nome = "Teste 2"; PecuaristaRep.Update(_Pecuarista); }
public async Task <IHttpActionResult> GetPecuarista(int id) { Pecuarista pecuarista = await db.Pecuaristas.FindAsync(id); if (pecuarista == null) { return(NotFound()); } return(Ok(pecuarista)); }
public async Task <IActionResult> Create([Bind("PecuaristaId,Nome")] Pecuarista pecuarista) { if (ModelState.IsValid) { _context.Add(pecuarista); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pecuarista)); }
private void btnAlterar_Click(object sender, EventArgs e) { if (txtNome.Text.Trim() == "") { MetroFramework.MetroMessageBox.Show(this, "O nome do pecuarista não pode ficar em branco.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); txtNome.Focus(); return; } else { if (MetroFramework.MetroMessageBox.Show(this, "Deseja salvar as informações ?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } WebServiceMarfrigSoapClient wbClinet = null; Pecuarista classPecuarista = null; try { wbClinet = new WebServiceMarfrigSoapClient(); classPecuarista = new WebServiceMarfrig.Pecuarista(); if (txtId.Text != "NOVO" && txtId.Text != "") { classPecuarista.Id = Convert.ToInt32(txtId.Text); } else { classPecuarista.Id = 1; } classPecuarista.Nome = txtNome.Text; if (txtId.Text != "NOVO" && txtId.Text != "") { wbClinet.UpdatePecuarista(classPecuarista); } else { wbClinet.InserirPecuarista(classPecuarista); txtId.Text = ""; txtNome.Text = ""; } GetAllPecuarista(); } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public async Task <IHttpActionResult> PostPecuarista(Pecuarista pecuarista) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Pecuaristas.Add(pecuarista); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = pecuarista.Id }, pecuarista)); }
private void getPecuarista() { try { pecuaristaBindingSource.DataSource = wbclient.GetAllPecuaristaCompraGado(); Pecuarista opecuarista = pecuaristaBindingSource.Current as Pecuarista; } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public async Task <IHttpActionResult> DeletePecuarista(int id) { Pecuarista pecuarista = await db.Pecuaristas.FindAsync(id); if (pecuarista == null) { return(NotFound()); } db.Pecuaristas.Remove(pecuarista); await db.SaveChangesAsync(); return(Ok(pecuarista)); }
private void GetAllPecuarista() { try { WebServiceMarfrigSoapClient webpec = new WebServiceMarfrigSoapClient(); pecuaristaBindingSource.DataSource = webpec.GetAllPecuarista(); Pecuarista oPecurista = pecuaristaBindingSource.Current as Pecuarista; } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool UpdatePecuarista(Pecuarista oPecuarista) { using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexaoSql"].ConnectionString)) { if (db.State == ConnectionState.Closed) { db.Open(); } int resultado = db.Execute("sp_Atualizar_Pecuarista", new { Id = oPecuarista.Id, Nome = oPecuarista.Nome }, commandType: CommandType.StoredProcedure); return(resultado != 0); } }
public async Task <ActionResult <Pecuarista> > Post( [FromServices] Contexto context, [FromBody] Pecuarista model) { if (ModelState.IsValid) { context.Pecuaristas.Add(model); await context.SaveChangesAsync(); return(model); } else { return(BadRequest(ModelState)); } }
// GET: Animais public ActionResult Index() { //return View(await _context.Animais.ToListAsync()); //List<Medico> medicos = new List<Medico>(); var pec = new Pecuarista(); HttpResponseMessage response = client.GetAsync("api/v1/Animais").Result; if (response.IsSuccessStatusCode) { pec = response.Content.ReadAsAsync <Pecuarista>().Result; } return(View(pec)); }
public int Inserir(Pecuarista oPecuarista) { using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexaoSqlServer"].ConnectionString)) { if (db.State == ConnectionState.Closed) { db.Open(); } DynamicParameters p = new DynamicParameters(); p.Add("@Id", dbType: DbType.Int32, direction: ParameterDirection.Output); p.AddDynamicParams(new { Nome = oPecuarista.Nome }); int resultado = db.Execute("sp_Inserir_Pecuarista", p, commandType: CommandType.StoredProcedure); if (resultado != 0) { return(p.Get <int>("@Id")); } return(0); } }
public async Task <IActionResult> Post(Pecuarista model) { try { var pecuarista = _mapper.Map <Pecuarista>(model); _repository.Add(pecuarista); if (await _repository.SaveChangesAsync()) { return(Created($"/api/marfrig/{model.Id}", _mapper.Map <PecuaristaDto>(pecuarista))); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, $"Banco de dados falhou {ex.Message}")); } return(BadRequest()); }
public void ValidarCompraGadoAppService() { CompraGadoAppService CompraService = new CompraGadoAppService(new CompraGadoService(new CompraGadoRepository(new SistemaCompraGadoDGContexto()), new CompraGadoValidar(new CompraGadoRepository(new SistemaCompraGadoDGContexto())), new CompraGadoItemRepository((new SistemaCompraGadoDGContexto())), new PecuaristaRepository((new SistemaCompraGadoDGContexto())), new AnimalRepository(new SistemaCompraGadoDGContexto()))); CompraGado Compra = new CompraGado(); SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository PecuaristaRep = new SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository(new SistemaCompraGadoDGContexto()); Pecuarista LstPecuarista = (Pecuarista)PecuaristaRep.GetAll().First(); List <CompraGadoItem> _Itens = new List <CompraGadoItem>(); AnimalRepository AnimalRep = new AnimalRepository(new SistemaCompraGadoDGContexto()); Animal LstAnimal = (Animal)AnimalRep.GetAll().First(); Compra.ID = 545; Compra.DataEntrega = DateTime.Now; Compra.PecuaristaID = LstPecuarista.ID; _Itens.Add(new CompraGadoItem { AnimalID = LstAnimal.ID, CompraGadoID = 544, Quantidade = "1.000" }); Compra.CompraDadoItem = _Itens; CompraService.AdicionarCompra(Compra); }