private static void InicializarDados(DbContexto dbContexto) { if (dbContexto.Marcacoes.Any() || dbContexto.Clientes.Any()) { return; } var marcacoes = new Marcacao[] { new Marcacao(DateTime.Now, new Cliente("Michael", "Jackson", "44.415.079-1", "(68) 98275-1375", new Endereco("Logradouro", "Número", "Complemento", "Cidade", "Estado", "CEP")), EnumTipoServico.Massagem1Hora), new Marcacao(DateTime.Now, new Cliente("Silvio", "Santos", "38.225.184-2", "(32) 99401-5342", new Endereco("Logradouro", "Número", "Complemento", "Cidade", "Estado", "CEP")), EnumTipoServico.Massagem30Minutos), new Marcacao(DateTime.Now, new Cliente("Carolina", "Dieckmann", "40.569.492-1", "(61) 98533-1477", new Endereco("Logradouro", "Número", "Complemento", "Cidade", "Estado", "CEP")), EnumTipoServico.Outros), new Marcacao(DateTime.Now, new Cliente("Neymar", "Junior", "47.929.051-9", "(37) 98895-9142", new Endereco("Logradouro", "Número", "Complemento", "Cidade", "Estado", "CEP")), EnumTipoServico.Massagem1Hora), new Marcacao(DateTime.Now, new Cliente("Viviane", "Araújo", "34.780.414-7", "(88) 99184-0317", new Endereco("Logradouro", "Número", "Complemento", "Cidade", "Estado", "CEP")), EnumTipoServico.Massagem30Minutos) }; try { dbContexto.Marcacoes.AddRange(marcacoes); dbContexto.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.ToString()); } }
private void ButtonLogar_Click(object sender, RoutedEventArgs e) { if (textBoxUsuario.Text != "" && passwordBoxSenha.Password != "") { try { using (DbContexto ctx = new DbContexto()) { var consulta = ctx.Usuarios.FirstOrDefault(u => u.usuario1 == textBoxUsuario.Text); if (consulta != null) { if (consulta.senha == passwordBoxSenha.Password) { this.Hide(); new Frams.Prinipal(consulta.usuario1, consulta.nivel_acesso.ToString()).ShowDialog(); } else { MessageBox.Show("Senha invalida!!"); } } else { MessageBox.Show("Usuário invalido!!"); } } } catch { } } else { MessageBox.Show("Campo usuário ou senha estão vazios!!"); } }
public ActionResult Login(string returnUrl) { using (DbContexto _contexto = new DbContexto()) { if (!_contexto.Database.Exists()) { try { var senha = Cripto.HashMD5("123456"); var login = new LoginModel { Login = "******", Nome = "Administrador", Senha = senha, Email = "*****@*****.**" }; _contexto.Login.Add(login); _contexto.SaveChanges(); } catch (Exception) { throw; } } } ViewBag.ReturnUrl = returnUrl; return(View()); }
public List <Restaurante> buscarRestaurantes() { DbContexto db = new DbContexto(); var restaurantes = db.restaurante.ToList(); return(restaurantes); }
public IActionResult Index() { DbContexto db = new DbContexto(); var e = db.Livro.ToList(); return(View()); }
public List <Prato> buscarPratosPorRestaurante(Restaurante restaurante) { DbContexto db = new DbContexto(); var restaurantes = db.prato.Where(p => p.restaurante.id == restaurante.id).ToList(); return(restaurantes); }
public Aluno ObterAlunoPorId(int idAluno) { using (DbContexto db = new DbContexto()) { return(db.Alunos.Where(x => x.Id == idAluno).FirstOrDefault()); } }
private void DataGridConsulta_Loaded(object sender, RoutedEventArgs e) { using (DbContexto ctx = new DbContexto()) { var consulta = ctx.Agendamentos; dataGridConsulta.ItemsSource = consulta.ToList(); } }
public void removerPrato(List <Prato> pratos) { DbContexto db = new DbContexto(); pratos.ForEach(prato => db.Entry(prato).State = EntityState.Deleted); db.SaveChanges(); }
public TabelaAuxiliarController() { _contexto = new DbContexto(); _repositorio = new RepositorioTabelaAuxiliar(_contexto); // ViewData["Funcionarios"] = _repositorioFuncionario.ObterTodos().Select(c => new { Id = c.PessoaId, Nome = c.Nome }).OrderBy(x=>x.Nome); }
public _WebSocketServico(DbContexto _db) { Repositorio repositorio = new Repositorio(_db); this._db = _db; this.livroServico = repositorio.getLivroServico(); this.autentificacaoServico = repositorio.getAutentificacaoServico(); this.mensagemServico = repositorio.getMensagemServico(); }
public void removerPrato(Prato prato) { DbContexto db = new DbContexto(); db.prato.Attach(prato); db.Entry(prato).State = EntityState.Deleted; db.SaveChanges(); }
private void ListarAgendamentos() { using (DbContexto ctx = new DbContexto()) { int a = ctx.Agendamentos.Count(); conta.Content = a; var consulta = ctx.Agendamentos; dataGridConsulta.ItemsSource = consulta.ToList(); } }
private void ListarPacientes() { using (DbContexto ctx = new DbContexto()) { int a = ctx.Clientes.Count(); conta.Content = a; var consulta = ctx.Clientes; dataGridConsulta.ItemsSource = consulta.ToList(); } }
private void ButtonBuscar_Click(object sender, RoutedEventArgs e) { try { using (DbContexto ctx = new DbContexto()) { var consulta = from c in ctx.Agendamentos where c.data.Contains(textBoxBuscar.Text) select c; dataGridConsulta.ItemsSource = consulta.ToList(); } } catch { } }
private void ButtonBuscaPaciente_Click(object sender, RoutedEventArgs e) { try { using (DbContexto ctx = new DbContexto()) { var consulta = from c in ctx.Clientes where c.nome.Contains(textBoxPaciente.Text) select c; dataGridPaciente.ItemsSource = consulta.ToList(); } } catch { } }
private void ButtonSalvar_Click(object sender, RoutedEventArgs e) { Agendamento a = new Agendamento(); a.medico = Convert.ToInt32(comboBoxMedico.Text); a.tipo = comboBoxTipoAgendamento.Text; a.data = datePickerDataAgendamento.Text; a.horario = textBoxHoraAtendimento.Text; a.paciente = textBoxCodigoPaciente.Text; a.convenio = comboBoxConvenio.Text; if (operacao == "cadastrar") { using (DbContexto ctx = new DbContexto()) { ctx.Agendamentos.Add(a); ctx.SaveChanges(); } } if (operacao == "alterar") { using (DbContexto ctx = new DbContexto()) { a = ctx.Agendamentos.Find(Convert.ToInt32(textBoxCodigo.Text)); if (a != null) { a.medico = Convert.ToInt32(comboBoxMedico.Text); a.tipo = comboBoxTipoAgendamento.Text; a.data = datePickerDataAgendamento.Text; a.horario = textBoxHoraAtendimento.Text; a.paciente = textBoxCodigoPaciente.Text; a.convenio = comboBoxConvenio.Text; ctx.SaveChanges(); } } } if (operacao == "excluir") { using (DbContexto ctx = new DbContexto()) { a = ctx.Agendamentos.Find(Convert.ToInt32(textBoxCodigo.Text)); ctx.Agendamentos.Remove(a); ctx.SaveChanges(); } } AlteraBotoes(1); LimparCampos(); LimparTabela(); ListarAgendamentos(); }
private void ButtonBuscar_Click(object sender, RoutedEventArgs e) { try { using (DbContexto ctx = new DbContexto()) { var consulta1 = from c in ctx.Lancamentos where c.data.Equals(textBoxBuscar.Text) & c.tipo.Equals("Entrada") select c; dataGridEntradas.ItemsSource = consulta1.ToList(); var consulta2 = from c in ctx.Lancamentos where c.data.Equals(textBoxBuscar.Text) & c.tipo.Equals("Saida") select c; dataGridSaidas.ItemsSource = consulta2.ToList(); } } catch { } }
IList <Aluno> IRepositorio.ListarAlunos() { try { using (DbContexto db = new DbContexto()) { return(db.Alunos.ToList()); } } catch (Exception ex) { return(null); } }
private void ButtonSalvar_Click(object sender, RoutedEventArgs e) { Lancamento l = new Lancamento(); l.tipo = comboBoxTipo.Text; l.data = comboBoxData.Text; l.descricao = TextBoxDescricao.Text; l.forma_pagamento = comboBoxFormaPagamento.Text; l.valor = Convert.ToDecimal(TextBoxValor.Text); l.mes = Convert.ToInt32(comboBoxMes.Text); if (operacao == "cadastrar") { using (DbContexto ctx = new DbContexto()) { ctx.Lancamentos.Add(l); ctx.SaveChanges(); } } if (operacao == "alterar") { using (DbContexto ctx = new DbContexto()) { l = ctx.Lancamentos.Find(Convert.ToInt32(textBoxCodigo.Text)); if (l != null) { l.tipo = comboBoxTipo.Text; l.data = comboBoxData.Text; l.descricao = TextBoxDescricao.Text; l.forma_pagamento = comboBoxFormaPagamento.Text; l.valor = Convert.ToDecimal(TextBoxValor.Text); l.mes = Convert.ToInt32(comboBoxMes.Text); ctx.SaveChanges(); } } } if (operacao == "excluir") { using (DbContexto ctx = new DbContexto()) { l = ctx.Lancamentos.Find(Convert.ToInt32(textBoxCodigo.Text)); ctx.Lancamentos.Remove(l); ctx.SaveChanges(); } } AlteraBotoes(1); LimparCampos(); ListarLancamentos(); }
//Functions private void LogarValidado(Login login) { using (DbContexto db = new DbContexto()) { var validaAcesso = db.Usuario.Where(u => u.Login.Equals(login.LoginUsuario) && u.Senha.Equals(login.Senha)).FirstOrDefault(); if (validaAcesso.Senha == login.Senha && validaAcesso.Login == login.LoginUsuario) { Session["Nome"] = validaAcesso.Nome; Session["Sobrenome"] = validaAcesso.Sobrenome; Session["ID"] = validaAcesso.ID; Session["UsuarioLogado"] = true; } } }
public virtual bool IdExiste(int id) { using (ISession session = DbContexto.AbrirSession()) { try { TEntity obj = session.Get <TEntity>(id); return(obj == null); } catch (Exception e) { return(false); } } }
public void cadastrarRestaurante(Restaurante restaurante) { var rest = this.buscarRestaurantes().Where(r => r.id == restaurante.id).FirstOrDefault(); DbContexto db = new DbContexto(); db.restaurante.Add(restaurante); if (rest != null) { db.Entry(restaurante).State = EntityState.Modified; } db.SaveChanges(); }
public virtual TEntity GetById(int id, params Expression <Func <TEntity, object> >[] includeProperties) { using (ISession session = DbContexto.AbrirSession()) { try { return(session.Get <TEntity>(id)); } catch (Exception e) { this.AddNotification("Buscar entidade base", e.Message); return(null); } } }
public virtual List <TEntity> GetAll(params Expression <Func <TEntity, object> >[] includeProperties) { using (ISession session = DbContexto.AbrirSession()) { try { return((from e in session.Query <TEntity>() select e).ToList()); //session.Get<TEntity>(TEntity.Equals); } catch (Exception e) { this.AddNotification("Listar entidade base", e.Message); return(new List <TEntity>()); } } }
public void removerRestaurante(Restaurante restaurante) { DbContexto db = new DbContexto(); var pratos = new PratoService().buscarPratosPorRestaurante(restaurante); if (pratos != null && pratos.Count > 0) { new PratoService().removerPrato(pratos); } db.restaurante.Attach(restaurante); db.Entry(restaurante).State = EntityState.Deleted; db.SaveChanges(); }
bool IRepositorio.CadastrarAluno(Aluno aluno) { try { using (DbContexto db = new DbContexto()) { db.Alunos.Add(aluno); db.SaveChanges(); return(true); } } catch (Exception ex) { return(false); } }
bool IRepositorio.AtualizarAluno(Aluno aluno) { try { using (DbContexto db = new DbContexto()) { db.Entry(aluno).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(true); } catch (Exception ex) { return(false); } }
private void ButtonSalvar_Click(object sender, RoutedEventArgs e) { Medico m = new Medico(); m.crm = Convert.ToInt32(textBoxCrm.Text); m.especialidade = textBoxEspecialidade.Text; m.nome = textBoxNome.Text; m.telefone = textBoxTelefone.Text; if (operacao == "cadastrar") { using (DbContexto ctx = new DbContexto()) { ctx.Medicos.Add(m); ctx.SaveChanges(); } } if (operacao == "alterar") { using (DbContexto ctx = new DbContexto()) { m = ctx.Medicos.Find(Convert.ToInt32(textBoxCrm.Text)); if (m != null) { m.crm = Convert.ToInt32(textBoxCrm.Text); m.especialidade = textBoxEspecialidade.Text; m.nome = textBoxNome.Text; m.telefone = textBoxTelefone.Text; ctx.SaveChanges(); } } } if (operacao == "excluir") { using (DbContexto ctx = new DbContexto()) { m = ctx.Medicos.Find(Convert.ToInt32(textBoxCrm.Text)); ctx.Medicos.Remove(m); ctx.SaveChanges(); } } AlteraBotoes(1); LimparCampos(); ListarMedicos(); }
private void ButtonSalvar_Click(object sender, RoutedEventArgs e) { Plano p = new Plano(); p.nome = textBoxNomePlano.Text; p.razao_social = textBoxRazaoSocial.Text; p.cnpj = textBoxCNPJ.Text; p.registro_ans = textBoxANS.Text; if (operacao == "cadastrar") { using (DbContexto ctx = new DbContexto()) { ctx.Planos.Add(p); ctx.SaveChanges(); } } if (operacao == "alterar") { using (DbContexto ctx = new DbContexto()) { p = ctx.Planos.Find(Convert.ToInt32(textBoxCodigo.Text)); if (p != null) { p.nome = textBoxNomePlano.Text; p.razao_social = textBoxRazaoSocial.Text; p.cnpj = textBoxCNPJ.Text; p.registro_ans = textBoxANS.Text; ctx.SaveChanges(); } } } if (operacao == "excluir") { using (DbContexto ctx = new DbContexto()) { p = ctx.Planos.Find(Convert.ToInt32(textBoxCodigo.Text)); ctx.Planos.Remove(p); ctx.SaveChanges(); } } AlteraBotoes(1); LimparCampos(); ListarPlanos(); }