public async Task <IActionResult> Edit(int id, [Bind("IdTipoCultivo,NombreTipoCultivos,CaracteristicasTipoCultivos")] TipoCultivo tipoCultivo) { if (id != tipoCultivo.IdTipoCultivo) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tipoCultivo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TipoCultivoExists(tipoCultivo.IdTipoCultivo)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tipoCultivo)); }
protected void btnCadastrar_Click(object sender, EventArgs e) { string mensagem; Cultivo cul = new Cultivo(); cul.Nome = txtNome.Text; TipoCultivo tip = new TipoCultivo(); tip.Id = Convert.ToInt32(ddlTipo.SelectedValue); cul.Tipo = tip; if (CultivoDB.Insert(cul)) { mensagem = "Cadastrado com sucesso!"; txtNome.Text = ""; txtNome.Focus(); } else { mensagem = "Erro!"; } Response.Write("<script language='javascript'>alert('" + mensagem + "');</script>"); }
public async Task <IActionResult> Create([Bind("IdTipoCultivo,NombreTipoCultivos,CaracteristicasTipoCultivos")] TipoCultivo tipoCultivo) { if (ModelState.IsValid) { _context.Add(tipoCultivo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tipoCultivo)); }
protected void btnCadastrar_Click(object sender, EventArgs e) { TipoCultivo tipo = new TipoCultivo(); tipo.Nome = txtNome.Text; TipoCultivoDB t = new TipoCultivoDB(); if (t.Insert(tipo)) { mensagem = "Cadastrado com sucesso!"; txtNome.Text = ""; txtNome.Focus(); } else { mensagem = "Erro!"; } Response.Write("<script language='javascript'>alert('" + mensagem + "');</script>"); }
//insert public bool Insert(TipoCultivo tipo) { System.Data.IDbConnection objConexao; System.Data.IDbCommand objCommand; try { string sql = "INSERT INTO tic_tipo_cultivo(tip_nome) VALUES(?tic_nome)"; objConexao = Mapped.Connection(); objCommand = Mapped.Command(sql, objConexao); objCommand.Parameters.Add(Mapped.Parameter("?tic_nome", tipo.Nome)); objCommand.ExecuteNonQuery(); objConexao.Close(); objCommand.Dispose(); objConexao.Dispose(); return(true); } catch (Exception e) { return(false); } }
//update public bool Update(TipoCultivo tipo) { System.Data.IDbConnection objConexao; System.Data.IDbCommand objCommand; string sql = "UPDATE tic_tipo_cultivo SET tic_nome = ?tic_nome WHERE tic_id = ?tic_id"; try { objConexao = Mapped.Connection(); objCommand = Mapped.Command(sql, objConexao); objCommand.Parameters.Add(Mapped.Parameter("?tip_nome", tipo.Nome)); objCommand.Parameters.Add(Mapped.Parameter("?tic_id", tipo.Id)); objCommand.ExecuteNonQuery(); objConexao.Close(); objCommand.Dispose(); objConexao.Dispose(); return(true); }catch (Exception e) { return(false); } }
public TipoCultivo Select(int id) { TipoCultivo obj = null; System.Data.IDbConnection objConexao; System.Data.IDbCommand objCommand; System.Data.IDataReader objDataReader; objConexao = Mapped.Connection(); objCommand = Mapped.Command("SELECT * FROM tic_tipo_cultivo WHERE tic_id = ?tic_id", objConexao); objCommand.Parameters.Add(Mapped.Parameter("?tic_id", id)); objDataReader = objCommand.ExecuteReader(); while (objDataReader.Read()) { obj = new TipoCultivo(); obj.Nome = Convert.ToString(objDataReader["tip_nome"]); } objDataReader.Close(); objConexao.Close(); objCommand.Dispose(); objConexao.Dispose(); objDataReader.Dispose(); return(obj); }
public async Task <IActionResult> Create(TipoCultivo tipoCultivo) { if (ModelState.IsValid) { //guarda la imagen en wwwroot/image string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(tipoCultivo.ImageFile.FileName); string extension = Path.GetExtension(tipoCultivo.ImageFile.FileName); //guarda el nombre de la imagen (ImageName) tipoCultivo.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; string path = Path.Combine(wwwRootPath + "/img/tipo", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await tipoCultivo.ImageFile.CopyToAsync(fileStream); } _context.Add(tipoCultivo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tipoCultivo)); }