public static string GetTicketAutomationTriggerLogicItem(RestCommand command, int triggerLogicID)
        {
            TicketAutomationTriggerLogicItem ticketAutomationTriggerLogicItem = TicketAutomationTriggerLogic.GetTicketAutomationTriggerLogicItem(command.LoginUser, triggerLogicID);

            if (ticketAutomationTriggerLogicItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(ticketAutomationTriggerLogicItem.GetXml("TicketAutomationTriggerLogicItem", true));
        }
        public static string GetTicketAutomationTriggerLogic(RestCommand command)
        {
            TicketAutomationTriggerLogic ticketAutomationTriggerLogic = new TicketAutomationTriggerLogic(command.LoginUser);

            ticketAutomationTriggerLogic.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(ticketAutomationTriggerLogic.GetXml("TicketAutomationTriggerLogic", "TicketAutomationTriggerLogicItem", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
Beispiel #3
0
        public TriggerData GetTrigger(int triggerID)
        {
            TicketAutomationTriggersViewItem trigger = TicketAutomationTriggersView.GetTicketAutomationTriggersViewItem(UserSession.LoginUser, triggerID);

            if (trigger.OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return(null);
            }

            TicketAutomationActions actions = new TicketAutomationActions(UserSession.LoginUser);

            actions.LoadByTrigger(triggerID);

            TicketAutomationTriggerLogic logic = new TicketAutomationTriggerLogic(UserSession.LoginUser);

            logic.LoadByTrigger(triggerID);

            TriggerData result = new TriggerData();

            result.Trigger    = trigger.GetProxy();
            result.LogicItems = logic.GetTicketAutomationTriggerLogicItemProxies();
            result.Actions    = actions.GetTicketAutomationActionProxies();
            return(result);
        }
Beispiel #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());
        }