public void CreateDeleteTicketPosts()
        {
            DepartmentCollection depts = TestSetup.KayakoApiService.Departments.GetDepartments();
            StaffUserCollection staff = TestSetup.KayakoApiService.Staff.GetStaffUsers();
            StaffUser randomStaffUser = staff[new Random().Next(staff.Count)];
            TicketCollection tickets = TestSetup.KayakoApiService.Tickets.GetTickets(depts.Select(d => d.Id).ToArray());
            Ticket randomTicket = tickets[new Random().Next(tickets.Count)];

            string subject = "New Post Subject";
            string contents = "This will be the contents";

            TicketPostRequest request = new TicketPostRequest()
            {
                TicketId = randomTicket.Id,
                Subject = subject,
                Contents = contents,
                StaffId = randomStaffUser.Id,
                IsPrivate = false
            };

            TicketPost createdPost = TestSetup.KayakoApiService.Tickets.AddTicketPost(request);

            Assert.IsNotNull(createdPost);
            Assert.AreEqual(createdPost.StaffId, randomStaffUser.Id);
            //Assert.AreEqual(createdPost.Contents, String.Format("{0}\n{1}", contents, randomStaffUser.Signature));

            //Subject?

            bool success = TestSetup.KayakoApiService.Tickets.DeleteTicketPost(randomTicket.Id, createdPost.Id);

            Assert.IsTrue(success);
        }
 public static TicketPost ToResponseData(TicketPostRequest requestData)
 {
     return TicketPostRequest.ToResponseType<TicketPostRequest, TicketPost>(requestData);
 }
 public static TicketPost ToResponseData(TicketPostRequest requestData)
 {
     return(TicketPostRequest.ToResponseType <TicketPostRequest, TicketPost>(requestData));
 }
 public static TicketPostRequest FromResponseData(TicketPost responseData)
 {
     return(TicketPostRequest.FromResponseType <TicketPost, TicketPostRequest>(responseData));
 }
        /// <summary>
		/// Add a new post to an existing ticket.. Only <paramref name="userid"/> or <paramref name="staffid"/> should be set.
		/// <remarks>
		/// See - http://wiki.kayako.com/display/DEV/REST+-+TicketPost#REST-TicketPost-POST%2FTickets%2FTicketPost
		/// </remarks>
		/// </summary>
		/// <param name="ticketid">The unique numeric identifier of the ticket</param>
		/// <param name="subject">The ticket post subject.</param>
		/// <param name="contents">The ticket post contents</param>
		/// <param name="userid">The User Id, if the ticket post is to be created as a user</param>
		/// <param name="staffid">The Staff Id, if the ticket post is to be created as a staff.</param>
		/// <returns></returns>
		public TicketPost AddTicketPost(TicketPostRequest request)
		{
            string apiMethod = "/Tickets/TicketPost";

            request.EnsureValidData(RequestTypes.Create);

			RequestBodyBuilder parameters = new RequestBodyBuilder();

            parameters.AppendRequestData("ticketid", request.TicketId);
            parameters.AppendRequestData("subject", request.Subject);
            parameters.AppendRequestData("contents", request.Contents);

            if (request.UserId == null && request.StaffId == null)
			{
				throw new ArgumentException("Neither UserId nor StaffId are set, one of these fields are required field and cannot be null.");
			}

            if (request.UserId != null && request.StaffId != null)
			{
				throw new ArgumentException("UserId are StaffId are both set, only one of these fields must be set.");
			}

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

            if (request.StaffId != null)
			{
                parameters.AppendRequestData("staffid", request.StaffId.Value);

				if (request.IsPrivate != null)
				{
					parameters.AppendRequestDataBool("isprivate", request.IsPrivate.Value);
				}
			}

			TicketPostCollection posts = Connector.ExecutePost<TicketPostCollection>(apiMethod, parameters.ToString());

			if (posts.Count > 0)
			{
				return posts[0];
			}

			return null;
		}