Esempio n. 1
0
        public Ticket CreateTicket(TicketRequest ticketRequest)
        {
            const string apiMethod = "/Tickets/Ticket";

            ticketRequest.EnsureValidData(RequestTypes.Create);

            var parameters = new RequestBodyBuilder();

            parameters.AppendRequestData("subject", ticketRequest.Subject);
            parameters.AppendRequestData("fullname", ticketRequest.FullName);
            parameters.AppendRequestData("email", ticketRequest.Email);
            parameters.AppendRequestData("contents", ticketRequest.Contents);
            parameters.AppendRequestData("departmentid", ticketRequest.DepartmentId);
            parameters.AppendRequestData("ticketstatusid", ticketRequest.TicketStatusId);
            parameters.AppendRequestData("ticketpriorityid", ticketRequest.TicketPriorityId);
            parameters.AppendRequestData("tickettypeid", ticketRequest.TicketTypeId);

            if (ticketRequest.AutoUserId != null)
            {
                parameters.AppendRequestData("autouserid", Convert.ToInt32(ticketRequest.AutoUserId));
            }
            else if (ticketRequest.UserId != null)
            {
                parameters.AppendRequestData("userid", ticketRequest.UserId);
            }
            else if (ticketRequest.StaffId != null)
            {
                parameters.AppendRequestData("staffid", ticketRequest.StaffId);
            }

            if (ticketRequest.OwnerStaffId != null)
            {
                parameters.AppendRequestData("ownerstaffid", ticketRequest.OwnerStaffId);
            }

            if (ticketRequest.TemplateGroupId != null)
            {
                parameters.AppendRequestData("templategroup", ticketRequest.TemplateGroupId);
            }
            else if (!string.IsNullOrEmpty(ticketRequest.TemplateGroupName))
            {
                parameters.AppendRequestData("templategroup", ticketRequest.TemplateGroupName);
            }

            if (ticketRequest.IgnoreAutoResponder != null)
            {
                parameters.AppendRequestData("ignoreautoresponder", Convert.ToInt32(ticketRequest.IgnoreAutoResponder));
            }

            if (ticketRequest.CreationType != null)
            {
                parameters.AppendRequestData("type", EnumUtility.ToApiString(ticketRequest.CreationType));
            }

            var tickets = this.Connector.ExecutePost <TicketCollection>(apiMethod, parameters.ToString());

            return(tickets.Count > 0 ? tickets[0] : null);
        }
        public Ticket UpdateTicket(TicketRequest request)
        {
            request.EnsureValidData(RequestTypes.Update);

            RequestBodyBuilder parameters = new RequestBodyBuilder();

            if (!String.IsNullOrEmpty(request.Subject))
            {
                parameters.AppendRequestData("subject", request.Subject);
            }

            if (!String.IsNullOrEmpty(request.FullName))
            {
                parameters.AppendRequestData("fullname", request.FullName);
            }

            if (!String.IsNullOrEmpty(request.Email))
            {
                parameters.AppendRequestData("email", request.Email);
            }

            if (request.DepartmentId != null)
            {
                parameters.AppendRequestData("departmentid", request.DepartmentId);
            }

            if (request.TicketStatusId != null)
            {
                parameters.AppendRequestData("ticketstatusid", request.TicketStatusId);
            }

            if (request.TicketPriorityId != null)
            {
                parameters.AppendRequestData("ticketpriorityid", request.TicketPriorityId);
            }

            if (request.TicketTypeId != null)
            {
                parameters.AppendRequestData("tickettypeid", request.TicketTypeId);
            }

            if (request.OwnerStaffId != null)
            {
                parameters.AppendRequestData("ownerstaffid", request.OwnerStaffId);
            }

            if (request.UserId != null)
            {
                parameters.AppendRequestData("userid", request.UserId);
            }

            if (request.TemplateGroupId != null)
            {
                parameters.AppendRequestData("templategroup", request.TemplateGroupId);
            }
            else if (!string.IsNullOrEmpty(request.TemplateGroupName))
            {
                parameters.AppendRequestData("templategroup", request.TemplateGroupName);
            }

            string apiMethod = String.Format("/Tickets/Ticket/{0}", request.Id);

            TicketCollection tickets = Connector.ExecutePut <TicketCollection>(apiMethod, parameters.ToString());

            if (tickets != null && tickets.Count > 0)
            {
                return(tickets[0]);
            }

            return(null);
        }