예제 #1
0
        public List <Models.UserLimitedResponse> GetAllUsers(long organization)
        {
            List <Models.UserLimitedResponse> UserList = null;

            try
            {
                //SQL Statement
                var sqlString = "SELECT * FROM users WHERE organization = @organization";

                using (var connection = new NpgsqlConnection(connectionString))
                {
                    connection.Open();

                    using (var command = new NpgsqlCommand(sqlString, connection))
                    {
                        command.Prepare();

                        using (var reader = command.ExecuteReader())
                        {
                            if (reader != null && reader.HasRows)
                            {
                                //Initialize a User
                                Models.UserLimitedResponse user = null;
                                //Create a List to hold multiple Users
                                UserList = new List <Models.UserLimitedResponse>();

                                while (reader.Read())
                                {
                                    //Create and hydrate a new Object
                                    user = new Models.UserLimitedResponse();

                                    user.Id                      = Convert.ToInt64(reader["id"]);
                                    user.FirstName               = Convert.ToString(reader["first_name"]).Trim();
                                    user.LastName                = Convert.ToString(reader["last_name"]).Trim();
                                    user.UserDescription         = Convert.ToString(reader["description"]).Trim();
                                    user.UserEmailAddress        = Convert.ToString(reader["email_address"]).Trim();
                                    user.Role                    = Convert.ToInt64(reader["role"]);
                                    user.UserGroup               = Convert.ToInt64(reader["user_group"]);
                                    user.AgreeToTermsAndPolicies = Convert.ToInt64(reader["agreed_to_terms_and_policies"]);
                                    user.Enabled                 = Convert.ToInt64(reader["enabled"]);
                                    //Add to List
                                    UserList.Add(user);
                                }
                            }
                        }
                    }
                }
                return(UserList);
            }
            catch (Exception ex)
            {
                //Log Exception
                //_logger.LogError(ex, "error retrieving users");
                return(UserList);
            }
        }
예제 #2
0
        public List <Models.UserLimitedResponse> GetAllUsers(Guid organization)
        {
            List <Models.UserLimitedResponse> UserList = null;

            try
            {
                //SQL Statement
                var sqlString = "SELECT * FROM users WHERE organization = @organization";

                using (var connection = new NpgsqlConnection(connectionString))
                {
                    connection.Open();

                    using (var command = new NpgsqlCommand(sqlString, connection))
                    {
                        command.Parameters.AddWithValue("@organization", NpgsqlTypes.NpgsqlDbType.Uuid, organization);
                        command.Prepare();

                        using (var reader = command.ExecuteReader())
                        {
                            if (reader != null && reader.HasRows)
                            {
                                //Initialize a User
                                Models.UserLimitedResponse user = null;
                                //Create a List to hold multiple Users
                                UserList = new List <Models.UserLimitedResponse>();

                                while (reader.Read())
                                {
                                    //Create and hydrate a new Object
                                    user = new Models.UserLimitedResponse();

                                    user.Id           = Guid.Parse(reader["id"].ToString());
                                    user.FirstName    = Convert.ToString(reader["first_name"]).Trim();
                                    user.LastName     = Convert.ToString(reader["last_name"]).Trim();
                                    user.Description  = Convert.ToString(reader["description"]).Trim();
                                    user.EmailAddress = Convert.ToString(reader["email_address"]).Trim();
                                    user.Role         = Convert.ToInt64(reader["role"]);
                                    user.Created      = Convert.ToDateTime(reader["created"]);
                                    user.CreatedBy    = Guid.Parse(reader["created_by"].ToString());
                                    //Add to List
                                    UserList.Add(user);
                                }
                            }
                        }
                    }
                }
                return(UserList);
            }
            catch (Exception ex)
            {
                //Log Exception
                _logger.LogError(ex, "error retrieving users");
                return(UserList);
            }
        }
예제 #3
0
        public Models.UserLimitedResponse GetUser(long id, long organization)
        {
            Models.UserLimitedResponse user = null;

            try
            {
                //SQL Statement
                var sqlString = "SELECT * FROM users WHERE id = @id AND organization = @organization";

                using (var connection = new NpgsqlConnection(connectionString))
                {
                    connection.Open();

                    using (var command = new NpgsqlCommand(sqlString, connection))
                    {
                        command.Parameters.AddWithValue("@id", NpgsqlTypes.NpgsqlDbType.Bigint, id);
                        command.Prepare();

                        using (var reader = command.ExecuteReader())
                        {
                            if (reader != null && reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    //Create and hydrate a new Object
                                    user = new Models.UserLimitedResponse();

                                    user.Id                      = Convert.ToInt64(reader["id"]);
                                    user.FirstName               = Convert.ToString(reader["first_name"]).Trim();
                                    user.LastName                = Convert.ToString(reader["last_name"]).Trim();
                                    user.UserDescription         = Convert.ToString(reader["description"]).Trim();
                                    user.UserEmailAddress        = Convert.ToString(reader["email_address"]).Trim();
                                    user.Role                    = Convert.ToInt64(reader["role"]);
                                    user.UserGroup               = Convert.ToInt64(reader["user_group"]);
                                    user.AgreeToTermsAndPolicies = Convert.ToInt64(reader["agreed_to_terms_and_policies"]);
                                    user.Enabled                 = Convert.ToInt64(reader["enabled"]);
                                }
                            }
                        }
                    }
                }
                return(user);
            }
            catch (Exception ex)
            {
                //Log Exception
                //_logger.LogError(ex, "error retrieving user");
                return(user);
            }
        }