public static void WriteTicketsViewItemXml(RestCommand command, XmlWriter writer, string ticketID, CustomFields customFields)
        {
            int             id     = int.Parse(ticketID);
            TicketsViewItem ticket = TicketsView.GetTicketsViewItem(command.LoginUser, id);

            WriteTicketsViewItemXml(command, writer, ticket, customFields);
        }
Beispiel #2
0
        private void ProcessTicketSearch(HttpContext context, int parentID, int userID, string searchTerm, int customerHubID)
        {
            SearchResults           ticketResults = TicketsView.GetHubSearchTicketResults(searchTerm, LoginUser.Anonymous, parentID);
            List <TicketSearchItem> result        = GetTicketResults(ticketResults, LoginUser.Anonymous, userID, parentID, customerHubID);

            WriteJson(context, result);
        }
Beispiel #3
0
        public static string CreateCustomerTicket(RestCommand command)
        {
            Tickets tickets = new Tickets(command.LoginUser);
            Ticket  ticket  = tickets.AddNewTicket();

            ticket.OrganizationID = (int)command.Organization.ParentID;
            ticket.TicketSource   = "API";
            ticket.NeedsIndexing  = true;
            string description = string.Empty;
            int?   contactID   = null;
            int?   customerID  = null;

            ticket.FullReadFromXml(command.Data, true, ref description, ref contactID, ref customerID);
            ticket.Collection.Save();
            ticket.UpdateCustomFieldsFromXml(command.Data);

            Actions actions = new Actions(command.LoginUser);

            Data.Action action = actions.AddNewAction();
            action.ActionTypeID       = null;
            action.Name               = "Description";
            action.SystemActionTypeID = SystemActionType.Description;
            action.Description        = description;
            action.IsVisibleOnPortal  = ticket.IsVisibleOnPortal;
            action.IsKnowledgeBase    = ticket.IsKnowledgeBase;
            action.TicketID           = ticket.TicketID;
            actions.Save();

            tickets.AddOrganization(command.Organization.OrganizationID, ticket.TicketID);
            UpdateFieldsOfSeparateTable(command, ticket, true);
            return(TicketsView.GetTicketsViewItem(command.LoginUser, ticket.TicketID).GetXml("Ticket", true));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["TicketID"] == null)
        {
            EndResponse("Invalid Ticket");
        }

        int             ticketID = int.Parse(Request["TicketID"]);
        TicketsViewItem ticket   = TicketsView.GetTicketsViewItem(TSAuthentication.GetLoginUser(), ticketID);

        CultureInfo us = new CultureInfo(TSAuthentication.GetLoginUser().CultureInfo.ToString());

        if (ticket == null)
        {
            EndResponse("Invalid Ticket");
        }

        if (ticket.SlaViolationTime < 0)
        {
            tipSla.Attributes.Add("class", "ts-icon ts-icon-sla-bad");
        }
        else if (ticket.SlaWarningTime < 0)
        {
            tipSla.Attributes.Add("class", "ts-icon ts-icon-sla-warning");
        }
        else
        {
            tipSla.Attributes.Add("class", "ts-icon ts-icon-sla-good");
        }


        tipNumber.InnerText = "Ticket #" + ticket.TicketNumber.ToString();
        tipNumber.Attributes.Add("onclick", "top.Ts.MainPage.openTicket(" + ticket.TicketNumber + "); return false;");
        tipName.InnerHtml = ticket.Name;

        StringBuilder props = new StringBuilder();

        AddStringProperty(props, "Assigned To", ticket.UserName, true, "", "openUser", ticket.UserID);
        AddStringProperty(props, "Group", ticket.GroupName, true, null, null, null);
        AddStringProperty(props, "Type", ticket.TicketTypeName, false, null, null, null);
        AddStringProperty(props, "Status", ticket.Status, false, null, null, null);
        AddStringProperty(props, "Severity", ticket.Severity, false, null, null, null);
        AddStringProperty(props, "Customers", GetCustomerLinks(ticketID), false, null, null, null);
        AddStringProperty(props, "Tags", GetTagLinks(ticketID), false, null, null, null);
        if (ticket.DueDate != null)
        {
            DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc((DateTime)ticket.DueDateUtc, TSAuthentication.GetLoginUser().TimeZoneInfo);

            if (ticket.DueDateUtc < DateTime.UtcNow)
            {
                AddStringProperty(props, "Due Date", cstTime.ToString(us.DateTimeFormat.ShortDatePattern + "  HH:mm"), false, null, null, null, true);
            }
            else
            {
                AddStringProperty(props, "Due Date", cstTime.ToString(us.DateTimeFormat.ShortDatePattern + "  HH:mm"), false, null, null, null);
            }
        }
        tipProps.InnerHtml = props.ToString();
    }
