private JObject GetTicketsHistory(HttpContext context)
        {
            JObject responseJObj = new JObject();

            try
            {
                UDC.Ticket ticket = new UDC.Ticket();
                ticket.Mode      = context.Request["mode"] != null?Convert.ToInt32(context.Request["mode"]) : 0;;
                ticket.AccountId = accountId;
                //ticket.AgentId = agentId;
                ticket.RoleId = roleId;
                if (roleId == 1)
                {
                    ticket.AgentId         = agentId;
                    ticket.SelectedAgentId = agentId;
                }
                else
                {
                    ticket.AgentId         = agentId;
                    ticket.SelectedAgentId = context.Request["agentId"] != null?Convert.ToInt32(context.Request["agentId"]) : 0;
                }

                //ticket.SelectedAgentId = context.Request["agentId"] != null ? Convert.ToInt32(context.Request["agentId"]) : 0;
                ticket.Id = context.Request["ticketId"] != null?Convert.ToInt64(context.Request["ticketId"]) : 0;

                ticket.Subject     = context.Request["subject"];
                ticket.StatusIds   = context.Request["statusIds"];
                ticket.PriorityIds = context.Request["priorityIds"];
                ticket.TicketType  = context.Request["ticketType"] != null?Convert.ToInt32(context.Request["ticketType"]) : 0;

                ticket.OverDueType = context.Request["overDueType"] != null?Convert.ToInt32(context.Request["overDueType"]) : 0;

                ticket.DurationType = context.Request["durationType"] != null?Convert.ToInt32(context.Request["durationType"]) : 0;

                ticket.CustomerId = context.Request["customerId"] != null?Convert.ToInt32(context.Request["customerId"]) : 0;

                ticket.FromDate  = context.Request["fromDate"];
                ticket.ToDate    = context.Request["toDate"];
                ticket.PageIndex = Convert.ToInt32(context.Request["pageIndex"]);
                ticket.PageSize  = Convert.ToInt32(context.Request["pageSize"]);
                ticket.IsStarred = context.Request["isStarred"] != null?Convert.ToBoolean(Convert.ToInt16(context.Request["isStarred"])) : Convert.ToBoolean(Convert.ToInt16(0));   //Convert.ToBoolean(Convert.ToInt16(context.Request["isStarred"]));

                ticket.CategoryId = context.Request["CategoryId"] != "0" ? Convert.ToInt32(context.Request["CategoryId"]) : 0;
                Press3.BusinessRulesLayer.Ticket ticketObj = new Press3.BusinessRulesLayer.Ticket();
                responseJObj = ticketObj.GetTicketsHistory(MyConfig.MyConnectionString, ticket);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            return(responseJObj);
        }
        private JObject GetTicketDetails(HttpContext context)
        {
            JObject responseJObj = new JObject();

            try
            {
                Press3.BusinessRulesLayer.Ticket ticketObj = new Press3.BusinessRulesLayer.Ticket();
                responseJObj = ticketObj.GetTicketDetails(MyConfig.MyConnectionString, accountId, Convert.ToInt32(context.Request["ticketId"]));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            return(responseJObj);
        }
        private JObject StarOrUnstarTicket(HttpContext context)
        {
            JObject responseJObj = new JObject();

            try
            {
                Press3.BusinessRulesLayer.Ticket ticketObj = new Press3.BusinessRulesLayer.Ticket();
                responseJObj = ticketObj.StarOrUnstarTicket(MyConfig.MyConnectionString, agentId, Convert.ToInt32(context.Request["ticketId"]), Convert.ToByte(context.Request["isStar"]));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            return(responseJObj);
        }
        private JObject CloseTickets(HttpContext context)
        {
            JObject responseJObj = new JObject();

            try
            {
                Press3.BusinessRulesLayer.Ticket ticketObj = new Press3.BusinessRulesLayer.Ticket();
                responseJObj = ticketObj.CloseTickets(MyConfig.MyConnectionString, agentId, context.Request["ticketIds"], context.Request["closureText"]);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            return(responseJObj);
        }
        private JObject MergeTickets(HttpContext context)
        {
            JObject responseJObj = new JObject();

            try
            {
                Press3.BusinessRulesLayer.Ticket ticketObj = new Press3.BusinessRulesLayer.Ticket();
                responseJObj = ticketObj.MergeTickets(MyConfig.MyConnectionString, agentId, context.Request["ticketIds"], Convert.ToInt32(context.Request["primaryTicketId"]));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            return(responseJObj);
        }
        private JObject GetTicketsToMerge(HttpContext context)
        {
            JObject responseJObj = new JObject();

            try
            {
                Press3.BusinessRulesLayer.Ticket ticketObj = new Press3.BusinessRulesLayer.Ticket();
                responseJObj = ticketObj.GetTicketsToMerge(MyConfig.MyConnectionString, context.Request["ticketIds"]);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            return(responseJObj);
        }
        private JObject GetTicketPriorities(HttpContext context)
        {
            JObject responseJObj = new JObject();

            try
            {
                Press3.BusinessRulesLayer.Ticket ticketObj = new Press3.BusinessRulesLayer.Ticket();
                responseJObj = ticketObj.GetTicketPriorities(MyConfig.MyConnectionString, accountId);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            return(responseJObj);
        }
        private JObject ManageTicketCategoryNodes(HttpContext context)
        {
            JObject responseJObj = new JObject();

            try
            {
                Press3.BusinessRulesLayer.Ticket ticketObj = new Press3.BusinessRulesLayer.Ticket();
                responseJObj = ticketObj.ManageTicketCategoryNodes(MyConfig.MyConnectionString, Convert.ToInt32(context.Request["Mode"]), accountId, context.Request["Category"].ToString(), Convert.ToInt32(context.Request["ParentId"]), context.Request["ColorCode"], agentId);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            return(responseJObj);
        }
        private JObject ManageTickets(HttpContext context)
        {
            JObject responseJObj = new JObject();

            try
            {
                UserDefinedClasses.Ticket ticketObj = new UserDefinedClasses.Ticket();
                ticketObj.Mode         = Convert.ToInt32(context.Request["Mode"]);
                ticketObj.AccountId    = accountId;
                ticketObj.AgentId      = agentId;
                ticketObj.PriorityId   = Convert.ToInt32(context.Request["PriorityId"]);
                ticketObj.Decscription = context.Request["Description"].ToString();
                if (Convert.ToInt32(context.Request["Mode"]) == 1)
                {
                    ticketObj.CategoryId = Convert.ToInt32(context.Request["CategoryId"]);
                    ticketObj.CustomerId = Convert.ToInt32(context.Request["CustomerId"]);
                    ticketObj.Subject    = context.Request["Topic"].ToString();
                    ticketObj.DueDate    = context.Request["DueDate"].ToString();
                    ticketObj.CallId     = Convert.ToInt32(context.Request["CallId"]);
                    ticketObj.IsOffline  = (context.Request["IsOffline"] != null && context.Request["IsOffline"] != "") ? Convert.ToBoolean(Convert.ToInt32(context.Request["IsOffline"])) : false;
                }
                else if (Convert.ToInt32(context.Request["Mode"]) == 2)
                {
                    ticketObj.Id        = Convert.ToInt32(context.Request["TicketId"]);
                    ticketObj.StatusIds = context.Request["StatusId"].ToString();
                    ticketObj.CallId    = (context.Request["CallId"] != null && context.Request["CallId"] != "") ? Convert.ToInt32(context.Request["CallId"]) : 0;
                }
                Press3.BusinessRulesLayer.Ticket ticketsObj = new Press3.BusinessRulesLayer.Ticket();
                responseJObj = ticketsObj.ManageTickets(MyConfig.MyConnectionString, ticketObj);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            return(responseJObj);
        }