private void FrmCadMaisMorador_Load(object sender, EventArgs e) { Morador cadMorador = new Morador(); incrementar = cadMorador.autoIncremento(incrementar); txtnCOD.Text = Convert.ToString(incrementar); }
private void btSalvar_Click(object sender, EventArgs e) { Morador cadastro = new Morador(); cadastro.Codigo = (txtnCOD.Text); cadastro.Nome = (txtnNome.Text); cadastro.Cpf = (txtnCPF.Text); listaCadMorador.Add(cadastro); ponteiro = listaCadMorador.Count - 1; LoadField(true); Mensagem salvar = new Mensagem(); salvar.salvando(); LimparTela limpa = new LimparTela(); limpa.Limpar(this); txtnNome.Focus(); Morador incremento = new Morador(); incrementar = incremento.autoIncremento(incrementar); txtnCOD.Text = Convert.ToString(incrementar); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,DataDeNascimento,Telefone,Cpf,Email,IdApartamento")] Morador moradorPreenchido) { if (id != moradorPreenchido.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(moradorPreenchido); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MoradorExists(moradorPreenchido.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(moradorPreenchido)); }
public void Atualizar(Morador registro) { string strConexao = "SERVER=localhost; DataBase=condominio; UID=root; pwd="; using (MySqlConnection conn = new MySqlConnection(strConexao)) { conn.Open(); using (MySqlCommand cmd = new MySqlCommand()) { string query = $@"UPDATE morador m SET m.Nome = '{registro.Nome}', m.Email = '{registro.Email}', m.Cpf = '{registro.Cpf}', m.Telefone = '{registro.Telefone}', m.IdApartamentoFkMorador = '{registro.IdApartamentoFkMorador}' WHERE m.IdMorador = {registro.IdMorador};"; cmd.Connection = conn; cmd.CommandText = query; cmd.ExecuteNonQuery(); } } }
public ActionResult CadastraMorador(Morador obj) { MoradorDAO dao = new MoradorDAO(); dao.cadastra(obj); return(RedirectToAction("frmBuscaMorador")); }
public ActionResult AlteraMorador(Morador obj) { MoradorDAO dao = new MoradorDAO(); // dao.altera(obj); return(RedirectToAction("frmBuscaMorador")); }
public static Morador RecuperaObj(int pID) { SqlConnection objConexao = FabricaConexao.getConexao(); SqlCommand objCommand; SqlDataReader objLeitor; Morador objMorador = null; try { String strQuery = "SELECT ID, nome, CPF, email, Telefone, IsResponsavel, Apartamento FROM Morador WHERE ID = '" + pID + "'"; objCommand = new SqlCommand(strQuery, objConexao); objCommand.ExecuteNonQuery(); objLeitor = objCommand.ExecuteReader(); while (objLeitor.Read()) { objMorador = new Morador(); objMorador.Id = Convert.ToInt32(objLeitor[0]); objMorador.Nome = Convert.ToString(objLeitor[1]); objMorador.Cpf = Convert.ToString(objLeitor[2]); objMorador.Email = Convert.ToString(objLeitor[3]); objMorador.Telefone = Convert.ToString(objLeitor[4]); objMorador.IsResponsavel = Convert.ToBoolean(objLeitor[5]); objMorador.Apartamento.Id = Convert.ToInt32(objLeitor[6]); } objLeitor.Close(); return(objMorador); } catch (SqlException err) { String strErro = "Erro: " + err.ToString(); Console.Write(strErro); return(objMorador); } }
public async Task Morador_PutWithNoValidValues() { KiperContext Context = GetContext(); _MoradoresControleer = new MoradoresController(Context); await ForceAddInContext(Context); Apartamento apartamento = new Apartamento { ApartamentoId = 10, Bloco = "C", Numero = 200 }; Morador morador = new Morador { MoradorId = 10, Apartamento = apartamento, CPF = "99988877765", DataNascimento = DateTime.Now.AddDays(-45), EMail = "*****@*****.**", Nome = "Kiper_TESTE", Telefone = "(33) 3344-9999" }; var result = await _MoradoresControleer.PutMorador(1, morador) as BadRequestResult; Assert.Equal(400, result.StatusCode); }
private void BtnSalvar_Click(object sender, RoutedEventArgs e) { try { MoradoresControle moradoresControle = new MoradoresControle(); if (string.IsNullOrEmpty(txtPlacaM.Text)) { throw new NullReferenceException("o campo placa é obrigatorio!"); } Morador morador = new Morador(); morador.PresencaM = txtPresencaM.Text; morador.PlacaMId = txtPlacaM.Text; morador.CarroM = txtCarroM.Text; morador.NomeM = txtNome.Text; morador.TelefoneM = txtTelefoneM.Text; morador.Casa_numM = txtCasa_numM.Text; morador.StatusM = txttatusM.Text; moradoresControle.Adicionar(morador); MessageBox.Show("Cadastro Realizado como sucesso"); } catch (Exception ex) { MessageBox.Show("Erro ao Salvar( " + ex.Message + ")"); } }
public void InserirMoradorInvalido() { MoradorServico service = new MoradorServico(); Morador morador = new Morador(); service.Inserir(morador); }
protected void btnCadastrar_Click(object sender, EventArgs e) { /* * Obj * */ Morador obj = new Morador(); obj.Id_condominio = Convert.ToInt32(dlCondominio.SelectedValue); obj.Nome = txNome.Text; obj.Cpf = txCpf.Text; obj.Rg = txRg.Text; obj.Numero_apt = Convert.ToInt32(txNumeroApt.Text); obj.Adimplente = cbAdimplente.Checked; if (txId.Text.Equals("")) { obj.Id = obj.NextId(); obj.Adicionar(); } else { obj.Id = Convert.ToInt32(txId.Text); obj.Editar(); } this.redirecionarMesmaPagina(); }
public void T1Add() { //Add Bloco var blocoAdd = new Bloco() { Descricao = "Bloco A" }; var addBloco = _blocoRepository.AddAsync(blocoAdd); Assert.True(addBloco.IsCompletedSuccessfully); //Add Bloco var blocoAdd2 = new Bloco() { Descricao = "Bloco B" }; var addBloco2 = _blocoRepository.AddAsync(blocoAdd2); Assert.True(addBloco2.IsCompletedSuccessfully); //Add Apartamento var apartamentoAdd = new Apartamento() { Bloco = blocoAdd, Numero = 1, Moradores = new List <Morador>() }; var addApartamento = _apartamentoRepository.AddAsync(apartamentoAdd); Assert.True(addApartamento.IsCompletedSuccessfully); //Add Apartamento var apartamentoAdd2 = new Apartamento() { Bloco = blocoAdd2, Numero = 125, Moradores = new List <Morador>() }; var addApartamento2 = _apartamentoRepository.AddAsync(apartamentoAdd); Assert.True(addApartamento2.IsCompletedSuccessfully); //Add Moradores var moradoresAdd = new List <Morador>(); for (int i = 0; i < 10; i++) { var moradorAdd = new Morador() { Cpf = 01988377129, DataNascimento = Convert.ToDateTime("28/06/1985"), Fone = "61993766328", NomeCompleto = "Vitão " + i.ToString(), Apartamento = apartamentoAdd }; moradoresAdd.Add(moradorAdd); } var addMoradores = _moradorRepository.AddAsync(moradoresAdd); Assert.True(addApartamento.IsCompletedSuccessfully); //Save Changes var saveChanges = _mainContext.SaveChangesAsync(); Assert.True(saveChanges.IsCompletedSuccessfully); }
public Morador FindForCode(int Id) { try { Cmd = new SqlCommand("SELECT * FROM tb_morador where id=@v1"); Cmd.Parameters.AddWithValue("@v1", Id); Dr = Cmd.ExecuteReader(); Morador c = null; //Criando um espaço na memória if (Dr.Read()) { c = new Morador(); c.Id = Convert.ToInt32(Dr["Id"]); c.Nome = Convert.ToString(Dr["nome"]); c.Data_nascimento = Convert.ToDateTime(Dr["data_nascimento"]); c.Sexo = Convert.ToString(Dr["sexo"]); c.Cpf = Convert.ToString(Dr["cpf"]); c.Rg = Convert.ToString(Dr["rg"]); c.Id_Apartamento = Convert.ToInt32(Dr["id_apartamento"]); c.Data_cadastro = Convert.ToDateTime(Dr["data_cadastro"]); c.Cadastrado_por = Convert.ToInt32(Dr["cadastrado_por"]); } return(c); } catch (Exception ex) { throw new Exception("Não foi possível encontrar o cliente" + ex.Message); } finally { CloseConnection(); } }
public void Update(Morador c) { try { OpenConnection(); Cmd = new SqlCommand("UPDATE tb_morador SET nome=@v1, data_nascimento=@v2, sexo=@v3, cpf=@v4, rg=@v5, id_apartamento=@v6, cadastrado_por=@v7 where id =@v8", Con); //Atribuindo valores as variaveis do insert Cmd.Parameters.AddWithValue("@V1", c.Nome); Cmd.Parameters.AddWithValue("@V2", c.Data_nascimento); Cmd.Parameters.AddWithValue("@v3", c.Sexo); Cmd.Parameters.AddWithValue("@V4", c.Cpf); Cmd.Parameters.AddWithValue("@V5", c.Rg); Cmd.Parameters.AddWithValue("@V6", c.Id_Apartamento); Cmd.Parameters.AddWithValue("@V7", c.Cadastrado_por); Cmd.Parameters.AddWithValue("@V8", c.Id); Cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Erro ao atualizar o registro!" + ex.Message); } finally { CloseConnection(); } }
public async Task <IActionResult> EditMorador(MoradorViewModel view) { view.Apartamentos = await GetDropDownItemsApartamentos(false); if (!ModelState.IsValid) { return(View(view)); } Morador mrd = new Morador { Apartamento = await this.Apartamento.GetApartamento(Convert.ToInt32(view.SelectApartamento)), CPF = view.CPF, DataNascimento = view.DataNascimento, EMail = view.EMail, MoradorId = view.MoradorId, Nome = view.Nome, Telefone = view.Telefone }; var response = await this.Morador.PutMorador(mrd); if (response.Error) { ViewBag.Message = response.Message; } else { ViewBag.Status = "Morador atualizado com sucesso."; } return(View(view)); }
public bool Editar(Morador morador) { StringBuilder builder = new StringBuilder(); builder.Append("UPDATE "); builder.Append(this.TableName + " "); builder.Append("SET "); builder.Append("id_condominio = "); builder.Append(morador.Id_condominio + ", "); builder.Append("nome = "); builder.Append("'" + morador.Nome + "', "); builder.Append("cpf = "); builder.Append("'" + morador.Cpf + "', "); builder.Append("rg = "); builder.Append("'" + morador.Rg + "', "); builder.Append("numero_apt = "); builder.Append(morador.Numero_apt + ", "); builder.Append("adimplente = "); builder.Append(((morador.Adimplente == true) ? 1 : 0) + " "); builder.Append("WHERE "); builder.Append("id = " + morador.Id); builder.Append(";"); return(this.Update(builder.ToString())); }
public void Record(Morador c) { try { //Chama o método que abre a conexão OpenConnection(); //Passa para o objeto Cmd, o insert recebendo valores de variaveis Cmd = new SqlCommand("INSERT INTO tb_morador (nome, data_nascimento, sexo, cpf, rg, id_apartamento, cadastrado_por) " + "values (@v1, @v2, @v3, @v4, @v5, @v6, @v7)", Con); //Atribuindo valores as variaveis do insert Cmd.Parameters.AddWithValue("@V1", c.Nome); Cmd.Parameters.AddWithValue("@V2", c.Data_nascimento); Cmd.Parameters.AddWithValue("@v3", c.Sexo); Cmd.Parameters.AddWithValue("@V4", c.Cpf); Cmd.Parameters.AddWithValue("@V5", c.Rg); Cmd.Parameters.AddWithValue("@V6", c.Id_Apartamento); Cmd.Parameters.AddWithValue("@V7", c.Cadastrado_por); //Executando o método Cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Erro ao gravar registro!:" + ex.Message); } finally { CloseConnection(); } }
public void Salvar(Morador morador) { try { Morador m = ObterPorId(morador.Id); if (m != null) { _condominioDbContext.Entry <Morador>(m).State = EntityState.Detached; _condominioDbContext.SaveChanges(); _condominioDbContext.Morador.Update(morador); } else { _condominioDbContext.Morador.Add(morador); } _condominioDbContext.SaveChanges(); var pedidoSalvo = ObterPorId(morador.Id); } catch (Exception ex) { string erro = ex.Message; } }
public bool Adicionar(Morador morador) { StringBuilder builder = new StringBuilder(); builder.Append("INSERT INTO "); builder.Append(this.TableName + " "); builder.Append("( "); builder.Append("id, "); builder.Append("id_condominio, "); builder.Append("nome, "); builder.Append("cpf, "); builder.Append("rg, "); builder.Append("numero_apt, "); builder.Append("adimplente "); builder.Append(") "); builder.Append("VALUES "); builder.Append("("); builder.Append(morador.Id + ", "); builder.Append(morador.Id_condominio + ", "); builder.Append("'" + morador.Nome + "', "); builder.Append("'" + morador.Cpf + "', "); builder.Append("'" + morador.Rg + "', "); builder.Append(morador.Numero_apt + ", "); builder.Append(((morador.Adimplente == true) ? 1 : 0) + " "); builder.Append(");"); return(this.Update(builder.ToString())); }
public void Atualizar(MoradorTO to) { _Contexto = ControladorAcesso.ObterContexto(); if (to.Identificador == 0 || to == null) { to.Valido = false; to.Mensagem = Mensagem.Atualizacao("Morador", false); return; } Morador entidade = _Contexto.Morador.FirstOrDefault(x => x.Identificador == to.Identificador); if (entidade == null) { to.Valido = false; to.Mensagem = Mensagem.Obter("Morador", false); return; } to.PreencherEntidade(entidade); _Contexto.SaveChanges(); to.PreencherTO(entidade); to.Valido = true; to.Mensagem = Mensagem.Atualizacao("Morador", true); return; }
private async Task ForceAddInContext(KiperContext Context) { Apartamento apartamento = new Apartamento { Bloco = "A", Numero = 100 }; Morador morador = new Morador { Apartamento = apartamento, CPF = "98998998989", DataNascimento = DateTime.Now.AddDays(-100), EMail = "*****@*****.**", Nome = "Kiper", Telefone = "(33) 3344-4578" }; if (Context.Moradores.FirstOrDefault(x => x.CPF.Equals(morador.CPF) && x.EMail.Equals(morador.EMail)) != null) { return; } await Context.Moradores.AddAsync(morador); await Context.SaveChangesAsync(); }
public async Task <IActionResult> Edit(int id, [Bind("Id_Morador,Nome,QtdBichos,Id_Familia")] Morador morador) { if (id != morador.Id_Morador) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(morador); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MoradorExists(morador.Id_Morador)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Id_Familia"] = new SelectList(_context.Familias, "Id_Familia", "Nome", morador.Id_Familia); return(View(morador)); }
public async Task Morador_PostWithoutApto() { KiperContext Context = GetContext(); _MoradoresControleer = new MoradoresController(Context); await ForceAddInContext(Context); Morador morador = new Morador { CPF = "23499087043", DataNascimento = DateTime.Now.AddDays(-500), EMail = "*****@*****.**", Nome = "João", Telefone = "(33) 3344-6755" }; var result = await _MoradoresControleer.PostMorador(morador) as NotFoundObjectResult; var jsonSerialize = JsonConvert.SerializeObject(result.Value); var jsonResult = JsonConvert.DeserializeObject <CallStatus>(jsonSerialize); Assert.Equal(404, result.StatusCode); Assert.Equal("Erro ao tentar incluir o Morador João".ToUpper(), jsonResult.Message.ToUpper()); Assert.True(jsonResult.Error); }
private void dgrMorador_CellClick(object sender, DataGridViewCellEventArgs e) { btnInserir.Text = "Alterar"; PopularApartamento(); if (e.RowIndex != -1) { int ID = Convert.ToInt32(dgrMorador.Rows[e.RowIndex].Cells[0].Value.ToString()); BLL.BllMorador bllMorador = new BLL.BllMorador(); Morador morador = new Morador(); Endereco endereco = new Endereco(); morador = bllMorador.Return_Morador(ID); txtNome.Text = morador.MORADORNOME; txtDoc.Text = morador.MORADORCPF; txtRG.Text = morador.MORADORRG; txtDDD1.Text = morador.MORADORDDD1; txtDDD2.Text = morador.MORADORDDD2; cbxApartamento.SelectedValue = Convert.ToInt32(morador.MORADORAPART.ToString()); txtTel.Text = morador.MORADORDTEL; txtCel.Text = morador.MORADORDCEL; txtEmail.Text = morador.MORADOREMAIL; lblID.Text = morador.MORADORID.ToString(); } }
public void Inserir(Morador morador) { var moradorLista = ObterMoradores().Where(x => x.Cpf == morador.Cpf).ToList(); using (Connection = new SqlConnection(StringConnection)) { if (moradorLista.Count == 0) { var parametros = new DynamicParameters(); parametros.Add("@Nome", morador.Nome.Trim().ToUpper()); parametros.Add("@DataDeNascimento", morador.DataDeNascimento); parametros.Add("@Telefone", morador.Telefone.Trim()); parametros.Add("@Celular", morador.Celular.Trim()); parametros.Add("@Email", morador.Email.Trim().ToUpper()); parametros.Add("@Cpf", morador.Cpf.Trim()); parametros.Add("@Ativo", EntidadeAtiva.Ativo); Connection.Execute("Insert_Morador", parametros, commandType: CommandType.StoredProcedure); } else { throw new Exception($"Já existe um morador com o CPF {morador.Cpf} registrado!"); } } }
public void AdicionarMoradorTest3() { var listTodosAptos = _apartamentoServices.ListarTodosApartamentos(); Assert.True((listTodosAptos.Count > 1)); var aptoNovoMorador = listTodosAptos.FirstOrDefault(it => it.Moradores.Count > 1); Morador novoMorador = new Morador() { Apartamento = aptoNovoMorador, Cpf = 123456789, DataNascimento = DateTime.Parse("28/04/2001"), Fone = "6133566565", NomeCompleto = "Jão do caminhãoo" }; _mainContext.GetSet <Apartamento>().Attach(aptoNovoMorador); var adicionarMorador = _moradorServices.AdicionarMorador(novoMorador); Assert.True(adicionarMorador); //Save Changes var saveChanges = _mainContext.SaveChangesAsync(); Assert.True(saveChanges.IsCompletedSuccessfully); }
public ActionResult DeleteConfirmed(int id) { Morador morador = db.Moradors.Find(id); db.Moradors.Remove(morador); db.SaveChanges(); return(RedirectToAction("Index")); }
public void ExclusaoMorador() { Morador morador = new Morador(); morador.Id = 1; Assert.IsTrue(morador.Excluir()); }
public object Excluir(String id) { Morador morador = new Morador(); morador.id = Convert.ToInt32(id); moradorServico.Excluir(morador); return(new HttpResponseMessage(HttpStatusCode.OK));; }
public IList <Morador> ListarPorApartamento(String idApartamento) { Morador morador = new Morador(); morador.apartamento = new Apartamento(); morador.apartamento.id = Convert.ToInt32(idApartamento); return(moradorServico.ListarPorApartamento(morador)); }