Пример #1
0
 // GET: api/Empleados/5
 public Empleado Get(int id)
 {
     using (GafetesEntities db = new GafetesEntities())
     {
         return(db.Empleados.FirstOrDefault(d => d.Id == id));
     }
 }
Пример #2
0
        // 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);
        }
Пример #3
0
        // 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" };
        }
Пример #4
0
        // 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);
        }