Esempio n. 1
0
        public ActionResult Cadastro([Bind(Include = "Id,Nome,Login,Senha,ConfirmacaoSenha")] Usuario usuario)
        {
            if (ModelState.IsValid || (usuario.Id > 0 && !string.IsNullOrWhiteSpace(usuario.Nome)))
            {
                if (usuario.Id > 0)
                {
                    // a única alteração que poderemos fazer no usuário é o nome dele
                    // a alteração da senha será em uma tela separada, específica
                    // este tbm é um exemplo de como alterar um registro usando SQL direto

                    var sql = string.Format("UPDATE Usuario SET Nome = '{0}' WHERE Id = {1}", usuario.Nome, usuario.Id);

                    db.Database.ExecuteSqlCommand(sql);
                }
                else
                {
                    db.Usuario.Add(usuario);
                }

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(usuario));
        }
Esempio n. 2
0
        public IHttpActionResult PutEstiloCerveja(int id, EstiloCerveja estiloCerveja)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != estiloCerveja.IDEstilo)
            {
                return(BadRequest());
            }

            db.Entry(estiloCerveja).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EstiloCervejaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "Id,Nombre")] Universidad universidad)
        {
            if (ModelState.IsValid)
            {
                db.Universidades.Add(universidad);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(universidad));
        }
Esempio n. 4
0
        public ActionResult Create([Bind(Include = "Id,Nombre")] Carrera carrera)
        {
            if (ModelState.IsValid)
            {
                db.Carreras.Add(carrera);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(carrera));
        }
Esempio n. 5
0
        public ActionResult Entrar()
        {
            var usuarioTarefaModel = new UsuariosTarefasModel
            {
                NomeCompleto = User.GetFullName(),
                Apelido      = User.GetNickName(),
                Email        = User.GetEmail()
            };

            db.Usuarios.Add(usuarioTarefaModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "Id,Nombre,Apellido,UniversidadID,CarreraId,Email,Telefono,Celular")] Profesor profesor)
        {
            if (ModelState.IsValid)
            {
                db.Profesores.Add(profesor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CarreraId     = new SelectList(db.Carreras, "Id", "Nombre", profesor.CarreraId);
            ViewBag.UniversidadID = new SelectList(db.Universidades, "Id", "Nombre", profesor.UniversidadID);
            return(View(profesor));
        }
Esempio n. 7
0
        /// <summary>
        /// Edita um registro de Pessoa com o ID
        /// </summary>
        /// <param name="id"></param>
        /// <param name="nome"></param>
        /// <param name="idade"></param>
        public Pessoa EditPessoas(int id, string nome = "", int idade = 0)
        {
            using (ContextoDB contexto = new ContextoDB())
            {
                try
                {
                    var filteredPerson = contexto.Pessoas
                                         .Single(i => i.ID_PESSOA == id);

                    if (nome == string.Empty)
                    {
                        filteredPerson.IDADE_PESSOA = idade;
                    }

                    contexto.SaveChanges();

                    Console.WriteLine($"Nome: {filteredPerson.NOME_PESSOA} e idade {filteredPerson.IDADE_PESSOA}");

                    return(filteredPerson);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Mensagem de erro: {e.Message}");
                    throw;
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Adiciona uma pessoa ao banco de dados.
        /// </summary>
        /// <param name="nome"></param>
        /// <param name="idade"></param>
        public void AddPessoas(string nome, int idade)
        {
            try
            {
                using (ContextoDB contexto = new ContextoDB())
                {
                    Pessoa pessoa1 = new Pessoa()
                    {
                        NOME_PESSOA  = nome,
                        IDADE_PESSOA = idade,
                        DATA_CRIADA  = DateTime.Now
                    };

                    contexto.Add(pessoa1);
                    contexto.SaveChanges();

                    Console.WriteLine("Pessoa adicionada com sucesso.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Mensagem de erro: {e}");
                throw;
            }
        }
Esempio n. 9
0
        public bool Salvar()
        {
            var ret   = 0;
            var model = ConsultarPeloId(this.PessoaId);

            using (var db = new ContextoDB())
            {
                if (this.Estado != null)
                {
                    this.EstadoId = this.Estado.Id;
                    this.Estado   = null;
                }

                if (this.Pessoa != null)
                {
                    this.PessoaId = this.Pessoa.Id;
                    this.Pessoa   = null;
                }

                if (model == null)
                {
                    db.EnderecoMap.Add(this);
                }
                else
                {
                    db.EnderecoMap.Attach(this);
                    db.Entry(this).State = EntityState.Modified;
                }

                db.SaveChanges();
                ret = this.Id;
            }
            return(!(ret == 0));
        }
Esempio n. 10
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            using (ContextoDB db = new ContextoDB())
            {
                var persona = new Persona()
                {
                    Nombre = txtNombre.Text, Apellido = txtApellido.Text, Cedula = txtCedula.Text, direccion = txtDireccion.Text, Edad = fechaNacimiento.Value, Telefono = txtTelefono.Text
                };

                var usuario = new Usuarios()
                {
                    NombreUsuario = txtUsuario.Text, Contraseña = txtContra.Text
                };


                db.usuarios.Add(usuario);
                db.Personas.Add(persona);
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException es)
                {
                    MessageBox.Show("" + es.Message);
                }
            }
        }
Esempio n. 11
0
 public JsonResult PessoaADD([System.Web.Http.FromBody] Pessoa pessoa)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Pessoas.Add(pessoa);
             db.SaveChanges();
             return(Json(new { Sucess = true }));
         }
         return(Json(new { Sucess = false }));
     }
     catch (Exception)
     {
         return(Json(new { Sucess = false }));
     }
 }
 public virtual void Actualizar(T obj)
 {
     using (var db = new ContextoDB())
     {
         db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
 public override void Eliminar(Zona zona)
 {
     using (var db = new ContextoDB())
     {
         db.Zonas.Remove(zona);
         db.SaveChanges();
     }
 }
Esempio n. 14
0
 public static int salvar(Ponto ponto)
 {
     using (var db = new ContextoDB())
     {
         db.Pontos.Add(ponto);
         return(db.SaveChanges());
     }
 }
Esempio n. 15
0
 public override void Eliminar(Cliente cliente)
 {
     using (var db = new ContextoDB())
     {
         var result = db.Clientes.Find(cliente.Cedula);
         result.Estado = false;
         db.SaveChanges();
     }
 }
Esempio n. 16
0
        public ActionResult Cadastro(TipoEspaco tipoEspaco)
        {
            if (ModelState.IsValid)
            {
                if (tipoEspaco.Id > 0)
                {
                    db.Entry(tipoEspaco).State = EntityState.Modified;
                }
                else
                {
                    db.TipoEspaco.Add(tipoEspaco);
                }

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(tipoEspaco));
        }
Esempio n. 17
0
        public ActionResult Cadastro(FormaPagamento formaPagamento)
        {
            if (ModelState.IsValid)
            {
                if (formaPagamento.Id > 0)
                {
                    db.Entry(formaPagamento).State = EntityState.Modified;
                }
                else
                {
                    db.FormaPagamento.Add(formaPagamento);
                }

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(formaPagamento));
        }
Esempio n. 18
0
        public ActionResult Cadastro(PJ PJ)
        {
            if (ModelState.IsValid)
            {
                if (PJ.Id > 0)
                {
                    _db.Entry(PJ).State = EntityState.Modified;
                }
                else
                {
                    _db.PJ.Add(PJ);
                }

                _db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(PJ));
        }
Esempio n. 19
0
        public IActionResult CrearCita([FromBody] CitaDto citaDto)
        {
            var cita = new Cita();

            cita.Fecha    = citaDto.Fecha;
            cita.Medico   = citaDto.Medico;
            cita.Paciente = citaDto.Paciente;

            _contexto.Citas.Add(cita);
            _contexto.SaveChanges();

            return(Ok());
        }
Esempio n. 20
0
 public void Insertar(ASIENTO_EVENTO P)
 {
     try
     {
         ContextoDB ct = new ContextoDB();
         ct.ASIENTO_EVENTO.Add(P);
         ct.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 21
0
        public RetornoGlobal <CatalogProjeto> Post(CreateCatalogProjeto parameter)
        {
            RetornoGlobal <CatalogProjeto> retorno = new RetornoGlobal <CatalogProjeto>();

            try
            {
                CreateCatalogValidator validator = new CreateCatalogValidator(contexto);
                var result = validator.Validate(parameter);

                if (result.IsValid)
                {
                    CatalogProjeto objetoMontado = new CatalogProjeto();
                    objetoMontado.nome_projeto    = parameter.nome_projeto;
                    objetoMontado.img_thumbnail   = parameter.img_thumbnail;
                    objetoMontado.descritivo_capa = parameter.descritivo_capa;
                    objetoMontado.texto_projeto   = parameter.texto_projeto;
                    objetoMontado.ListaFotos      = parameter.ListaFotos;

                    contexto.TabelaCatalogProjeto.Add(objetoMontado);
                    contexto.SaveChanges();
                    retorno.status        = true;
                    retorno.RetornoObjeto = objetoMontado;
                }
                else
                {
                    retorno.status = false;
                    result.Errors.ToList().ForEach(r =>
                                                   retorno.errors.Add(r.ToString())
                                                   );
                }
            }
            catch (Exception e) {
                retorno.status = false;
                retorno.errors.Append(e.Message);
                retorno.errors.Append(e.InnerException.ToString());
            }

            return(retorno);
        }
Esempio n. 22
0
 public void Insertar(DETALLE_VENTA P)
 {
     try
     {
         ContextoDB ct = new ContextoDB();
         ct.DETALLE_VENTA.Add(P);
         ct.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 23
0
 public static bool excluirPeloId(int id)
 {
     using (var db = new ContextoDB())
     {
         var ponto = new Ponto {
             Id = id
         };
         db.Pontos.Attach(ponto);
         db.Entry(ponto).State = EntityState.Deleted;
         db.SaveChanges();
         return(true);
     }
 }
Esempio n. 24
0
        public RetornoGlobal <UsuariosModel> postLogin(CreateLoginCommand login)
        {
            RetornoGlobal <UsuariosModel> retorno = new RetornoGlobal <UsuariosModel>();

            try
            {
                CreateLoginValidator validator = new CreateLoginValidator(contexto);

                ValidationResult result = validator.Validate(login);
                if (result.IsValid)
                {
                    UsuariosModel model = new UsuariosModel();
                    model.Login           = login.Login;
                    model.Senha           = login.Senha;
                    model.UsuarioAcessoId = login.UsuarioAcessoId;

                    contexto.TabelaUsuarios.Add(model);
                    contexto.SaveChanges();

                    retorno.status        = true;
                    retorno.RetornoObjeto = model;
                }
                else
                {
                    retorno.status = false;
                    result.Errors.ToList().ForEach(r =>
                                                   retorno.errors.Add(r.ToString())
                                                   );
                }
            }
            catch (Exception e)
            {
                retorno.errors.Append(e.Message);
                retorno.errors.Append(e.InnerException.ToString());
                retorno.status = false;
            }
            return(retorno);
        }
 public virtual void Agregar(T obj)
 {
     using (var db = new ContextoDB())
     {
         try
         {
             db.Entry(obj).State = System.Data.Entity.EntityState.Added;
             db.SaveChanges();
         }catch (DbEntityValidationException e)
         {
             Console.WriteLine(e.Message);
         }
     }
 }
Esempio n. 26
0
        public ActionResult Cadastro(Agendamento agendamento, int tipoCliente)
        {
            if (ModelState.IsValid)
            {
                if (agendamento.Id > 0)
                {
                    db.Entry(agendamento).State = EntityState.Modified;
                }
                else
                {
                    db.Agendamento.Add(agendamento);
                }

                db.SaveChanges();

                return(RedirectToAction("Index", new { id = tipoCliente == 1 ? agendamento.PFId : agendamento.PJId, tipoCliente = tipoCliente }));
            }

            ViewBag.ClientId    = tipoCliente == 1 ? agendamento.PFId : agendamento.PJId;
            ViewBag.TipoCliente = tipoCliente;

            return(View(agendamento));
        }
Esempio n. 27
0
 public int Insertar(EVENTO P)
 {
     try
     {
         ContextoDB ct = new ContextoDB();
         ct.EVENTO.Add(P);
         ct.SaveChanges();
         return(P.CEvento);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 28
0
 public int Insertar(TIPO_ASIENTO P)
 {
     try
     {
         ContextoDB ct = new ContextoDB();
         ct.TIPO_ASIENTO.Add(P);
         ct.SaveChanges();
         return(P.CTipoAsiento);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 29
0
 public int Insertar(USUARIO P)
 {
     try
     {
         ContextoDB ct = new ContextoDB();
         ct.USUARIO.Add(P);
         ct.SaveChanges();
         return(P.CUsuario);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 30
0
 public int Insertar(TIPOEMPLEADO P)
 {
     try
     {
         ContextoDB ct = new ContextoDB();
         ct.TIPOEMPLEADO.Add(P);
         ct.SaveChanges();
         return(P.CTipoEmpleado);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }