<?xml version="1.0" encoding="utf-8"?>
<AlvaoApplication xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ModelVersion="1">
  <Applications>
    <Application id="32">
      <Name>Object Intune</Name>
      <Description>In the Object page, adds the MS Intune command that redirects user to the MS Intune for selected object based on the object Intune device id property.</Description>
      <UniqueId>5ec06e7d-897a-4335-95dc-3f3b5a16075b</UniqueId>
      <Version>2</Version>
      <AdvancedSettings />
      <Scripts>
        <Script id="69">
          <Name>IntuneCommand</Name>
          <Code>using Alvao.API.Common.Model.CustomApps;
using Alvao.Apps.API;
using Alvao.Context;
using Dapper;

public class IntuneCommand : IEntityCommand 
{
    public string Id {get; set;}
    public Entity Entity {get; set;}

    public IntuneCommand()
    {
        Id = "ObjectIntune";
        Entity = Entity.Object;
    }

    public EntityCommandShowResult Show(int entityId, int personId)
    {   
        int position = 2;
        string icon = "phone_tablet_20_regular";
        string name = "MS Intune";
        if (!LicenceCheck())
            return new EntityCommandShowResult (false, name, icon, position);
        bool show = !string.IsNullOrEmpty(GetObjectIntuneId(entityId));
        
        return new EntityCommandShowResult (show, name, icon, position);
    }

    public CommandResult Run(int entityId, int personId)
    {
        if (!LicenceCheck())
            return new CommandResult(MessageType.Error, "Module is not activated.", null);
        MessageType messageType = MessageType.None;
        string messageText = string.Empty;
        string navigateToUrl = string.Empty;

        string intuneId = GetObjectIntuneId(entityId);
        if (string.IsNullOrEmpty(intuneId)){
            messageType = MessageType.Error;
            messageText = "Error getting the value of the Intune device Id property.";
        } else {
            navigateToUrl = "https://endpoint.microsoft.com/#view/Microsoft_Intune_Devices/DeviceSettingsMenuBlade/~/overview/mdmDeviceId/" + intuneId;
        }
        
        return new CommandResult(messageType, messageText, navigateToUrl);
    }

    private bool LicenceCheck() =&gt; Alvao.API.Common.Activation.IsModuleActivated(Alvao.Global.ModuleInfo.ModuleId.EndpointManagementConnectors);

            private string GetObjectIntuneId(int objectId){
            using (var scope = AlvaoContext.GetConnectionScope())
            {
            //Retrieving the IntuneId from the database.
            return scope.Connection.QueryFirstOrDefault&lt;string&gt;(@"
                select N.IntuneDeviceId from NodeCust N
                where N.NodeId = @objectId", new { objectId }
            );
            }
            }
            }</Code>
          <IsLibCode>false</IsLibCode>
          <Codesign>DOD/V/7J+BiAwZEq0frbH+MlwNAax/Piorz5JiQL845TS+cwNd4iytGSrTOifxyyII1G3F7dMPcwRleUwEInppaPAK7gOoy6B4xKIn9VaXUqnOy4gwBu6rQPfe6N7uRjVRj5V6k0FzvjfuxTnGUb+n8QVblaOm67dA3cuVat8tV/aK8XzORoqaMGu/gO4q/1ChLp6LTosLZIqoLAITTHnlOwVexTMEEdzqdUwUDxB8h3BFpp64CAMWrDRkaGdoy/XqUXpr+xPjIfadVRf1sEIomLKaByzJdjCaeQba6Qq04KIgDNqexdKOGmUGWFg4funqZLSoMDSPR7q45Uqb/aHQ==</Codesign>
        </Script>
      </Scripts>
    </Application>
  </Applications>
</AlvaoApplication>