Ejemplo n.º 1
0
        public ActionResult Create(Models.ViewModel.EmpleadosViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (PruebaEntities DTB = new PruebaEntities())
                    {
                        /**/
                        int total  = DTB.Empleados.Count();
                        var oTabla = new Empleados();
                        oTabla.ID_Empleado = total + 1;
                        oTabla.Nombre      = model.Nombre;
                        oTabla.Apellido    = model.Apellido;
                        oTabla.Telefono    = model.Telefono;
                        oTabla.Correo      = model.Correo;
                        oTabla.ID_Estado   = model.ID_Estado;
                        //if (DTB.Estados.Where(d => d.ID_Estado == model.ID_Estado).Count() > 0)
                        //{

                        //}
                        db.Empleados.Add(oTabla);

                        db.SaveChanges();
                    }

                    return(RedirectToAction("Index"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public ActionResult Create(Models.ViewModel.EstadosViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (PruebaEntities DTB = new PruebaEntities())
                    {
                        /**/
                        var oTabla = new Estados();
                        oTabla.ID_Estado = model.ID_Estado;
                        oTabla.Estado    = model.Estado;
                        if (DTB.Estados.Where(d => d.ID_Estado == model.ID_Estado).Count() > 0)
                        {
                        }
                        db.Estados.Add(oTabla);

                        db.SaveChanges();
                    }

                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }
            catch (Exception ex) {
                throw new Exception(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Nombre,Apellido,Cedula")] Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                db.Cliente.Add(cliente);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cliente));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "Numero_cuenta,Cedula,Fecha_apertura,Monto")] CuentaBancaria cuentaBancaria)
        {
            if (ModelState.IsValid)
            {
                db.CuentaBancaria.Add(cuentaBancaria);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Cedula = new SelectList(db.Cliente, "Cedula", "Nombre", cuentaBancaria.Cedula);
            return(View(cuentaBancaria));
        }
Ejemplo n.º 5
0
        // GET: Cliente
        public JsonResult AddCliente(ClienteDTO cliente)
        {
            var response = new Response <Clientes>();

            try
            {
                Clientes cli = new Clientes();
                cli.Cedula      = cliente.Cedula;
                cli.Nombre      = cliente.Nombre;
                cli.Email       = cliente.Email;
                cli.Telefono    = cliente.Telefono;
                cli.Provincia   = cliente.Provincia;
                cli.Municipio   = cliente.Municipio;
                cli.RNC         = cliente.RNC;
                cli.RazonSocial = cliente.RazonSocial;
                cli.Posicion    = cliente.Posicion;
                cli.Comentarios = cliente.Comentarios;

                dbc.Entry(cli).State = System.Data.Entity.EntityState.Added;
                dbc.SaveChanges();
                if (cliente.file != null)
                {
                    foreach (var file in cliente.file)
                    {
                        MemoryStream target = new MemoryStream();
                        file.InputStream.CopyTo(target);
                        byte[]         data    = target.ToArray();
                        AdjuntoCliente adjunto = new AdjuntoCliente();
                        adjunto.Clientes = cli;
                        adjunto.Adjunto  = data;

                        dbc.Entry(adjunto).State = System.Data.Entity.EntityState.Added;
                        dbc.SaveChanges();
                    }
                }

                response.Success = true;
            }
            catch (Exception e)
            {
                var response2 = new Response <Exception>();
                response2.Success = false;
                response2.Data    = e;
                return(Json(e, JsonRequestBehavior.AllowGet));
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        public void agregarUsuario(int id, string nombreC, string nacimiento, string contraseña, byte[] foto, string correo, int telefono)
        {
            contraseña = encriptarDatos(contraseña);

            TBL_USUARIOS usuario = new TBL_USUARIOS();

            usuario.Identificacion   = id;
            usuario.Nombre_Completo  = nombreC;
            usuario.Fecha_Nacimiento = nacimiento;
            usuario.Contraseña       = contraseña;
            usuario.Foto             = foto;
            usuario.Correo           = correo;
            usuario.Telefono         = telefono;

            modeloBD.TBL_USUARIOS.Add(usuario);
            modeloBD.SaveChanges();
        }
Ejemplo n.º 7
0
        public ActionResult Eliminar(int Id)
        {
            using (PruebaEntities db = new PruebaEntities())
            {
                var oCrud = db.crud.Find(Id);
                db.crud.Remove(oCrud);
                db.SaveChanges();
            }

            return(Redirect("~/Crud/"));
        }
Ejemplo n.º 8
0
        public string GuardarFactura(Entidades.Factura.Factura Factura, List <Entidades.Factura.DetalleFactura> ListDetalleFactura)
        {
            string resultado = "";

            try
            {
                using (var bd = new PruebaEntities())
                {
                    //var dos = bd.Factura;
                    using (var tran = new TransactionScope())
                    {
                        //dos.Add(Factura);
                        //var uno = bd.Factura;
                        //uno.Add(Factura);
                        bd.Factura.Add(Factura);
                        bd.SaveChanges();

                        ListDetalleFactura.ForEach(n =>
                        {
                            n.IdFactura = Factura.Id;
                            bd.DetalleFactura.Add(n);
                        });

                        bd.SaveChanges();

                        //tran.Dispose();

                        tran.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                resultado = "Error: " + ex.Message;
            }

            return(resultado);
        }
Ejemplo n.º 9
0
        public Reply Agregar([FromBody] TareaViewModel modelo)
        {
            Reply oR = new Reply();

            oR.result = 0;

            if (!Verify(modelo.token))
            {
                oR.message = " No autorizado";
                return(oR);
            }

            //validaciones
            if (!Validate(modelo))
            {
                oR.message = error;
                return(oR);
            }

            try
            {
                using (PruebaEntities db = new PruebaEntities())
                {
                    Tarea oTarea = new Tarea();
                    oTarea.estado      = false;
                    oTarea.Nombre      = modelo.nombre;
                    oTarea.descripcion = modelo.descripcion;

                    db.Tarea.Add(oTarea);
                    db.SaveChanges();

                    List <ListTareasViewModel> lst = (from d in db.Tarea
                                                      select new ListTareasViewModel
                    {
                        nombre = d.Nombre,
                        descripcion = d.descripcion
                    }).ToList();

                    oR.result = 1;
                    oR.data   = lst;
                }
            }
            catch (Exception ex)
            {
                oR.message = "Ocurrio el siguiente error:" + ex.ToString();
                throw;
            }

            return(oR);
        }
Ejemplo n.º 10
0
        public Reply Edit([FromBody] TareaViewModel modelo)
        {
            Reply oR = new Reply();

            oR.result = 0;

            if (!Verify(modelo.token))
            {
                oR.message = " No autorizado";
                return(oR);
            }

            //validaciones
            if (!Validate(modelo))
            {
                oR.message = error;
                return(oR);
            }

            try
            {
                using (PruebaEntities db = new PruebaEntities())
                {
                    Tarea oTarea = db.Tarea.Find(modelo.Id);
                    oTarea.estado = modelo.estado;

                    db.Entry(oTarea).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    List <ListTareasViewModel> lst = (from d in db.Tarea
                                                      select new ListTareasViewModel
                    {
                        nombre = d.Nombre,
                        descripcion = d.descripcion
                    }).ToList();

                    oR.result = 1;
                    oR.data   = lst;
                }
            }
            catch (Exception ex)
            {
                oR.message = "Ocurrio el siguiente error:" + ex.ToString();
                throw;
            }

            return(oR);
        }
Ejemplo n.º 11
0
        public Reply Agregar([FromBody] UsuarioViewModel modelo)
        {
            Reply oR = new Reply();

            oR.result = 0;


            //validaciones
            if (!Validate(modelo))
            {
                oR.message = error;
                return(oR);
            }

            try
            {
                using (PruebaEntities db = new PruebaEntities())
                {
                    Usuario oUser = new Usuario();
                    oUser.nombre   = modelo.nombre;
                    oUser.username = modelo.username;
                    oUser.password = modelo.password;


                    db.Usuario.Add(oUser);
                    db.SaveChanges();

                    List <ListUsuarioViewModel> lst = (from d in db.Usuario
                                                       select new ListUsuarioViewModel
                    {
                        nombre = d.nombre,
                        username = d.username
                    }).ToList();

                    oR.result = 1;
                    oR.data   = lst;
                }
            }
            catch (Exception ex)
            {
                oR.message = "Ocurrio el siguiente error:" + ex.ToString();
                throw;
            }

            return(oR);
        }
Ejemplo n.º 12
0
        public ActionResult Editar(CrudViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (PruebaEntities db = new PruebaEntities())
                {
                    var oCrud = db.crud.Find(model.Id);
                    oCrud.Id               = model.Id;
                    oCrud.Nombre           = model.Nombre;
                    oCrud.Correo           = model.Correo;
                    oCrud.Fecha_nacimiento = model.Fecha_Nacimiento;

                    db.Entry(oCrud).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                return(Redirect("~/Crud/"));
            }

            return(View(model));
        }
Ejemplo n.º 13
0
        public ActionResult Nuevo(CrudViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (PruebaEntities db = new PruebaEntities())
                {
                    var oCrud = new crud();
                    oCrud.Id               = model.Id;
                    oCrud.Nombre           = model.Nombre;
                    oCrud.Correo           = model.Correo;
                    oCrud.Fecha_nacimiento = model.Fecha_Nacimiento;

                    db.crud.Add(oCrud);
                    db.SaveChanges();
                }
                return(Redirect("~/Crud/"));
            }

            return(View(model));
        }
Ejemplo n.º 14
0
        public Reply Login([FromBody] AccessViewModel model)
        {
            Reply oR = new Reply();

            oR.result = 0;
            try
            {
                using (PruebaEntities db = new PruebaEntities())
                {
                    var lst = db.Usuario.Where(d => d.username == model.username && d.password == model.password);

                    if (lst.Count() > 0)
                    {
                        oR.result = 1;
                        oR.data   = Guid.NewGuid().ToString();

                        Usuario oUser = lst.First();
                        oUser.token = (string)oR.data;

                        db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        oR.message = "Credenciales Erroneas";
                    }
                }
            }
            catch (Exception ex)
            {
                oR.result  = 0;
                oR.message = " Ocurrió un error!";
            }

            return(oR);
        }
Ejemplo n.º 15
0
        protected void Guardar_Onclick(object sender, EventArgs e)
        {
            string     path = @"C:\Users\kevin\OneDrive\Escritorio\Importar-Excel-aspx\archivoexcelparasubir\miexcel.xlsx";//direccion del archivos para que cargue los datos en la base
            SLDocument sl   = new SLDocument(path);

            using (var db = new PruebaEntities())
            {
                int iRow = 2;
                while (!string.IsNullOrEmpty(sl.GetCellValueAsString(iRow, 1)))
                {
                    int    codigo  = sl.GetCellValueAsInt32(iRow, 1);
                    string nombre  = sl.GetCellValueAsString(iRow, 2);
                    int    edad    = sl.GetCellValueAsInt32(iRow, 3);
                    var    Persona = new Persona();
                    Persona.codigo = codigo;
                    Persona.nombre = nombre;
                    Persona.edad   = edad;
                    db.Persona.Add(Persona);
                    db.SaveChanges();
                    iRow++;
                    Lbl_Mensaje.Text = "Datos Guardados Exitosamente";
                }
            }
        }