예제 #1
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 GetTicketRating(RestCommand command, int ticketID)
        {
            TicketRating ticketRating = TicketRatings.GetTicketRating(command.LoginUser, ticketID);

            if (ticketRating.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(ticketRating.GetXml("TicketRating", true));
        }
        public static string GetTicketRatings(RestCommand command)
        {
            TicketRatings ticketRatings = new TicketRatings(command.LoginUser);

            ticketRatings.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(ticketRatings.GetXml("TicketRatings", "TicketRating", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }