﻿<?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="36">
      <Name>Report Problem</Name>
      <Description>Adds Report problem command to the main menu. Using the command, the requester can report a problem via the Service Catalog.</Description>
      <Scripts>
        <Script id="76">
          <Name>ReportProblem</Name>
          <Code>using System;
using System.Data;
using Microsoft.Data.SqlClient;
using Alvao.Apps.API;
using Alvao.API.Common;

namespace Alvao.Helpdesk
{
    class ReportProblem : IGeneralCommand
    {
        CommandDesc commandDesc;

        public CommandDesc CommandDesc
        {
            get { return commandDesc; }
            set { commandDesc = value; }
        }

        public ReportProblem()
        {
            int id = Settings.CommandId;
            string name = Settings.CommandName;
            int position = Settings.CommandPosition;
	        string icon = Settings.CommandIcon;

            commandDesc = new CommandDesc(id, name, position, icon);
        }

        public bool Show(SqlConnection con, int personId)
        {
            bool show = false;
            bool isRequester = PersonRights.IsAnySectionRoleMember(personId, PersonRights.SectionRoles.Requester);
            bool isOperator = PersonRights.IsAnySectionRoleMember(personId, PersonRights.SectionRoles.MainSolver);

            // If user is requester and not operator, command is shown.
            if (isRequester &amp;&amp; !isOperator)
                show = true;

            return show;
        }

        public Tuple&lt;bool, string, string&gt; Run(SqlConnection con, int personId)
        {
            bool complete = false;
            string message = "";
            string url = "";

            // Check whether the conditions for its execution / display have not changed between display and execution of the command (can be done anywhere in this Run method).
            if (!Show(con, personId))
            {
                message = "The command cannot be executed because the conditions for its display are not met.";
                complete = false;
                return Tuple.Create(complete, message, url);
            }

            // Finding the WA address.
            string waUrl = Alvao.API.Common.DbProperty.WebAppUrl;

            if (!string.IsNullOrEmpty(waUrl))
            {
                // Part of the problem reporting services catalog.
                url = waUrl + Settings.ProblemServiceCatalogUrl;

                complete = true;
            }
            else
            {
                message = "The command cannot be executed because the WebApp URL setting is missing in the ALVAO system. Please contact the ALVAO system administrator.";
                complete = false;
            }
            return Tuple.Create(complete, message, url);
        }
    }
}</Code>
          <IsLibCode>false</IsLibCode>
        </Script>
        <Script id="77">
          <Name>Settings</Name>
          <Code>public static class Settings 
{
    public const int CommandId = 2;
    public const string CommandName = "Report a problem";
    public const int CommandPosition = 1;
    public const string CommandIcon = "bullet_list_square_warning_20_regular";

    public const string ProblemServiceCatalogUrl = "/NewTicket/SectionCatalog/1";
}</Code>
          <IsLibCode>true</IsLibCode>
        </Script>
      </Scripts>
    </Application>
  </Applications>
</AlvaoApplication>