private static void LoadDBItemChildren(PetaPoco.Database db, SqlSystemRole item)
 {
     item.SystemRoleUserList = db.Query<SqlSystemRoleUser>("FROM SystemRoleUser WHERE SystemRoleID=@0", item.Id).ToList();
 }
 public SystemRole CreateSystemRole(string roleName, EnumSystemRoleType roleType, SystemRolePermissions permissions, SystemRoleAssignments assignments)
 {
     if(string.IsNullOrEmpty(roleName))
     {
         throw new ArgumentNullException("roleName");
     }
     using (var db = _sqlConnectionInfo.GetDB())
     {
         var count = db.ExecuteScalar<int>("SELECT COUNT(*) FROM SystemRole WHERE RoleName=@0", roleName);
         if (count != 0)
         {
             throw new ArgumentException("RoleName already exists: " + roleName);
         }
     }
     var item = new SqlSystemRole
     {
         Id = Guid.NewGuid().ToString(),
         RoleName = roleName, 
         RoleType = roleType,
         PermissionsJson = (permissions ?? new SystemRolePermissions()).ToJson(),
         //AssignmentsJson = (assignments ?? new SystemRoleAssignments()).ToJson()
     };
     item.SetCreatedFields(_userIdentity.UserName);
     using(var db = _sqlConnectionInfo.GetDB())
     {
         db.Insert("SystemRole", "ID", false, item);
         
         if(assignments != null && assignments.UserNameList != null)
         {
             foreach(var userName in assignments.UserNameList)
             {
                 var userItem = new SqlSystemRoleUser
                 {
                     Id = Guid.NewGuid().ToString(),
                     SystemRoleId = item.Id,
                     UserName = userName
                 };
                 db.Insert("SystemRoleUser", "ID", false, userItem);
             }
         }
     }
     return this.GetSystemRole(item.Id);
 }