Hi Vlad,
This part is not correct:
if (!UserCanEditModule(moduleId, ItemGuid))
You should be passing in FeatureGuid of the feature not an ItemGuid. This check is to make sure the module exists on the page corresponding to pageid param and the feature guid is needed to make sure the module is an instance of your feature and not some other module that the user may have permission on.
FeatureGuid represents the feature, ModuleId/ModuleGuid represents the instance of the feature, ItemGuid is some item contained within the instance.
Hope that helps,
Joe