// GET: api/Empleados/5 public Empleado Get(int id) { using (GafetesEntities db = new GafetesEntities()) { return(db.Empleados.FirstOrDefault(d => d.Id == id)); } }
// PUT: api/Empleados/5 public HttpResponseMessage Put([FromBody] Empleado emp) { int resp = 0; HttpResponseMessage msg = null; try { using (GafetesEntities db = new GafetesEntities()) { db.Entry(emp).State = EntityState.Modified; resp = db.SaveChanges(); msg = Request.CreateErrorResponse(HttpStatusCode.OK, "Actualizado con exito"); } } catch (Exception ex) { msg = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } return(msg); }
// GET: api/Empleados public IEnumerable <Empleado> Get() { using (GafetesEntities db = new GafetesEntities()) { return(db.Empleados.ToList()); /* * switch (img) { * case "no": * return db.Empleados.Select(x => new Empleado { * Id = x.Id, * Nombre = x.Nombre, * Direccion = x.Direccion, * Telefono = x.Telefono, * Curp = x.Telefono, * Imagen = (x.Imagen != null) ? "1" : "0" * }); * case "thumbs": * return db.Empleados.Select(x => new Empleado * { * Id = x.Id, * Nombre = x.Nombre, * Direccion = x.Direccion, * Telefono = x.Telefono, * Curp = x.Telefono, * Imagen = x.Imagen //convert to Thumbnails * }); * default: * return db.Empleados.Select(x => new Empleado * { * Id = x.Id, * Nombre = x.Nombre, * Direccion = x.Direccion, * Telefono = x.Telefono, * Curp = x.Telefono, * Imagen = (x.Imagen != null) ? "1" : "0" * }); * }*/ } //return new string[] { "value1", "value2" }; }
// DELETE: api/Empleados/5 public HttpResponseMessage Delete(int id) { int resp = 0; HttpResponseMessage msg = null; try { using (GafetesEntities db = new GafetesEntities()) { Empleado emp = db.Empleados.FirstOrDefault(x => x.Id == id); db.Entry(emp).State = EntityState.Deleted; resp = db.SaveChanges(); msg = Request.CreateErrorResponse(HttpStatusCode.OK, "Eliminado con exito"); } } catch (Exception ex) { msg = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } return(msg); }