protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         try
         {
             _productID = int.Parse(Request["tf_ProductID"]);
             if (Request["tf_SolvedVersionID"] != null)
             {
                 _resolvedVersionID = int.Parse(Request["tf_SolvedVersionID"]);
             }
             if (Request["tf_ReportedVersionID"] != null)
             {
                 _reportedVersionID = int.Parse(Request["tf_ReportedVersionID"]);
             }
             int        ticketTypeID = int.Parse(Request["tf_TicketTypeID"]);
             TicketType ticketType   = (TicketType)TicketTypes.GetTicketType(UserSession.LoginUser, ticketTypeID);
             if (ticketType.OrganizationID != UserSession.LoginUser.OrganizationID)
             {
                 throw new Exception("Unauthorized ticket type.");
             }
             CreateTabButtons(ticketType);
             tsMain.SelectedIndex           = Settings.UserDB.ReadInt("SelectedOrganizationTicketTabIndex" + Request.Url, 0);
             ticketsFrame.Attributes["src"] = tsMain.SelectedTab.Value;
         }
         catch (Exception ex)
         {
             Response.Write("Invalid Ticket Type: " + ex.Message);
             Response.End();
         }
     }
 }
Пример #2
0
        public static string GetTicketType(RestCommand command, int ticketTypeID)
        {
            TicketType ticketType = TicketTypes.GetTicketType(command.LoginUser, ticketTypeID);

            if (ticketType.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(ticketType.GetXml("TicketType", true));
        }
        public static string GetTickets(RestCommand command)
        {
            string xml = "";

            if (command.Filters["TicketTypeID"] != null)
            {
                try
                {
                    ReportTicketsView tickets = new ReportTicketsView(command.LoginUser);
                    int        ticketTypeID   = int.Parse(command.Filters["TicketTypeID"]);
                    TicketType ticketType     = TicketTypes.GetTicketType(command.LoginUser, ticketTypeID);
                    if (ticketType.OrganizationID != command.Organization.OrganizationID)
                    {
                        throw new Exception();
                    }
                    tickets.LoadByTicketTypeID(ticketTypeID);
                    xml = tickets.GetXml("Tickets", "Ticket", true, command.Filters);
                }
                catch (Exception ex)
                {
                    throw new RestException(HttpStatusCode.NotAcceptable, "Invalid TicketTypeID to filter.", ex);
                }
            }
            else
            {
                TicketTypes ticketTypes = new TicketTypes(command.LoginUser);
                ticketTypes.LoadByOrganizationID(command.Organization.OrganizationID);

                ReportTicketsView tickets = new ReportTicketsView(command.LoginUser);
                XmlTextWriter     writer  = Tickets.BeginXmlWrite("Tickets");

                foreach (TicketType ticketType in ticketTypes)
                {
                    tickets.LoadByTicketTypeID(ticketType.TicketTypeID);
                    //writer.WriteStartElement(ticketType.Name);
                    foreach (DataRow row in tickets.Table.Rows)
                    {
                        tickets.WriteXml(writer, row, "Ticket", true, command.Filters);
                    }
                    //writer.WriteEndElement();
                }

                xml = Tickets.EndXmlWrite(writer);
            }

            //return tickets.GetXml("Tickets", "Ticket", command.Filters["TicketTypeID"] != null, command.Filters);
            return(xml);
        }
Пример #4
0
        public static string GetTickets(RestCommand command)
        {
            string xml             = "";
            bool   hasBeenFiltered = false;
            int    totalRecords    = 0;

            if (command.IsPaging)
            {
                try
                {
                    TicketsView tickets = new TicketsView(command.LoginUser);
                    tickets.LoadAllTicketIds(command.Organization.OrganizationID, command.Filters, command.PageNumber, command.PageSize);
                    hasBeenFiltered = true;
                    XmlTextWriter writer = Tickets.BeginXmlWrite("Tickets");

                    foreach (int ticketTypeId in tickets.GroupBy(g => g.TicketTypeID).Select(p => p.Key).ToList())
                    {
                        try
                        {
                            TicketsView ticketsResult = new TicketsView(command.LoginUser);
                            ticketsResult.LoadByTicketIDList(command.Organization.OrganizationID, ticketTypeId, tickets.Where(w => w.TicketTypeID == ticketTypeId).Select(p => p.TicketID).ToList());

                            foreach (DataRow row in ticketsResult.Table.Rows)
                            {
                                int  ticketId = (int)row["TicketID"];
                                Tags tags     = new Tags(command.LoginUser);
                                tags.LoadByReference(ReferenceType.Tickets, ticketId);
                                tags = tags ?? new Tags(command.LoginUser);
                                ticketsResult.WriteXml(writer, row, "Ticket", true, !hasBeenFiltered ? command.Filters : new System.Collections.Specialized.NameValueCollection(), tags);
                            }
                        }
                        catch (Exception ex)
                        {
                            ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetTickets(). Paging.");
                        }
                    }

                    if (tickets.Count > 0)
                    {
                        totalRecords = tickets[0].TotalRecords;
                    }

                    writer.WriteElementString("TotalRecords", totalRecords.ToString());
                    xml = Tickets.EndXmlWrite(writer);
                }
                catch (Exception ex)
                {
                    ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetTickets(). Paging. SQL filtering generation failed.");
                    throw new RestException(HttpStatusCode.InternalServerError, "There was an error processing your request. Please contact TeamSupport.com", ex);
                }
            }
            else
            {
                //No Paging
                if (command.Filters["TicketTypeID"] != null)
                {
                    try
                    {
                        TicketsView tickets      = new TicketsView(command.LoginUser);
                        int         ticketTypeID = int.Parse(command.Filters["TicketTypeID"]);
                        TicketType  ticketType   = TicketTypes.GetTicketType(command.LoginUser, ticketTypeID);
                        if (ticketType.OrganizationID != command.Organization.OrganizationID)
                        {
                            throw new Exception();
                        }

                        try
                        {
                            tickets.LoadByTicketTypeID(ticketTypeID, command.Organization.OrganizationID, command.Filters);
                        }
                        catch (Exception ex)
                        {
                            //if something fails use the old method
                            tickets.LoadByTicketTypeID(ticketTypeID);
                            ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetTickets(). No Paging. SQL filtering generation failed, fell into old method.");
                        }

                        xml = tickets.GetXml("Tickets", "Ticket", true, command.Filters);
                        xml = AddTagsToTickets(xml, command);
                    }
                    catch (Exception ex)
                    {
                        throw new RestException(HttpStatusCode.NotAcceptable, "Invalid TicketTypeID to filter.", ex);
                    }
                }
                else
                {
                    TicketTypes ticketTypes = new TicketTypes(command.LoginUser);
                    ticketTypes.LoadByOrganizationID(command.Organization.OrganizationID);

                    TicketsView   tickets = new TicketsView(command.LoginUser);
                    XmlTextWriter writer  = Tickets.BeginXmlWrite("Tickets");

                    foreach (TicketType ticketType in ticketTypes)
                    {
                        try
                        {
                            tickets.LoadByTicketTypeID(ticketType.TicketTypeID, command.Organization.OrganizationID, command.Filters);
                        }
                        catch (Exception ex)
                        {
                            if (ex is System.Data.SqlClient.SqlException && ex.Message.ToLower().Contains("variable names must be unique within a query batch or stored procedure"))
                            {
                                throw ex;
                            }
                            else
                            {
                                //if something fails use the old method
                                tickets.LoadByTicketTypeID(ticketType.TicketTypeID);
                                ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetTickets(). No Paging. No TicketTypeId filter. SQL filtering generation failed, fell into old method.");
                            }
                        }

                        foreach (DataRow row in tickets.Table.Rows)
                        {
                            int  ticketId = (int)row["TicketID"];
                            Tags tags     = new Tags(command.LoginUser);
                            tags.LoadByReference(ReferenceType.Tickets, ticketId);
                            tags = tags ?? new Tags(command.LoginUser);
                            tickets.WriteXml(writer, row, "Ticket", true, command.Filters, tags);
                        }
                    }

                    xml = Tickets.EndXmlWrite(writer);
                }
            }

            return(xml);
        }
Пример #5
0
        public static string GetCustomerTickets(RestCommand command)
        {
            TicketsView tickets = new TicketsView(command.LoginUser);
            string      xml     = "";

            if (command.Filters["TicketTypeID"] != null)
            {
                try
                {
                    int        ticketTypeID = int.Parse(command.Filters["TicketTypeID"]);
                    TicketType ticketType   = TicketTypes.GetTicketType(command.LoginUser, ticketTypeID);
                    if (ticketType.OrganizationID != command.Organization.ParentID)
                    {
                        throw new Exception();
                    }
                    tickets.LoadByCustomerTicketTypeID(command.Organization.OrganizationID, ticketTypeID);
                }
                catch (Exception ex)
                {
                    throw new RestException(HttpStatusCode.NotAcceptable, ex.Message);
                    throw new RestException(HttpStatusCode.NotAcceptable, "Invalid TicketTypeID to filter.", ex);
                }
            }
            else
            {
                if (command.IsPaging)
                {
                    try
                    {
                        //remove Paging parameters
                        NameValueCollection filters = new NameValueCollection();

                        foreach (string key in command.Filters.AllKeys)
                        {
                            if (key.ToLower() != "pagenumber" && key.ToLower() != "pagesize")
                            {
                                filters.Add(key, command.Filters[key]);
                            }
                        }

                        tickets.LoadByCustomerID(command.Organization.OrganizationID, command.Filters, (int)command.PageNumber, (int)command.PageSize);

                        XmlTextWriter writer = Tickets.BeginXmlWrite("Tickets");

                        foreach (DataRow row in tickets.Table.Rows)
                        {
                            int  ticketId = (int)row["TicketID"];
                            Tags tags     = new Tags(command.LoginUser);
                            tags.LoadByReference(ReferenceType.Tickets, ticketId);
                            tags = tags ?? new Tags(command.LoginUser);
                            tickets.WriteXml(writer, row, "Ticket", true, new NameValueCollection(), tags);
                        }

                        int totalRecords = 0;

                        if (tickets.Count > 0)
                        {
                            totalRecords = tickets[0].TotalRecords;
                        }

                        writer.WriteElementString("TotalRecords", totalRecords.ToString());
                        xml = Tickets.EndXmlWrite(writer);
                    }
                    catch (Exception ex)
                    {
                        ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetCustomerTickets(). Paging. SQL filtering generation failed.");
                        throw new RestException(HttpStatusCode.InternalServerError, "There was an error processing your request. Please contact TeamSupport.com", ex);
                    }
                }
                else
                {
                    tickets.LoadByCustomerID(command.Organization.OrganizationID);
                    xml = tickets.GetXml("Tickets", "Ticket", true, command.Filters, command.IsPaging);
                    xml = AddTagsToTickets(xml, command, true);
                }
            }

            return(xml);
        }
    public static string UpdateType(SelectedType type,
                                    string arg,
                                    int?id,
                                    string name,
                                    string description,
                                    bool isTimed,
                                    bool isClosed,
                                    bool isClosedEmail,
                                    bool isEmailResponse,
                                    bool pauseSla,
                                    bool isShipping,
                                    bool isDiscontinued,
                                    string productFamilyID,
                                    string iconUrl,
                                    bool isVisibleOnPortal,
                                    bool isActive,
                                    bool ExcludeFromCDI)
    {
        if (!UserSession.CurrentUser.IsSystemAdmin)
        {
            return("");
        }
        switch (type)
        {
        case SelectedType.ActionTypes:
            ActionType actionType = id == null ? (new ActionTypes(UserSession.LoginUser)).AddNewActionType() : ActionTypes.GetActionType(UserSession.LoginUser, (int)id);
            actionType.IsTimed     = isTimed;
            actionType.Name        = name;
            actionType.Description = description;
            if (id == null)
            {
                actionType.Position = actionType.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                actionType.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            actionType.Collection.Save();
            actionType.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.PhoneTypes:
            PhoneType phoneType = id == null ? (new PhoneTypes(UserSession.LoginUser)).AddNewPhoneType() : PhoneTypes.GetPhoneType(UserSession.LoginUser, (int)id);
            phoneType.Name        = name;
            phoneType.Description = description;
            if (id == null)
            {
                phoneType.Position = phoneType.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                phoneType.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            phoneType.Collection.Save();
            phoneType.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.ProductVersionStatuses:
            ProductVersionStatus productVersionStatus = id == null ? (new ProductVersionStatuses(UserSession.LoginUser)).AddNewProductVersionStatus() : ProductVersionStatuses.GetProductVersionStatus(UserSession.LoginUser, (int)id);
            productVersionStatus.IsDiscontinued = isDiscontinued;
            productVersionStatus.IsShipping     = isShipping;
            productVersionStatus.Name           = name;
            productVersionStatus.Description    = description;
            if (id == null)
            {
                productVersionStatus.Position = productVersionStatus.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                productVersionStatus.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            productVersionStatus.Collection.Save();
            productVersionStatus.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.TicketSeverities:
            TicketSeverity ticketSeverity = id == null ? (new TicketSeverities(UserSession.LoginUser)).AddNewTicketSeverity() : TicketSeverities.GetTicketSeverity(UserSession.LoginUser, (int)id);
            ticketSeverity.Name        = name;
            ticketSeverity.Description = description;
            if (id == null)
            {
                ticketSeverity.Position = ticketSeverity.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                ticketSeverity.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            ticketSeverity.VisibleOnPortal = isVisibleOnPortal;
            ticketSeverity.Collection.Save();
            ticketSeverity.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.TicketStatuses:
            if (isEmailResponse == true)
            {
                TicketStatuses statuses = new TicketStatuses(UserSession.LoginUser);
                statuses.LoadByTicketTypeID(int.Parse(arg));
                foreach (TicketStatus status in statuses)
                {
                    status.IsEmailResponse = false;
                }
                statuses.Save();
            }

            TicketStatus ticketStatus = id == null ? (new TicketStatuses(UserSession.LoginUser)).AddNewTicketStatus() : TicketStatuses.GetTicketStatus(UserSession.LoginUser, (int)id);
            ticketStatus.TicketTypeID    = int.Parse(arg);
            ticketStatus.IsClosed        = isClosed;
            ticketStatus.IsClosedEmail   = isClosedEmail;
            ticketStatus.IsEmailResponse = isEmailResponse;
            ticketStatus.PauseSLA        = pauseSla;
            ticketStatus.Name            = name;
            ticketStatus.Description     = description;
            if (id == null)
            {
                ticketStatus.Position = ticketStatus.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                ticketStatus.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            ticketStatus.Collection.Save();
            ticketStatus.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.TicketTypes:
            TicketType ticketType = id == null ? (new TicketTypes(UserSession.LoginUser)).AddNewTicketType() : TicketTypes.GetTicketType(UserSession.LoginUser, (int)id);
            ticketType.Name              = name;
            ticketType.Description       = description;
            ticketType.IconUrl           = iconUrl;
            ticketType.IsVisibleOnPortal = isVisibleOnPortal;
            ticketType.IsActive          = isActive;
            ticketType.ExcludeFromCDI    = ExcludeFromCDI;
            if (id == null)
            {
                ticketType.Position = ticketType.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                ticketType.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            if (productFamilyID == "-1")
            {
                ticketType.ProductFamilyID = null;
            }
            else
            {
                ticketType.ProductFamilyID = Convert.ToInt32(productFamilyID);
            }

            ticketType.Collection.Save();
            ticketType.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            if (id == null)
            {
                try
                {
                    System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
                    command.CommandText = "UPDATE Users SET MenuItems = MenuItems + ',mniTicketType_" + ticketType.TicketTypeID.ToString() + "' WHERE UserID IN (SELECT UserID WHERE OrganizationID = @OrganizationID)";
                    command.Parameters.AddWithValue("OrganizationID", UserSession.LoginUser.OrganizationID);
                    SqlExecutor.ExecuteNonQuery(UserSession.LoginUser, command);
                }
                catch (Exception ex)
                {
                    ExceptionLogs.LogException(UserSession.LoginUser, ex, "Ticket Type Creation - menu item");
                }

                TicketStatuses ticketStatuses = new TicketStatuses(UserSession.LoginUser);
                ticketStatus                = ticketStatuses.AddNewTicketStatus();
                ticketStatus.Name           = "New";
                ticketStatus.Description    = "New";
                ticketStatus.Position       = 0;
                ticketStatus.OrganizationID = UserSession.LoginUser.OrganizationID;
                ticketStatus.TicketTypeID   = ticketType.TicketTypeID;
                ticketStatus.IsClosed       = false;
                ticketStatus.IsClosedEmail  = false;

                ticketStatus                = ticketStatuses.AddNewTicketStatus();
                ticketStatus.Name           = "Closed";
                ticketStatus.Description    = "Closed";
                ticketStatus.Position       = 30;
                ticketStatus.OrganizationID = UserSession.LoginUser.OrganizationID;
                ticketStatus.TicketTypeID   = ticketType.TicketTypeID;
                ticketStatus.IsClosed       = true;
                ticketStatus.IsClosedEmail  = false;
                ticketStatus.Collection.Save();
                ticketStatus.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);


/*          TicketNextStatuses ticketNextStatuses = new TicketNextStatuses(UserSession.LoginUser);
 *        ticketNextStatuses.AddNextStatus(ticketStatuses[0], ticketStatuses[1], 0);
 *        ticketNextStatuses.AddNextStatus(ticketStatuses[1], ticketStatuses[0], 1);
 *        ticketNextStatuses.Save();*/
            }

            break;

        case SelectedType.ActivityTypes:
            ActivityType activityType = id == null ? (new ActivityTypes(UserSession.LoginUser)).AddNewActivityType() : ActivityTypes.GetActivityType(UserSession.LoginUser, (int)id);
            activityType.Name        = name;
            activityType.Description = description;
            if (id == null)
            {
                activityType.Position = activityType.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                activityType.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            activityType.Collection.Save();
            activityType.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        default:
            break;
        }


        return(GetTypesHtml(type, arg));
    }
    public static TypeObject GetTypeObject(SelectedType type, int id)
    {
        TypeObject result = new TypeObject();

        switch (type)
        {
        case SelectedType.ActionTypes:
            ActionType actionType = ActionTypes.GetActionType(UserSession.LoginUser, id);
            result.ID          = actionType.ActionTypeID;
            result.Name        = actionType.Name;
            result.Description = actionType.Description;
            result.IsTimed     = actionType.IsTimed;
            break;

        case SelectedType.PhoneTypes:
            PhoneType phoneType = PhoneTypes.GetPhoneType(UserSession.LoginUser, id);
            result.ID          = phoneType.PhoneTypeID;
            result.Name        = phoneType.Name;
            result.Description = phoneType.Description;
            break;

        case SelectedType.ProductVersionStatuses:
            ProductVersionStatus productVersionStatus = ProductVersionStatuses.GetProductVersionStatus(UserSession.LoginUser, id);
            result.ID             = productVersionStatus.ProductVersionStatusID;
            result.Name           = productVersionStatus.Name;
            result.Description    = productVersionStatus.Description;
            result.IsShipping     = productVersionStatus.IsShipping;
            result.IsDiscontinued = productVersionStatus.IsDiscontinued;
            break;

        case SelectedType.TicketSeverities:
            TicketSeverity ticketSeverity = TicketSeverities.GetTicketSeverity(UserSession.LoginUser, id);
            result.ID                = ticketSeverity.TicketSeverityID;
            result.Name              = ticketSeverity.Name;
            result.Description       = ticketSeverity.Description;
            result.IsVisibleOnPortal = ticketSeverity.VisibleOnPortal;
            break;

        case SelectedType.TicketStatuses:
            TicketStatus ticketStatus = TicketStatuses.GetTicketStatus(UserSession.LoginUser, id);
            result.ID              = ticketStatus.TicketStatusID;
            result.Name            = ticketStatus.Name;
            result.Description     = ticketStatus.Description;
            result.IsClosed        = ticketStatus.IsClosed;
            result.IsClosedEmail   = ticketStatus.IsClosedEmail;
            result.IsEmailResponse = ticketStatus.IsEmailResponse;
            result.PauseSla        = ticketStatus.PauseSLA;
            break;

        case SelectedType.TicketTypes:
            TicketType ticketType = TicketTypes.GetTicketType(UserSession.LoginUser, id);
            result.ID                = ticketType.TicketTypeID;
            result.Name              = ticketType.Name;
            result.Description       = ticketType.Description;
            result.IsVisibleOnPortal = ticketType.IsVisibleOnPortal;
            result.IconUrl           = ticketType.IconUrl;
            result.IsActive          = ticketType.IsActive;
            result.ExcludeFromCDI    = ticketType.ExcludeFromCDI;

            if (ticketType.ProductFamilyID == null)
            {
                result.ProductFamilyID = -1;
            }
            else
            {
                result.ProductFamilyID = (int)ticketType.ProductFamilyID;
            }

            break;

        case SelectedType.ActivityTypes:
            ActivityType activityType = ActivityTypes.GetActivityType(UserSession.LoginUser, id);
            result.ID          = activityType.ActivityTypeID;
            result.Name        = activityType.Name;
            result.Description = activityType.Description;
            break;

        default:
            break;
        }

        return(result);
    }
    public static string ReplaceType(SelectedType type, int oldID, int newID, string arg)
    {
        if (!UserSession.CurrentUser.IsSystemAdmin)
        {
            return("");
        }
        switch (type)
        {
        case SelectedType.ActionTypes:
            if (ActionTypes.GetActionType(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (ActionTypes.GetActionType(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new Actions(UserSession.LoginUser)).ReplaceActionType(oldID, newID);
            ActionTypes actionTypes = new ActionTypes(UserSession.LoginUser);
            actionTypes.DeleteFromDB(oldID);
            actionTypes.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.PhoneTypes:
            if (PhoneTypes.GetPhoneType(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (PhoneTypes.GetPhoneType(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new PhoneNumbers(UserSession.LoginUser)).ReplacePhoneType(oldID, newID);
            PhoneTypes phoneTypes = new PhoneTypes(UserSession.LoginUser);
            phoneTypes.DeleteFromDB(oldID);
            phoneTypes.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.ProductVersionStatuses:
            if (ProductVersionStatuses.GetProductVersionStatus(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (ProductVersionStatuses.GetProductVersionStatus(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new ProductVersions(UserSession.LoginUser)).ReplaceProductVersionStatus(oldID, newID);
            ProductVersionStatuses productVersionStatuses = new ProductVersionStatuses(UserSession.LoginUser);
            productVersionStatuses.DeleteFromDB(oldID);
            productVersionStatuses.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.TicketSeverities:
            if (TicketSeverities.GetTicketSeverity(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (TicketSeverities.GetTicketSeverity(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new Tickets(UserSession.LoginUser)).ReplaceTicketSeverity(oldID, newID);
            TicketSeverities ticketSeverities = new TicketSeverities(UserSession.LoginUser);
            ticketSeverities.DeleteFromDB(oldID);
            ticketSeverities.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.TicketStatuses:
            TicketStatus oldStatus = TicketStatuses.GetTicketStatus(UserSession.LoginUser, oldID);
            if (oldStatus.OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (TicketStatuses.GetTicketStatus(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new Tickets(UserSession.LoginUser)).ReplaceTicketStatus(oldID, newID);
            TicketStatuses ticketStatuses = new TicketStatuses(UserSession.LoginUser);
            ticketStatuses.DeleteFromDB(oldID);
            ticketStatuses.ValidatePositions(oldStatus.TicketTypeID);
            break;

        case SelectedType.TicketTypes:
            if (TicketTypes.GetTicketType(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (TicketTypes.GetTicketType(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new Tickets(UserSession.LoginUser)).ReplaceTicketType(oldID, newID);
            TicketTypes ticketTypes = new TicketTypes(UserSession.LoginUser);

            CustomFields customFields = new CustomFields(UserSession.LoginUser);
            customFields.LoadByTicketTypeID(UserSession.LoginUser.OrganizationID, oldID);

            ticketTypes.DeleteFromDB(oldID);
            ticketTypes.ValidatePositions(UserSession.LoginUser.OrganizationID);

            int?crmLinkFieldId = null;

            foreach (CustomField customField in customFields)
            {
                try
                {
                    crmLinkFieldId = CRMLinkFields.FindIdByCustomFieldId(customField.CustomFieldID, UserSession.LoginUser);
                }
                catch (Exception ex)
                {
                    crmLinkFieldId = null;
                }

                if (crmLinkFieldId != null && crmLinkFieldId > 0)
                {
                    CRMLinkFields crmLinkFieldsDelete = new CRMLinkFields(UserSession.LoginUser);
                    crmLinkFieldsDelete.DeleteFromDB((int)crmLinkFieldId);
                }
            }

            break;

        case SelectedType.ActivityTypes:
            if (ActivityTypes.GetActivityType(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            var types = Enum.GetValues(typeof(ActivityTypeEnum));
            if (newID > types.Length)
            {
                if (ActivityTypes.GetActivityType(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
                {
                    return("");
                }
            }
            (new Notes(UserSession.LoginUser)).ReplaceActivityType(oldID, newID);
            ActivityTypes activityTypes = new ActivityTypes(UserSession.LoginUser);
            activityTypes.DeleteFromDB(oldID);
            activityTypes.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        default:
            break;
        }
        return(GetTypesHtml(type, arg));
    }
    public static RadComboBoxItemData[] GetReplaceTypeComboData(int id, SelectedType type, int ticketTypeID)
    {
        //IDictionary<string, object> contextDictionary = (IDictionary<string, object>)context;
        List <RadComboBoxItemData> list = new List <RadComboBoxItemData>();

        /*string[] s = context["FilterString"].ToString().Split(',');
         * SelectedType type = (SelectedType)int.Parse(s[0]);
         * int ticketTypeID = int.Parse(s[1]);
         * int id = int.Parse(s[2]);*/

        BaseCollection collection  = null;
        string         nameColName = "Name";
        string         idColName   = "ID";

        switch (type)
        {
        case SelectedType.ActionTypes:
            ActionTypes actionTypes = new ActionTypes(UserSession.LoginUser);
            actionTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            collection = actionTypes;
            idColName  = "ActionTypeID";
            break;

        case SelectedType.PhoneTypes:
            PhoneTypes phoneTypes = new PhoneTypes(UserSession.LoginUser);
            phoneTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            collection = phoneTypes;
            idColName  = "PhoneTypeID";
            break;

        case SelectedType.ProductVersionStatuses:
            ProductVersionStatuses productVersionStatuses = new ProductVersionStatuses(UserSession.LoginUser);
            productVersionStatuses.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            collection = productVersionStatuses;
            idColName  = "ProductVersionStatusID";
            break;

        case SelectedType.TicketSeverities:
            TicketSeverities ticketSeverities = new TicketSeverities(UserSession.LoginUser);
            ticketSeverities.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            collection = ticketSeverities;
            idColName  = "TicketSeverityID";
            break;

        case SelectedType.TicketStatuses:
            TicketStatuses ticketStatuses = new TicketStatuses(UserSession.LoginUser);
            TicketType     ticketType     = TicketTypes.GetTicketType(UserSession.LoginUser, ticketTypeID);
            if (ticketType.OrganizationID == UserSession.LoginUser.OrganizationID)
            {
                ticketStatuses.LoadAllPositions(ticketTypeID);
                collection = ticketStatuses;
                idColName  = "TicketStatusID";
            }
            break;

        case SelectedType.TicketTypes:
            TicketTypes ticketTypes = new TicketTypes(UserSession.LoginUser);
            ticketTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            collection = ticketTypes;
            idColName  = "TicketTypeID";
            break;

        case SelectedType.ActivityTypes:
            ActivityTypes activityTypes = new ActivityTypes(UserSession.LoginUser);
            activityTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            //Load base items
            //Get default activity types
            foreach (ActivityTypeEnum activity in Enum.GetValues(typeof(ActivityTypeEnum)))
            {
                var value = Enum.Parse(typeof(ActivityTypeEnum), activity.ToString());
                //results.Add(new ActivityTypesDropDown() { Name = activity.ToString(), Value = (int)value });
                RadComboBoxItemData itemData = new RadComboBoxItemData();
                itemData.Text  = activity.ToString();
                itemData.Value = ((int)value).ToString();
                list.Add(itemData);
            }

            collection = activityTypes;
            idColName  = "ActivityTypeID";
            break;

        default:
            break;
        }

        foreach (DataRow row in collection.Table.Rows)
        {
            int i = (int)row[idColName];
            if (id != i)
            {
                RadComboBoxItemData itemData = new RadComboBoxItemData();
                itemData.Text  = row[nameColName].ToString();
                itemData.Value = i.ToString();
                list.Add(itemData);
            }
        }

        if (list.Count < 1)
        {
            RadComboBoxItemData noData = new RadComboBoxItemData();
            noData.Text  = "[No types to display.]";
            noData.Value = "-1";
            list.Add(noData);
        }

        return(list.ToArray());
    }
    protected override void OnLoad(EventArgs e)
    {
        if (!UserSession.CurrentUser.IsSystemAdmin)
        {
            Response.Write("Invalid Request");
            Response.End();
            return;
        }


        base.OnLoad(e);

        if (Request["SlaTriggerID"] != null)
        {
            _slaTriggerID = int.Parse(Request["SlaTriggerID"]);
        }
        if (Request["SlaLevelID"] != null)
        {
            _slaLevelID = int.Parse(Request["SlaLevelID"]);
        }
        if (Request["TicketTypeID"] != null)
        {
            _ticketTypeID = int.Parse(Request["TicketTypeID"]);
        }

        if (!IsPostBack)
        {
            LoadTimeZones();
            SetTimes(Settings.UserDB.ReadInt("SlaTriggerWarningTime", 1440),
                     Settings.UserDB.ReadInt("SlaTriggerInitialResponseTime", 60),
                     Settings.UserDB.ReadInt("SlaTriggerLastActionTime", 60),
                     Settings.UserDB.ReadInt("SlaTriggerClosedTime", 60));

            cbGroupViolations.Checked             = Settings.UserDB.ReadBool("SlaTriggerGroupViolations", true);
            cbGroupWarnings.Checked               = Settings.UserDB.ReadBool("SlaTriggerGroupWarnings", true);
            cbUserViolations.Checked              = Settings.UserDB.ReadBool("SlaTriggerUserViolations", true);
            cbUserWarnings.Checked                = Settings.UserDB.ReadBool("SlaTriggerUserWarnings", true);
            rbBusinessHours.Checked               = Settings.UserDB.ReadBool("SlaTriggerUseBusinessHours", true);
            rbCustomBusinessHours.Checked         = !rbBusinessHours.Checked;
            cbPauseOnOrganizationHolidays.Checked = Settings.UserDB.ReadBool("SlaTriggerPauseOnOrganizationHolidays", true);
            daysToPauseList.Attributes.Add("onkeydown", "DeleteSelectedItems(event);");
        }

        if (_slaTriggerID > -1)
        {
            _trigger = SlaTriggers.GetSlaTrigger(UserSession.LoginUser, _slaTriggerID);
            if (_trigger == null || SlaLevels.GetSlaLevel(UserSession.LoginUser, _trigger.SlaLevelID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                Response.Write("Invalid Request");
                Response.End();
                return;
            }
            _slaLevelID   = _trigger.SlaLevelID;
            _ticketTypeID = _trigger.TicketTypeID;

            if (!IsPostBack)
            {
                LoadTrigger(_trigger);
            }
        }
        else
        {
            DisableEnableCustomBusinessHours(rbBusinessHours.Checked, rbNoBusinessHours.Checked);
        }

        SlaLevel   level = SlaLevels.GetSlaLevel(UserSession.LoginUser, _slaLevelID);
        TicketType type  = TicketTypes.GetTicketType(UserSession.LoginUser, _ticketTypeID);

        if (level == null || type == null || level.OrganizationID != UserSession.LoginUser.OrganizationID || type.OrganizationID != UserSession.LoginUser.OrganizationID)
        {
            Response.Write("Invalid Request");
            Response.End();
            return;
        }

        lblSla.Text        = level.Name;
        lblTicketType.Text = type.Name;

        if (!IsPostBack)
        {
            LoadSeverities();
        }
    }