public static string GetPhoneType(RestCommand command, int phoneTypeID)
        {
            PhoneType phoneType = PhoneTypes.GetPhoneType(command.LoginUser, phoneTypeID);

            if (phoneType.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(phoneType.GetXml("PhoneType", true));
        }
Beispiel #2
0
        private void LoadCustomProperty()
        {
            switch (_refType)
            {
            case ReferenceType.ActionTypes:
                ActionType actionType = (ActionType)ActionTypes.GetActionType(LoginSession.LoginUser, _id);
                textDescription.Text = actionType.Description;
                textName.Text        = actionType.Name;
                break;

            case ReferenceType.PhoneTypes:
                PhoneType phoneType = (PhoneType)PhoneTypes.GetPhoneType(LoginSession.LoginUser, _id);
                textDescription.Text = phoneType.Description;
                textName.Text        = phoneType.Name;
                break;

            case ReferenceType.ProductVersionStatuses:
                ProductVersionStatus productVersionStatus = (ProductVersionStatus)ProductVersionStatuses.GetProductVersionStatus(LoginSession.LoginUser, _id);
                textDescription.Text   = productVersionStatus.Description;
                textName.Text          = productVersionStatus.Name;
                cbDiscontinued.Checked = productVersionStatus.IsDiscontinued;
                cbShipping.Checked     = productVersionStatus.IsShipping;
                break;

            case ReferenceType.TicketSeverities:
                TicketSeverity ticketSeverity = (TicketSeverity)TicketSeverities.GetTicketSeverity(LoginSession.LoginUser, _id);
                textDescription.Text = ticketSeverity.Description;
                textName.Text        = ticketSeverity.Name;
                break;

            case ReferenceType.TicketStatuses:
                TicketStatus ticketStatus = (TicketStatus)TicketStatuses.GetTicketStatus(LoginSession.LoginUser, _id);
                textDescription.Text = ticketStatus.Description;
                textName.Text        = ticketStatus.Name;
                cbClosed.Checked     = ticketStatus.IsClosed;
                break;

            default:
                break;
            }
        }
    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 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 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));
    }