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); } }
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/")); }
public bool Verify(string token) { using (PruebaEntities db = new PruebaEntities()) { if (db.Usuario.Where(d => d.token == token).Count() > 0) { return(true); } } return(false); }
public Servicio() { //int[] valores = {10,20,30,40,50 }; //cantidad = valores.Count(x => x >= 30); using (var context = new PruebaEntities()) { lista_clientes = (from cli in context.clientes // where st.StudentName == "Bill" select cli).ToList(); } }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { using (PruebaEntities db = new PruebaEntities()) { int sEstado = (int)value; if (db.Estados.Where(d => d.ID_Estado == sEstado).Count() > 0) { return(new ValidationResult("Estado ya Existe")); } } return(ValidationResult.Success); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { using (PruebaEntities db = new PruebaEntities()) { string sCorreo = (string)value; if (db.Empleados.Where(d => d.Correo == sCorreo).Count() > 0) { return(new ValidationResult("Usuario ya Existe")); } } return(ValidationResult.Success); }
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); }
public ActionResult Editar(int Id) { CrudViewModel model = new CrudViewModel(); using (PruebaEntities db = new PruebaEntities()) { var oCrud = db.crud.Find(Id); model.Nombre = oCrud.Nombre; model.Correo = oCrud.Correo; model.Fecha_Nacimiento = oCrud.Fecha_nacimiento; model.Id = oCrud.Id; } return(View(model)); }
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); }
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); }
public List <Entidades.Factura.Factura> GetFactura() { List <Entidades.Factura.Factura> ListFactura = new List <Entidades.Factura.Factura>(); try { using (var bd = new PruebaEntities()) { ListFactura = bd.Factura.ToList(); } } catch (Exception ex) { } return(ListFactura); }
//// GET: Crud public ActionResult index() { List <ListCrudViewModel> lst; using (PruebaEntities db = new PruebaEntities()) { lst = (from d in db.crud select new ListCrudViewModel { Id = d.Id, Nombre = d.Nombre, Correo = d.Correo }).ToList(); //lst = db.crud.select(c => new listcrudviewmodel() { correo = c.correo, id = c.id, nombre = c.nombre }).tolist(); } return(View(lst)); }
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)); }
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)); }
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); }
public Reply Get([FromBody] SecurityViewModel model) { Reply oR = new Reply(); oR.result = 0; if (!Verify(model.token)) { oR.message = " No autorizado"; return(oR); } try { using (PruebaEntities db = new PruebaEntities()) { List <ListUsuarioViewModel> lst = (from d in db.Usuario select new ListUsuarioViewModel { nombre = d.nombre, username = d.username }).ToList(); oR.data = lst; oR.result = 1; } } catch (Exception ex) { oR.message = "ocurrio el siguiente error" + ex.ToString(); throw; } return(oR); }
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"; } } }
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); }
// GET: Persona public ClienteController() { dbc = new PruebaEntities(); }
public UserTripsData() { _context = new PruebaEntities(); }
public OwnerService() { Context = new PruebaEntities(); }