Esempio n. 1
0
        public string VerificaEmail(string email, int userid)
        {
            string response = string.Empty;

            using (var context = new ExamenOneCoreBDContext(_dbConnection))
            {
                try
                {
                    UsuarioModel usuarioModel = context.Usuario.Where(select => select.Email.Equals(email) && select.UserId != userid).FirstOrDefault();
                    if (usuarioModel != null)
                    {
                        response = !string.IsNullOrWhiteSpace(usuarioModel.Email) ? "El correo electrónico ya existe" : "Correo electrónico disponible";
                    }
                    else
                    {
                        response = "Correo electrónico disponible";
                    }
                }
                catch (Exception ex)
                {
                    response = string.Format("Error: ", ex.Message);
                }
            }
            return(response);
        }
Esempio n. 2
0
        public string Create(UsuarioModel usuarioModel)
        {
            string response = string.Empty;

            using (var context = new ExamenOneCoreBDContext(_dbConnection))
            {
                try
                {
                    context.Database.ExecuteSqlCommand("spCreateUsuario @p0, @p1, @p2, @p3, @p4", parameters: new[] {
                        usuarioModel.Username.ToString(),
                        Security.Encrypt(usuarioModel.Password.ToString()),
                        usuarioModel.Email.ToString(),
                        usuarioModel.Sexo.ToString(),
                        usuarioModel.Estatus.ToString()
                    });

                    response = string.Format("Usuario Creado");
                }
                catch (Exception ex)
                {
                    response = string.Format("Error: ", ex.Message);
                }
            }
            return(response);
        }
Esempio n. 3
0
        public string Login(LoginModel loginModel)
        {
            string response = string.Empty;

            using (var context = new ExamenOneCoreBDContext(_dbConnection))
            {
                try
                {
                    UsuarioModel usuarioModel = context.Usuario.Where(select => select.Username.Equals(loginModel.Username) && select.Password.Equals(Security.Encrypt(loginModel.Password.ToString()))).FirstOrDefault();
                    if (usuarioModel != null)
                    {
                        if (usuarioModel.UserId > byte.MinValue)
                        {
                            response = string.Format("OK");
                        }
                        else
                        {
                            response = string.Format("FAIL");
                        }
                    }
                    else
                    {
                        response = string.Format("FAIL");
                    }
                }
                catch (Exception ex)
                {
                    response = string.Format("FAIL");
                }
            }
            return(response);
        }
Esempio n. 4
0
        public List <UsuarioModel> GetUsuariosActivos()
        {
            List <UsuarioModel> usersList = new List <UsuarioModel>();

            using (var context = new ExamenOneCoreBDContext(_dbConnection))
            {
                usersList = context.Usuario.ToList();
            }

            return(usersList);
        }
Esempio n. 5
0
        public UsuarioModel GetUsuario(int userId)
        {
            UsuarioModel response = new UsuarioModel();

            using (var context = new ExamenOneCoreBDContext(_dbConnection))
            {
                try
                {
                    response = context.Usuario.Where(select => select.UserId == userId).FirstOrDefault();
                }
                catch (Exception)
                {
                    response = new UsuarioModel();
                }
            }
            return(response);
        }
Esempio n. 6
0
        public string Delete(int userId)
        {
            string response = string.Empty;

            using (var context = new ExamenOneCoreBDContext(_dbConnection))
            {
                try
                {
                    UsuarioModel usuarioModel = context.Usuario.Where(select => select.UserId == userId).FirstOrDefault();
                    usuarioModel.Estatus            = false;
                    usuarioModel.FechaActualizacion = DateTime.Now;
                    context.Update <UsuarioModel>(usuarioModel);
                    context.SaveChanges();
                    response = string.Format("Usuario Eliminado");
                }
                catch (Exception ex)
                {
                    response = string.Format("Error: ", ex.Message);
                }
            }
            return(response);
        }
Esempio n. 7
0
        public string UpdatePassword(ChangePasswordModel changePasswordModel)
        {
            string response = string.Empty;

            using (var context = new ExamenOneCoreBDContext(_dbConnection))
            {
                try
                {
                    context.Database.ExecuteSqlCommand("spUpdatePassword @p0, @p1", parameters: new[] {
                        changePasswordModel.UserId.ToString(),
                        Security.Encrypt(changePasswordModel.Password.ToString())
                    });

                    response = string.Format("Contraseña Actualizada");
                }
                catch (Exception ex)
                {
                    response = string.Format("Error: ", ex.Message);
                }
            }
            return(response);
        }