public Ticket CreateTicket(Account Account, Contact Contact, string Title, string Description, DateTimeOffset DueDate, string Source, string Status, string Priority, string Queue, string WorkType) { Ticket _result = null; if (String.IsNullOrWhiteSpace(Title)) { Title = "Empty subject line"; } if (string.IsNullOrWhiteSpace(Description)) { Description = "Empty message contents"; } if (Account == null || DueDate == null || string.IsNullOrWhiteSpace(Source) || string.IsNullOrWhiteSpace(Status) || string.IsNullOrWhiteSpace(Priority) || string.IsNullOrWhiteSpace(Queue) || string.IsNullOrWhiteSpace(WorkType)) { throw new ArgumentNullException(); } try { _result = new Ticket() { AccountID = Account.id, DueDateTime = DueDate.LocalDateTime, Priority = Convert.ToInt32(PickListValueFromField(ticket_fieldInfo.GetFieldInfoResult, "Priority", Priority)), Status = Convert.ToInt32(PickListValueFromField(ticket_fieldInfo.GetFieldInfoResult, "Status", Status)), QueueID = Convert.ToInt32(PickListValueFromField(ticket_fieldInfo.GetFieldInfoResult, "QueueID", Queue)), Source = Convert.ToInt32(PickListValueFromField(ticket_fieldInfo.GetFieldInfoResult, "Source", Source)), AllocationCodeID = allocationCodes_WorkType.Exists(_code => Convert.ToString(_code.Name) == WorkType) ? allocationCodes_WorkType.First(_code => Convert.ToString(_code.Name) == WorkType).id : new long?(), ContactID = (Contact != null) ? Convert.ToInt32(Contact.id) : new int?(), // ternary null bug work around: new int?() Title = Title.Substring(0, Title.Length > 255 ? 255 : Title.Length), Description = Description.Substring(0, Description.Length > 8000 ? 8000 : Description.Length), }; } catch (Exception _ex) { _result = null; throw new ArgumentException("Unable to build ticket request. Please review InnerException.", _ex); } try { if (_result != null) { createResponse _response = _atwsServicesClient.create(new createRequest(_atwsIntegrations, new Entity[] { _result })); if (_response.createResult.ReturnCode > 0 && _response.createResult.EntityResults.Length > 0) { _result = (Ticket)_response.createResult.EntityResults[0]; } else if (_response.createResult.ReturnCode <= 0 && _response.createResult.EntityResults.Length == 0 && _response.createResult.Errors.Count() > 0) { throw new CommunicationException(_response.createResult.Errors[0].Message); } else { throw new CommunicationException("AutotaskAPIClient.CreateTicketNote() UNKNOWN ERROR"); } } } catch (Exception _ex) { _result = null; throw new CommunicationException("Unable to create ticket. Please review InnerException.", _ex); } return(_result); }
public TicketNote CreateTicketNote(Ticket Ticket, Resource ImpersonateResource, string Title, string Description, string Type, string Publish) { TicketNote _result = null; if (String.IsNullOrWhiteSpace(Title)) { Title = "Empty subject line"; } if (string.IsNullOrWhiteSpace(Description)) { Description = "Empty message contents"; } if (Ticket == null || string.IsNullOrWhiteSpace(Type) || string.IsNullOrWhiteSpace(Publish)) { throw new ArgumentNullException(); } try { _result = new TicketNote() { TicketID = Convert.ToInt32(Ticket.id), Title = Title.Substring(0, Title.Length > 250 ? 250 : Title.Length), Description = Description.Substring(0, Description.Length > 3200 ? 3200 : Description.Length), NoteType = Convert.ToInt32(PickListValueFromField(ticketNote_fieldInfo.GetFieldInfoResult, "NoteType", Type)), Publish = Convert.ToInt32(PickListValueFromField(ticketNote_fieldInfo.GetFieldInfoResult, "Publish", Publish)), }; } catch (Exception _ex) { _result = null; throw new ArgumentException("Unable to build ticketnote request. Please review InnerException.", _ex); } try { if (_result != null) { _atwsIntegrations.ImpersonateAsResourceID = ImpersonateResource != null ? (int)ImpersonateResource.id : 0; _atwsIntegrations.ImpersonateAsResourceIDSpecified = _atwsIntegrations.ImpersonateAsResourceID == 0 ? false : true; createResponse _response = _atwsServicesClient.create(new createRequest(_atwsIntegrations, new Entity[] { _result })); _atwsIntegrations.ImpersonateAsResourceID = 0; _atwsIntegrations.ImpersonateAsResourceIDSpecified = false; if (_response.createResult.ReturnCode > 0 && _response.createResult.EntityResults.Length > 0) { _result = (TicketNote)_response.createResult.EntityResults[0]; } else if (_response.createResult.ReturnCode <= 0 && _response.createResult.EntityResults.Length == 0 && _response.createResult.Errors.Count() > 0) { throw new CommunicationException(_response.createResult.Errors[0].Message); } else { throw new CommunicationException("AutotaskAPIClient.CreateTicketNote() UNKNOWN ERROR"); } } } catch (Exception _ex) { _result = null; throw new CommunicationException("Unable to create ticketnote. Please review InnerException.", _ex); } return(_result); }