Exemplo n.º 1
0
        public HttpResponseMessage Post(UserBaseCLS userbaseCLS)
        {
            try
            {
                using (steujedo_sindicatoEntities db = new steujedo_sindicatoEntities())
                {
                    User_Base userbase = new User_Base();
                    userbase.ub_user   = userbaseCLS.ub_user;
                    userbase.ub_nombre = userbaseCLS.ub_nombre;
                    userbase.ub_curp   = userbaseCLS.ub_curp;
                    userbase.ub_rfc    = userbaseCLS.ub_rfc;
                    SHA256Managed sha               = new SHA256Managed();
                    byte[]        byteContra        = Encoding.Default.GetBytes(userbaseCLS.ub_password);
                    byte[]        byteContraCifrado = sha.ComputeHash(byteContra);
                    string        contraCifrada     = BitConverter.ToString(byteContraCifrado).Replace("-", "");
                    userbase.ub_password = contraCifrada;
                    int persona = db.Database.SqlQuery <int>("select count(*) from steujedo_sindicato.User_Base where ub_user="******"El usuario ya se encuentra registrado.");

                        return(Mensaje);
                    }
                    else
                    {
                        db.User_Base.Add(userbase);
                        db.SaveChanges();
                        var Mensaje = Request.CreateResponse(HttpStatusCode.Created, userbase);
                        return(Mensaje);
                    }
                    //var user = db.User_Base.FirstOrDefault(x => x.ub_user == userbaseCLS.ub_user && x.ub_password== userbase.ub_password);
                    //if (user != null)
                    //{


                    //}
                    //else
                    //{


                    //}
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage PutBaseUser(string user, UserBaseCLS userCLS)
        {
            try
            {
                user = userCLS.ub_user;
                using (steujedo_sindicatoEntities db = new steujedo_sindicatoEntities())
                {
                    User_Base usuarios = new User_Base();
                    usuarios = db.User_Base.Where(p => p.ub_user.Equals(user)).First();
                    if (usuarios == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Trabajador con ID " + user.ToString() + " no encontrado"));
                    }
                    else
                    {
                        if (userCLS.ub_password != null && userCLS.ub_password != "")
                        {
                            usuarios.ub_nombre = userCLS.ub_nombre;
                            usuarios.ub_curp   = userCLS.ub_curp;
                            usuarios.ub_rfc    = userCLS.ub_rfc;
                            SHA256Managed sha               = new SHA256Managed();
                            byte[]        byteContra        = Encoding.Default.GetBytes(userCLS.ub_password);
                            byte[]        byteContraCifrado = sha.ComputeHash(byteContra);
                            string        contraCifrada     = BitConverter.ToString(byteContraCifrado).Replace("-", "");
                            usuarios.ub_password = contraCifrada;

                            db.SaveChanges();
                            return(Request.CreateResponse(HttpStatusCode.OK));
                        }
                        else
                        {
                            usuarios.ub_nombre = userCLS.ub_nombre;
                            usuarios.ub_curp   = userCLS.ub_curp;
                            usuarios.ub_rfc    = userCLS.ub_rfc;
                            db.SaveChanges();
                            return(Request.CreateResponse(HttpStatusCode.OK));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemplo n.º 3
0
 public HttpResponseMessage Updatepass([FromUri] string user, [FromUri] string pass)
 {
     try
     {
         using (steujedo_sindicatoEntities db = new steujedo_sindicatoEntities())
         {
             string contraCifrada = "";
             Console.WriteLine(user);
             Console.WriteLine(pass);
             if (pass != null)
             {
                 SHA256Managed sha               = new SHA256Managed();
                 byte[]        byteContra        = Encoding.Default.GetBytes(pass);
                 byte[]        byteContraCifrado = sha.ComputeHash(byteContra);
                 contraCifrada = BitConverter.ToString(byteContraCifrado).Replace("-", "");
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Falta  Ingresar password  " + pass));
             }
             User_Base usuario = new User_Base();
             usuario = db.User_Base.FirstOrDefault(e => e.ub_user == user);
             if (usuario == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Trabajador con ID " + user.ToString() + " no encontrado"));
             }
             else
             {
                 usuario.ub_password = contraCifrada;
                 db.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }