Exemplo n.º 1
0
        public Task <int> Login(Login data)
        {
            try
            {
                Task <int> result;
                using (var conn = _settings.GetConnection())
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    var query = $"Select dbo.LOGIN(N'{data.Username}', N'{data.Password}');";
                    using (var cmd = new SqlCommand(query, conn))
                    {
                        result = Task.FromResult((int)cmd.ExecuteScalar());
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Task.FromResult(-4));
            }
        }
Exemplo n.º 2
0
        public Task <bool> DeleteProductPrice(int priceId)
        {
            try
            {
                using (var conn = _settings.GetConnection())
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    using (var cmd = new SqlCommand("ELIMINA_PRECIO", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@PRECIO", SqlDbType.Int).Value = priceId;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
                return(Task.FromResult(true));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Task.FromResult(false));
            }
        }
Exemplo n.º 3
0
        public Task <bool?> ExistTransacction(string transactionId)
        {
            try
            {
                Task <bool?> result;
                using (var conn = _settings.GetConnection())
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    var query = $"Select dbo.EXISTE_TRANSACCION(N'{transactionId}');";
                    using (var cmd = new SqlCommand(query, conn))
                    {
                        result = Task.FromResult((bool?)cmd.ExecuteScalar());
                    }
                }
                return(result);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public Task <DataSet> TotalUsers()
        {
            try
            {
                DataSet ds = new DataSet();
                using (var conn = _settings.GetConnection())
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    string query = $@"SELECT * FROM V_ADMINISTRADORES;";
                    using (var cmd = new SqlCommand(query, conn))
                    {
                        using (var adapter = new SqlDataAdapter(cmd))
                        {
                            adapter.Fill(ds);
                        }
                    }
                }
                return(Task.FromResult(ds));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        public Task <bool> Register(Register register)
        {
            try
            {
                using (var conn = _settings.GetConnection())
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    using (var cmd = new SqlCommand("REGISTRO", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@USUARIO", SqlDbType.NVarChar).Value   = register.Username;
                        cmd.Parameters.Add("@CLAVE", SqlDbType.NVarChar).Value     = register.Password;
                        cmd.Parameters.Add("@PREGUNTA", SqlDbType.Int).Value       = register.Question;
                        cmd.Parameters.Add("@RESPUESTA", SqlDbType.NVarChar).Value = register.Answer;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
                return(Task.FromResult(true));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Task.FromResult(false));
            }
        }
Exemplo n.º 6
0
        public Task <bool> UpdateUserStatus(UserStatus userStatus)
        {
            try
            {
                using (var conn = _settings.GetConnection())
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    using (var cmd = new SqlCommand("ACTUALIZA_ESTADO_ADMINISTRADOR", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@USUARIO", SqlDbType.NVarChar).Value = userStatus.Username;
                        cmd.Parameters.Add("@ESTADO", SqlDbType.Bit).Value       = userStatus.NewStatus;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
                return(Task.FromResult(true));
            }
            catch (Exception)
            {
                return(Task.FromResult(false));
            }
        }
Exemplo n.º 7
0
        public Task <List <LineType> > LineTypeList()
        {
            try
            {
                DataSet ds = new DataSet();
                using (var conn = _settings.GetConnection())
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    string query = "SELECT * FROM V_TIPO_LINEA_CLIENTE;";
                    using (var cmd = new SqlCommand(query, conn))
                    {
                        using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
                        {
                            adapter.Fill(ds);
                        }
                    }
                }
                return(Task.FromResult(ConvertToList_LineType(ds)));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 8
0
        public Task <UsersList> ReturnUserStatus(int pkUser)
        {
            try
            {
                UsersList user = new UsersList();
                using (var conn = _settings.GetConnection())
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    string query = $"SELECT * FROM RETORNA_ESTADO_ADMINISTRADOR({pkUser});";
                    using (var cmd = new SqlCommand(query, conn))
                    {
                        cmd.CommandType = CommandType.Text;
                        var dr = cmd.ExecuteReader();
                        while (dr.Read())
                        {
                            user.PkCode   = dr.GetInt32(0);
                            user.Username = dr.GetString(1);
                            user.Status   = dr.GetBoolean(2);
                        }
                    }
                }
                return(Task.FromResult(user));
            }
            catch (Exception)
            {
                return(null);
            }
        }