public static string GetTicketAutomationTrigger(RestCommand command, int triggerID)
        {
            TicketAutomationTrigger ticketAutomationTrigger = TicketAutomationTriggers.GetTicketAutomationTrigger(command.LoginUser, triggerID);

            if (ticketAutomationTrigger.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(ticketAutomationTrigger.GetXml("TicketAutomationTrigger", true));
        }
Exemplo n.º 2
0
        public void DeleteTrigger(int triggerID)
        {
            TicketAutomationTrigger trigger = TicketAutomationTriggers.GetTicketAutomationTrigger(UserSession.LoginUser, triggerID);

            if (trigger.OrganizationID != UserSession.LoginUser.OrganizationID || !UserSession.CurrentUser.IsSystemAdmin)
            {
                return;
            }

            trigger.Delete();
            trigger.Collection.Save();
        }
Exemplo n.º 3
0
        public int CreateTrigger()
        {
            TicketAutomationTrigger trigger = (new TicketAutomationTriggers(UserSession.LoginUser)).AddNewTicketAutomationTrigger();

            trigger.Name           = "New Trigger";
            trigger.Active         = true;
            trigger.Position       = 0;
            trigger.OrganizationID = UserSession.LoginUser.OrganizationID;
            trigger.UseCustomSQL   = false;
            trigger.Collection.Save();
            return(trigger.TriggerID);
        }
Exemplo n.º 4
0
        public TicketAutomationTriggerProxy SaveTrigger(string value)
        {
            SaveTriggerData data = Newtonsoft.Json.JsonConvert.DeserializeObject <SaveTriggerData>(value);

            HttpContext.Current.Request.InputStream.Position = 0;

            TicketAutomationTrigger trigger = null;

            if (data.TriggerID > -1)
            {
                trigger = TicketAutomationTriggers.GetTicketAutomationTrigger(UserSession.LoginUser, data.TriggerID);
                if (trigger.OrganizationID != UserSession.LoginUser.OrganizationID || !UserSession.CurrentUser.IsSystemAdmin)
                {
                    return(null);
                }
            }
            else
            {
                trigger = (new TicketAutomationTriggers(UserSession.LoginUser)).AddNewTicketAutomationTrigger();
                trigger.OrganizationID = UserSession.LoginUser.OrganizationID;
            }

            trigger.Active   = data.IsActive;
            trigger.Name     = data.Name;
            trigger.Position = trigger.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            trigger.Collection.Save();

            TicketAutomationTriggerLogic logic = new TicketAutomationTriggerLogic(UserSession.LoginUser);

            logic.LoadByTrigger(data.TriggerID);
            foreach (TicketAutomationTriggerLogicItem logicItem in logic)
            {
                logicItem.Delete();
            }
            logic.Save();

            TicketAutomationActions actions = new TicketAutomationActions(UserSession.LoginUser);

            actions.LoadByTrigger(data.TriggerID);
            foreach (TicketAutomationAction action in actions)
            {
                action.Delete();
            }
            actions.Save();

            actions = new TicketAutomationActions(UserSession.LoginUser);
            foreach (TicketAutomationActionProxy actionProxy in data.Actions)
            {
                TicketAutomationAction action = actions.AddNewTicketAutomationAction();
                action.TriggerID    = trigger.TriggerID;
                action.ActionValue  = actionProxy.ActionValue;
                action.ActionValue2 = actionProxy.ActionValue2;
                action.ActionID     = actionProxy.ActionID;
            }
            actions.Save();

            logic = new TicketAutomationTriggerLogic(UserSession.LoginUser);
            foreach (LogicItem logicItemProxy in data.LogicItems)
            {
                TicketAutomationTriggerLogicItem logicItem = logic.AddNewTicketAutomationTriggerLogicItem();
                logicItem.TriggerID    = trigger.TriggerID;
                logicItem.TableID      = logicItemProxy.IsCustom ? -1 : logicItemProxy.TableID;
                logicItem.FieldID      = logicItemProxy.FieldID;
                logicItem.TestValue    = logicItemProxy.TestValue;
                logicItem.Measure      = logicItemProxy.Measure;
                logicItem.MatchAll     = logicItemProxy.MatchAll;
                logicItem.OtherTrigger = logicItemProxy.OtherTrigger;
            }
            logic.Save();

            return(trigger.GetProxy());
        }