public bool AddUserToGroup(int userId, int groupId)
        {
            if (GetUserGroupById(groupId) == null)
            {
                return(false);
            }

            using (IDbConnection db = new SqlConnection(_connectionString))
            {
                UserGroupMemberRecord userRecord = db.Query <UserGroupMemberRecord>(
                    @"SELECT * FROM UserGroupMember 
                        WHERE UserId = @userId 
                        AND GroupId = @groupId",
                    new { userId, groupId }).FirstOrDefault();

                if (userRecord != null)
                {
                    return(false);
                }

                userRecord.UserId  = userId;
                userRecord.GroupId = groupId;

                db.Query("INSERT INTO UserGroupMember (UserId, GroupId) " +
                         "VALUES(@userId, @groupId)", userRecord);
            }

            return(true);
        }
        public void ExcludeUserFromGroup(int userId, int groupId)
        {
            UserGroupMemberRecord userRecord = new UserGroupMemberRecord()
            {
                UserId = userId, GroupId = groupId
            };

            using (IDbConnection db = new SqlConnection(_connectionString))
            {
                db.Query(@"DELETE FROM UserGroupMember 
                        WHERE UserId = @userId 
                        AND GroupId = @groupId",
                         userRecord);
            }
        }