public Ticket GetTicket(Session session, int ticketId) { Ticket ticket = null; using (var select = Select(GetTicketQuery, Config.Get("mysql_db"), session.AccountId, ticketId, "EST")) { if (select.Read()) { ticket = new Ticket(select.GetInt32(0)) { CreatedDate = select.IsDBNull(1) ? null : select.GetString(1), ClosedDate = select.IsDBNull(2) ? null : select.GetString(2), DueDate = select.IsDBNull(3) ? null : select.GetString(3), FirstTouchDate = select.IsDBNull(5) ? null : select.GetString(5), Status = (TICKET_STATUS)select.GetInt32(6), OpenedById = select.IsDBNull(7) ? null : new int?(select.GetInt32(7)), OpenedByUsername = select.IsDBNull(8) ? null : select.GetString(8), OpenedByName = select.IsDBNull(9) ? null : select.GetString(9), ClosedById = select.IsDBNull(10) ? null : new int?(select.GetInt32(10)), ClosedByUsername = select.IsDBNull(11) ? null : select.GetString(11), ClosedByName = select.IsDBNull(12) ? null : select.GetString(12), Subject = select.IsDBNull(13) ? null : select.GetString(13), AccountId = select.GetInt32(14), FormId = select.GetInt32(15), FormName = select.IsDBNull(16) ? null : select.GetString(16), UpdatedDate = select.IsDBNull(17) ? null : select.GetString(17), AssignedId = select.IsDBNull(18) ? null : new int?(select.GetInt32(18)), AssignedUsername = select.IsDBNull(19) ? null : select.GetString(19), AssignedName = select.IsDBNull(20) ? null : select.GetString(20), ClientGuid = select.IsDBNull(21) ? null : select.GetString(21), ContactId = select.IsDBNull(22) ? null : new int?(select.GetInt32(22)), ContactUsername = select.IsDBNull(23) ? null : select.GetString(23), ContactName = select.IsDBNull(24) ? null : select.GetString(24), ReasonId = select.IsDBNull(25) ? null : new int?(select.GetInt32(25)), ParentId = select.IsDBNull(26) ? null : new int?(select.GetInt32(26)), Priority = select.IsDBNull(27) ? null : new int?(select.GetInt32(27)), LockedById = select.IsDBNull(28) ? null : new int?(select.GetInt32(28)), SourceType = select.IsDBNull(29) ? null : select.GetString(29) }; } } if (ticket == null) { return(null); } ticket.Permissions = new TicketPermissions(formData.GetPermissionsForForm(session, ticket.FormId)); ticket.History = GetTicketHistory(session, ticketId); ticket.Comments = commentData.GetCommentsForTicket(session, ticketId, ticket.Permissions); if (ticket.AssignedId == session.UserId) { ticket.Permissions.CanView = true; ticket.Permissions.CanComment = true; } foreach (var e in ticket.History) { if (e.UserId == session.UserId) { ticket.Permissions.CanView = true; ticket.Permissions.CanComment = true; break; } } return(ticket); }