Beispiel #5
0
        public static string GetTicketsByCustomerID(RestCommand command, int customerID, bool orderByDateCreated = false)
        {
            TicketsView tickets = new TicketsView(command.LoginUser);
            string      orderBy = orderByDateCreated ? "ot.DateCreated DESC" : "TicketNumber";
            string      xml     = "";

            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(customerID, filters, (int)command.PageNumber, (int)command.PageSize, orderBy);
                    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. GetTicketsByCustomerID(). 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(customerID, orderBy);
                xml = tickets.GetXml("Tickets", "Ticket", true, command.Filters, command.IsPaging);
                xml = AddTagsToTickets(xml, command);
            }

            return(xml);
        }
        public string GetData()
        {
            TicketsView tickets     = new TicketsView(_command.LoginUser);
            TicketTypes ticketTypes = new TicketTypes(_command.LoginUser);

            ticketTypes.LoadAllPositions(_command.Organization.OrganizationID);
            TicketType   ticketType = null;
            CustomFields customFields;
            string       elementName = "Ticket";

            switch (_restTicketType)
            {
            case RestTicketType.Bug:
                elementName = "Bug";
                ticketType  = ticketTypes.FindByName("Bugs");
                break;

            case RestTicketType.Feature:
                elementName = "Feature";
                ticketType  = ticketTypes.FindByName("Features");
                break;

            case RestTicketType.Task:
                elementName = "Task";
                ticketType  = ticketTypes.FindByName("Tasks");
                break;

            case RestTicketType.Issue:
                elementName = "Issue";
                ticketType  = ticketTypes.FindByName("Issues");
                break;

            default:
                break;
            }

            if (ticketType == null)
            {
                tickets.LoadByOrganizationID(_command.Organization.OrganizationID);
                customFields = null;
            }
            else
            {
                tickets.LoadByTicketTypeID(ticketType.TicketTypeID);
                customFields = new CustomFields(_command.LoginUser);
                customFields.LoadByTicketTypeID(_command.Organization.OrganizationID, ticketType.TicketTypeID);
            }

            RestXmlWriter writer = new RestXmlWriter(elementName + "s");

            foreach (TicketsViewItem ticket in tickets)
            {
                writer.XmlWriter.WriteStartElement(elementName);
                RestTicketsViewItem.WriteTicketsViewItemXml(_command, writer.XmlWriter, ticket, customFields);
                writer.XmlWriter.WriteEndElement();
            }
            return(writer.GetXml());
        }
 private void HideAllItemViews()
 {
     BoxView.Hide();
     //BrawlerView.Hide();
     BrawlerPowerView.Hide();
     CoinsView.Hide();
     GemsView.Hide();
     TicketsView.Hide();
 }
Beispiel #8
0
        private List <KBSearchItem> GetKBResults(SearchResults results, LoginUser loginUser, int userID, int parentID, int hubID)
        {
            bool enableCustomerSpecificKB          = false;
            bool enableCustomerProductAssociation  = false;
            bool enableAnonymousProductAssociation = false;

            List <KBSearchItem> items = new List <KBSearchItem>();
            int  customerID           = 0;
            User user = Users.GetUser(loginUser, userID);

            if (user != null)
            {
                customerID = user.OrganizationID;
            }

            CustomerHubFeatureSettings hubFeatureSettings = new CustomerHubFeatureSettings(loginUser);

            hubFeatureSettings.LoadByCustomerHubID(hubID);

            if (hubFeatureSettings.Any())
            {
                enableCustomerProductAssociation  = hubFeatureSettings[0].EnableCustomerProductAssociation;
                enableAnonymousProductAssociation = hubFeatureSettings[0].EnableAnonymousProductAssociation;
                enableCustomerSpecificKB          = hubFeatureSettings[0].EnableCustomerSpecificKB;
            }

            for (int i = 0; i < results.Count; i++)
            {
                results.GetNthDoc(i);
                int ticketID = int.Parse(results.CurrentItem.Filename);
                if (ticketID > 0)
                {
                    TicketsView ticketsViewHelper = new TicketsView(loginUser);
                    ticketsViewHelper.LoadHubKBByID(ticketID, parentID, customerID, enableCustomerSpecificKB, enableCustomerProductAssociation, enableAnonymousProductAssociation);

                    if (ticketsViewHelper.Any())
                    {
                        KBSearchItem item = new KBSearchItem();
                        item.HitRating = results.CurrentItem.ScorePercent;
                        item.Article   = ticketsViewHelper[0].GetProxy();

                        TicketRatings ratings = new TicketRatings(loginUser);
                        ratings.LoadByTicketID(ticketID);

                        if (ratings.Any())
                        {
                            TicketRating rating = ratings[0];
                            item.VoteRating = rating.ThumbsUp;
                        }

                        items.Add(item);
                    }
                }
            }
            return(items);
        }
        public static string GetTicketsViewItem(RestCommand command, int ticketID)
        {
            TicketsViewItem ticketsViewItem = TicketsView.GetTicketsViewItem(command.LoginUser, ticketID);

            if (ticketsViewItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(ticketsViewItem.GetXml("TicketsViewItem", true));
        }
        override protected void LoadData()
        {
            TicketsView tickets = new TicketsView(_loginUser);

            tickets.LoadForIndexing(_organizationID, _maxCount, _isRebuilding);
            foreach (TicketsViewItem ticket in tickets)
            {
                _itemIDList.Add(ticket.TicketID);
            }
        }
        public string GetData()
        {
            TicketsViewItem ticket       = TicketsView.GetTicketsViewItem(_command.LoginUser, _ticketID);
            CustomFields    customFields = new CustomFields(_command.LoginUser);

            customFields.LoadByTicketTypeID(_command.Organization.OrganizationID, ticket.TicketTypeID);

            RestXmlWriter writer = new RestXmlWriter("Ticket");

            WriteTicketsViewItemXml(_command, writer.XmlWriter, ticket, customFields);
            return(writer.GetXml());
        }
Beispiel #12
0
        public static string UnSubscribeFromTicket(RestCommand command, int ticketIDOrNumber, int userId)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            Subscriptions.RemoveSubscription(command.LoginUser, userId, ReferenceType.Tickets, ticket.TicketID);

            return(ticket.GetXml("Ticket", true));
        }
        public static string GetCustomerActions(RestCommand command, int ticketID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumberForCustomer(command.LoginUser, (int)command.Organization.ParentID, ticketID);

            if (ticket.OrganizationID != command.Organization.ParentID || !ticket.GetIsCustomer(command.Organization.OrganizationID))
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            ActionsView actions = new ActionsView(command.LoginUser);

            actions.LoadByTicketID(ticket.TicketID);

            return(actions.GetXml("Actions", "Action", true, command.Filters));
        }
Beispiel #14
0
        public void RequestTicketUpdate(int ticketID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItem(UserSession.LoginUser, ticketID);

            if (ticket == null)
            {
                return;
            }
            EmailPosts.SendTicketUpdateRequest(UserSession.LoginUser, ticketID);

            string description = String.Format("{0} requested an update from {1} for {2}", UserSession.CurrentUser.FirstLastName, ticket.UserName, Tickets.GetTicketLink(UserSession.LoginUser, ticketID));

            ActionLogs.AddActionLog(UserSession.LoginUser, ActionLogType.Update, ReferenceType.Tickets, ticket.TicketID, description);
        }
Beispiel #15
0
        public static string UpdateCustomerTicket(RestCommand command, int ticketID)
        {
            Ticket ticket = Tickets.GetTicket(command.LoginUser, ticketID);

            if (ticket.OrganizationID != command.Organization.ParentID || !ticket.GetTicketView().GetIsCustomer(command.Organization.OrganizationID))
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            ticket.ReadFromXml(command.Data, false);
            ticket.Collection.Save();
            ticket.UpdateCustomFieldsFromXml(command.Data);
            ticket = Tickets.GetTicket(command.LoginUser, ticket.TicketID);
            return(TicketsView.GetTicketsViewItem(command.LoginUser, ticket.TicketID).GetXml("Ticket", true));
        }
Beispiel #16
0
        public static string DeleteTicket(RestCommand command, int ticketIDOrNumber)
        {
            TicketsViewItem ticketViewItem = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);
            Ticket          ticket         = Tickets.GetTicket(command.LoginUser, ticketViewItem.TicketID);
            string          result         = ticketViewItem.GetXml("Ticket", true);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            ticket.Delete();
            ticket.Collection.Save();
            return(result);
        }
        public static string GetTicketsView(RestCommand command)
        {
            TicketsView ticketsView = new TicketsView(command.LoginUser);

            ticketsView.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(ticketsView.GetXml("TicketsView", "TicketsViewItem", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
Beispiel #18
0
        public static string GetTicketsByAssetID(RestCommand command, int assetID, bool orderByDateCreated = false)
        {
            TicketsView tickets = new TicketsView(command.LoginUser);

            if (orderByDateCreated)
            {
                tickets.LoadByAssetID(assetID, "at.DateCreated DESC");
            }
            else
            {
                tickets.LoadByAssetID(assetID);
            }

            return(tickets.GetXml("Tickets", "Ticket", command.Filters["TicketTypeID"] != null, command.Filters));
        }
Beispiel #19
0
        // Customer Only Methods

        public static string GetCustomerTicket(RestCommand command, int ticketID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumberForCustomer(command.LoginUser, (int)command.Organization.ParentID, ticketID);

            if (ticket.OrganizationID != command.Organization.ParentID || !ticket.GetIsCustomer(command.Organization.OrganizationID))
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            Tags tags = new Tags(command.LoginUser);

            tags.LoadByReference(ReferenceType.Tickets, ticket.TicketID, command.Organization.ParentID);

            return(ticket.GetXml("Ticket", true, tags));
        }
        public static string CreateAttachment(RestCommand command, int ticketIDOrNumber, int actionID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            string path = AttachmentPath.GetPath(command.LoginUser, command.Organization.OrganizationID, AttachmentPath.Folder.Actions, 3);

            path = Path.Combine(path, actionID.ToString());
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            HttpFileCollection files = command.Context.Request.Files;

            if (files.Count > 0)
            {
                if (files[0].ContentLength > 0)
                {
                    string fileName = RemoveSpecialCharacters(DataUtils.VerifyUniqueUrlFileName(path, Path.GetFileName(files[0].FileName)));

                    files[0].SaveAs(Path.Combine(path, fileName));

                    Attachment attachment = (new Attachments(command.LoginUser)).AddNewAttachment();
                    attachment.RefType        = AttachmentProxy.References.Actions;
                    attachment.RefID          = (int)actionID;
                    attachment.OrganizationID = command.Organization.OrganizationID;
                    attachment.FileName       = fileName;
                    attachment.Path           = Path.Combine(path, fileName);
                    attachment.FileType       = files[0].ContentType;
                    attachment.FileSize       = files[0].ContentLength;
                    attachment.FilePathID     = 3;
                    attachment.Collection.Save();
                    return(attachment.Collection.GetXml("Attachments", "Attachment", true, command.Filters));
                }
                else
                {
                    throw new RestException(HttpStatusCode.BadRequest, "The file to attach is empty.");
                }
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "No file to attach.");
            }
        }
        public static string GetActions(RestCommand command, int ticketIDOrNumber, int?limitNumber = null)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            ActionsView actions = new ActionsView(command.LoginUser);

            actions.LoadByTicketID(ticket.TicketID, limitNumber);

            actions.Select(p => { p.Description = RemoveInvalidXmlChars(p.Description); return(p); }).ToList();

            return(actions.GetXml("Actions", "Action", true, command.Filters));
        }
Beispiel #22
0
        public static string GetRelatedTickets(RestCommand command, int ticketIDOrTicketNumber)
        {
            TicketsView tickets = new TicketsView(command.LoginUser);

            tickets.LoadRelated(ticketIDOrTicketNumber);
            if (tickets.IsEmpty)
            {
                tickets = new TicketsView(command.LoginUser);
                tickets.LoadRelatedByTicketNumber(ticketIDOrTicketNumber, command.Organization.OrganizationID);
            }
            if (tickets.Count > 0 && tickets[0].OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            return(tickets.GetXml("Tickets", "Ticket", true, command.Filters));
        }
Beispiel #23
0
        public static string GetZapierTickets(RestCommand command, int limitNumber)
        {
            string xml = "";

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

            tickets.LoadByOrganizationIDOrderByNumberDESC(command.Organization.OrganizationID, limitNumber);
            foreach (DataRow row in tickets.Table.Rows)
            {
                tickets.WriteXml(writer, row, "Ticket", true, command.Filters);
            }

            xml = Tickets.EndXmlWrite(writer);

            //return tickets.GetXml("Tickets", "Ticket", command.Filters["TicketTypeID"] != null, command.Filters);
            return(xml);
        }
        public static string CreateAction(RestCommand command, int ticketIDOrNumber)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            Actions actions = new Actions(command.LoginUser);

            TeamSupport.Data.Action action = actions.AddNewAction();
            action.TicketID = ticket.TicketID;
            action.ReadFromXml(command.Data, true);
            action.Collection.Save();
            action.UpdateCustomFieldsFromXml(command.Data);
            return(ActionsView.GetActionsViewItem(command.LoginUser, action.ActionID).GetXml("Action", true));
        }
Beispiel #25
0
        public static string UpdateTicket(RestCommand command, int ticketIDOrNumber)
        {
            TicketsViewItem ticketViewItem = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);
            Ticket          ticket         = Tickets.GetTicket(command.LoginUser, ticketViewItem.TicketID);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            ticket.ReadFromXml(command.Data, false);
            ticket.Collection.Save();
            ticket.UpdateCustomFieldsFromXml(command.Data);

            ticket = Tickets.GetTicket(command.LoginUser, ticket.TicketID);
            UpdateFieldsOfSeparateTable(command, ticket);

            return(TicketsView.GetTicketsViewItem(command.LoginUser, ticket.TicketID).GetXml("Ticket", true));
        }
        public static string UpdateCustomerAction(RestCommand command, int actionID)
        {
            TeamSupport.Data.Action action = Actions.GetAction(command.LoginUser, actionID);
            if (action == null)
            {
                throw new RestException(HttpStatusCode.BadRequest);
            }
            TicketsViewItem ticket = TicketsView.GetTicketsViewItem(command.LoginUser, action.TicketID);

            if (ticket.OrganizationID != command.Organization.ParentID || !ticket.GetIsCustomer(command.Organization.OrganizationID))
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            action.ReadFromXml(command.Data, false);
            action.Collection.Save();
            action.UpdateCustomFieldsFromXml(command.Data);
            return(ActionsView.GetActionsViewItem(command.LoginUser, action.ActionID).GetXml("Action", true));
        }
        public static string GetTicketOrganizations(RestCommand command, int ticketIDOrNumber, bool orderByDateCreated = false)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            OrganizationsView organizations = new OrganizationsView(command.LoginUser);

            if (orderByDateCreated)
            {
                organizations.LoadByTicketID(ticket.TicketID, "ot.DateCreated DESC");
            }
            else
            {
                organizations.LoadByTicketID(ticket.TicketID);
            }
            return(organizations.GetXml("Customers", "Customer", true, command.Filters));
        }
        public static string RemoveTicketOrganization(RestCommand command, int ticketIDOrNumber, int organizationID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            Organization organization = Organizations.GetOrganization(command.LoginUser, organizationID);

            if (organization == null || organization.ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            Tickets tickets = new Tickets(command.LoginUser);

            tickets.RemoveOrganization(organizationID, ticket.TicketID);
            return(OrganizationsView.GetOrganizationsViewItem(command.LoginUser, organizationID).GetXml("Customer", true));
        }
Beispiel #29
0
        public static string RemoveTicketContact(RestCommand command, int ticketIDOrNumber, int contactID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            User         user         = Users.GetUser(command.LoginUser, contactID);
            Organization organization = Organizations.GetOrganization(command.LoginUser, user.OrganizationID);

            if (organization == null || organization.ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            Tickets tickets = new Tickets(command.LoginUser);

            tickets.RemoveContact(user.UserID, ticket.TicketID);
            return(ContactsView.GetContactsViewItem(command.LoginUser, user.UserID).GetXml("Contact", true));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        string domain = SystemSettings.GetAppUrl();

        if (Request["CustomerID"] == null)
        {
            EndResponse("Invalid Customer");
        }

        int          organizationID = int.Parse(Request["CustomerID"]);
        Organization organization   = Organizations.GetOrganization(TSAuthentication.GetLoginUser(), organizationID);

        if (organization == null)
        {
            EndResponse("Invalid Customer");
        }

        if (organization.OrganizationID != TSAuthentication.OrganizationID && organization.ParentID != TSAuthentication.OrganizationID)
        {
            EndResponse("Invalid Customer");
        }

        tipCompany.InnerText = organization.Name;
        tipCompany.Attributes.Add("onclick", "top.Ts.MainPage.openNewCustomer(" + organizationID.ToString() + "); return false;");

        StringBuilder props = new StringBuilder();

        if (!string.IsNullOrEmpty(organization.Website))
        {
            string website;
            website = organization.Website;
            if (organization.Website.IndexOf("http://") < 0 && organization.Website.IndexOf("https://") < 0)
            {
                website = "http://" + organization.Website;
            }
            props.Append(string.Format("<dt>Website</dt><dd><a target=\"_blank\" href=\"{0}\">{0}</a></dd>", website));
        }

        if (organization.SAExpirationDate != null)
        {
            string css = organization.SAExpirationDate <= DateTime.UtcNow ? "tip-customer-expired" : "";
            props.Append(string.Format("<dt>Service Expiration</dt><dd class=\"{0}\">{1:D}</dd>", css, (DateTime)organization.SAExpirationDate));
        }

        PhoneNumbersView numbers = new PhoneNumbersView(organization.Collection.LoginUser);

        numbers.LoadByID(organization.OrganizationID, ReferenceType.Organizations);

        foreach (PhoneNumbersViewItemProxy number in numbers.GetPhoneNumbersViewItemProxies())
        {
            props.Append(string.Format("<dt>{0}</dt><dd><a href=\"tel:{1}\">{1} {2}</a></dd>", number.PhoneType, number.FormattedPhoneNumber, number.Extension));
        }

        tipProps.InnerHtml = props.ToString();

        TicketsView tickets = new TicketsView(TSAuthentication.GetLoginUser());

        tickets.LoadLatest5Tickets(organizationID);
        StringBuilder recent = new StringBuilder();

        foreach (TicketsViewItem t in tickets)
        {
            if (t.TicketNumber != null && t.Name != null && t.Status != null)
            {
                recent.Append(string.Format("<div><a href='{0}?TicketNumber={1}' target='_blank' onclick='top.Ts.MainPage.openTicket({2}); return false;'><span class='ticket-tip-number'>{3}</span><span class='ticket-tip-status'>{4}</span><span class='ticket-tip-name'>{5}</span></a></div>", domain, t.TicketNumber, t.TicketNumber, t.TicketNumber, t.Status.Length > 17 ? t.Status.Substring(0, 15) + "..." : t.Status, t.Name.Length > 35 ? t.Name.Substring(0, 33) + "..." : t.Name));
            }
        }

        if (recent.Length == 0)
        {
            recent.Append("There are no recent tickets for this organization");
        }

        tipRecent.InnerHtml = recent.ToString();

        //Support Hours
        StringBuilder supportHours = new StringBuilder();

        if (organization.SupportHoursMonth > 0)
        {
            tipTimeSpent.Visible = true;
            double timeSpent = organization.GetTimeSpentMonth(TSAuthentication.GetLoginUser(), organization.OrganizationID) / 60;
            supportHours.AppendFormat("<div class='ui-widget-content ts-separator'></div><div id='tipRecent' runat='server'><dt>Monthly Support Hours</dt><dt>Hours Used</dt><dd>{0}</dd><dt>Hours Remaining</dt>", Math.Round(timeSpent, 2));

            if (timeSpent > organization.SupportHoursMonth)
            {
                supportHours.AppendFormat("<dd class='red'>-{0}</dd>", Math.Round(timeSpent - organization.SupportHoursMonth, 2));
            }
            else
            {
                supportHours.AppendFormat("<dd>{0}</dd>", Math.Round(organization.SupportHoursMonth - timeSpent, 2));
            }
        }


        tipTimeSpent.InnerHtml = supportHours.ToString();

        // Customer Notes
        StringBuilder notesString = new StringBuilder();
        NotesView     notes       = new NotesView(TSAuthentication.GetLoginUser());

        notes.LoadbyCustomerID(organizationID);

        foreach (NotesViewItem t in notes)
        {
            notesString.Append(string.Format("<div><a href='#' target='_blank' onclick='top.Ts.MainPage.openNewCustomerNote({0},{1}); return false;'><span class='ticket-tip-name'>{2}</span></a></div>", t.RefID, t.NoteID, t.Title.Length > 65 ? t.Title.Substring(0, 65) + "..." : t.Title));
        }

        if (notesString.Length == 0)
        {
            notesString.Append("");
        }

        tipNotes.InnerHtml = notesString.ToString();
    }