/// <summary>
 ///     Determines whether a level is unlocked for a user by evaluating the level preconditions against that user.
 /// </summary>
 /// <param name="level">The level.</param>
 /// <param name="userId">The user.</param>
 /// <returns><c>true</c> if [is level unlocked for user] [the specified level]; otherwise, <c>false</c>.</returns>
 public bool IsLevelUnlockedForUser(IPreconditionXml level, string userId)
 {
     try
     {
         var preconditionXml = level.Precondition ?? string.Empty;
         var specification   = new SingleUserWithBadges(userId);
         var maybeUser       = unitOfWork.Users.GetMaybe(specification);
         if (maybeUser.None)
         {
             return(false);
         }
         if (string.IsNullOrWhiteSpace(preconditionXml))
         {
             return(true); // No rules = unlocked
         }
         var parser = new LevelPreconditionParser();
         var rules  = parser.ParsePreconditionXml(preconditionXml);
         return(rules.Evaluate(maybeUser.Single()));
     }
     catch (Exception e)
     {
         Log.Error(e, $"Error while evaluating level access for user {userId}", level);
         return(false);
     }
 }