Пример #1
0
        /// <summary>
        /// Read the proxy given the RefID
        /// </summary>
        public static T ReadRefTypeProxyByRefID <T>(int id) where T : class
        {
            T t = null;

            try
            {
                using (ConnectionContext connection = new ConnectionContext())
                {
                    switch (typeof(T).Name) // alphabetized list
                    {
                    case "UserPhotoAttachmentProxy":
                        t = Data_API.ReadRefTypeProxyByRefID <UserPhotoAttachmentProxy>(connection, id) as T;
                        break;

                    default:
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                // we use this method to check if it exists
                //int logid = Data_API.LogException(new IDTree.AuthenticationModel(), ex, "ReadByRefID Exception" + ex.Source);
            }
            return(t);
        }
        public void ActionAttachments()
        {
            string userData = _userScot;
            AuthenticationModel authentication = AuthenticationModel.AuthenticationModelTest(userData, _connectionString);

            using (ConnectionContext connection = new ConnectionContext(authentication))
            {
                // user ticket
                TicketProxy ticketProxy = IDTreeTest.EmptyTicket();                                   // from front end
                TicketModel ticketModel = (TicketModel)Data_API.Create(connection.User, ticketProxy); // dbo.Tickets

                // ticket action
                ActionProxy actionProxy = IDTreeTest.EmptyAction();                               // from front end
                ActionModel actionModel = (ActionModel)Data_API.Create(ticketModel, actionProxy); // dbo.Actions

                // action attachment
                ActionAttachmentProxy attachmentProxy = (ActionAttachmentProxy)IDTreeTest.CreateAttachment(connection.OrganizationID,
                                                                                                           AttachmentProxy.References.Actions, actionModel.ActionID, actionModel.AttachmentPath);
                AttachmentModel attachmentModel = (AttachmentModel)Data_API.Create(actionModel, attachmentProxy);

                // read back attachment
                AttachmentProxy read = Data_API.ReadRefTypeProxy <AttachmentProxy>(connection, attachmentProxy.AttachmentID);
                switch (read)
                {
                case ActionAttachmentProxy output:      // Action attachment
                    Assert.AreEqual(attachmentProxy, output);
                    break;

                default:
                    Assert.Fail();
                    break;
                }
            }
        }
Пример #3
0
        /// <summary> Subscriptions </summary>
        void MergeSubscriptions()
        {
            SubscriptionModel[] subscriptions = Source.Subscriptions();
            if (subscriptions.Length == 0)
            {
                return;
            }

            SubscriptionModel[] destinationSubscriptions = Destination.Subscriptions();
            foreach (SubscriptionModel subscriptionModel in subscriptions)
            {
                // WHERE NOT EXISTS(SELECT * FROM Subscriptions WHERE reftype = 17 AND RefID = {model.TicketID} AND UserID = {proxy.UserID})
                if (!destinationSubscriptions.Where(s => s.User.UserID == subscriptionModel.User.UserID).Any())
                {
                    SubscriptionProxy subscriptionProxy = new SubscriptionProxy()
                    {
                        RefType = ReferenceType.Tickets,
                        RefID   = Destination.TicketID,
                        UserID  = subscriptionModel.User.UserID
                    };
                    Data_API.Create(Destination, subscriptionProxy);
                }

                Data_API.Delete(subscriptionModel);
            }
        }
Пример #4
0
        void MergeRelationships()
        {
            TicketRelationshipProxy[] proxies = Data_API.Read <TicketRelationshipProxy[]>(Source);
            TicketRelationshipModel   idNode;

            foreach (TicketRelationshipProxy proxy in proxies)
            {
                switch (GetState(proxy))
                {
                case TicketRelationship.SourceIsDestination:
                    idNode = new TicketRelationshipModel(Source, Destination, proxy.TicketRelationshipID);
                    Data_API.Delete(idNode);       // circular reference
                    break;

                case TicketRelationship.SourceTicket2:
                    TicketModel ticket2 = new TicketModel(Source.Connection, proxy.Ticket2ID);
                    idNode = new TicketRelationshipModel(Source, ticket2, proxy.TicketRelationshipID);
                    Data_API.Update(idNode, new UpdateArguments("Ticket1ID", Destination.TicketID));
                    break;

                case TicketRelationship.Ticket1Source:
                    TicketModel ticket1 = new TicketModel(Source.Connection, proxy.Ticket1ID);
                    idNode = new TicketRelationshipModel(ticket1, Source, proxy.TicketRelationshipID);
                    Data_API.Update(idNode, new UpdateArguments("Ticket2ID", Destination.TicketID));
                    break;
                }
            }
        }
Пример #5
0
        public static TicketModel InsertTicket(UserModel user)
        {
            // new ticket
            TicketProxy inTicketProxy = EmptyTicket();
            TicketModel ticket        = (TicketModel)Data_API.Create(user, inTicketProxy); // user created a ticketD

            TicketProxy outTicketProxy = Data_API.Read <TicketProxy>(ticket);

            Assert.AreEqual(inTicketProxy, outTicketProxy);

            // Actions
            ActionModel[] actions = new ActionModel[4];
            for (int j = 0; j < 4; ++j)
            {
                // new action
                ActionProxy inActionProxy = EmptyAction();
                actions[j] = Data_API.Create(ticket, inActionProxy) as ActionModel;
                Assert.AreEqual(actions[j], ticket.Action(actions[j].ActionID));
                ActionProxy outActionProxy = Data_API.Read <ActionProxy>(actions[j]);
                Assert.AreEqual(inActionProxy, outActionProxy);
            }

            ActionModel[] readActions = ticket.Actions();
            CollectionAssert.AreEqual(actions, readActions);

            return(ticket);
        }
Пример #6
0
        /// <summary>
        /// DELETE
        /// </summary>
        //public static void Delete<T>(T proxy)
        //{
        //    try
        //    {
        //        using (ConnectionContext connection = new ConnectionContext())
        //        {
        //            switch (typeof(T).Name)
        //            {
        //                case "ActionProxy":
        //                    ActionProxy actionProxy = proxy as ActionProxy;
        //                    Data_API.Delete(new ActionModel(connection, actionProxy.ActionID));
        //                    break;
        //                case "AttachmentProxy":
        //                    AttachmentProxy attachmentProxy = proxy as AttachmentProxy;
        //                    Data_API.Delete(new AttachmentModel(connection, attachmentProxy.AttachmentID));
        //                    break;
        //            }
        //        }
        //    }
        //    catch (AuthenticationException ex)
        //    {
        //        // TODO - tell user they don't have permission
        //        Data_API.LogMessage(ActionLogType.Delete, ReferenceType.None, 0, "choke", ex);
        //    }
        //    catch (System.Data.ConstraintException ex)
        //    {
        //        // TODO - data integrity failure
        //        Data_API.LogMessage(ActionLogType.Delete, ReferenceType.None, 0, "choke", ex);
        //    }
        //    catch (Exception ex)
        //    {
        //        //int logid = DataAPI.Data_API.LogException(new Proxy.AuthenticationModel(authenticationTicket), ex, "Ticket Merge Exception:" + ex.Source);
        //        //return $"Error merging tickets. Exception #{logid}. Please report this to TeamSupport by either emailing [email protected], or clicking Help/Support Hub in the upper right of your account.";
        //    }
        //}



        #region Tickets
        public static string MergeTickets(int destinationTicketID, int sourceTicketID)
        {
            try
            {
                using (ConnectionContext connection = new ConnectionContext(true))    // use transaction
                {
                    try
                    {
                        TicketMerge merge = new TicketMerge(connection, connection.Ticket(destinationTicketID), connection.Ticket(sourceTicketID));
                        merge.Merge1();
                        connection.Commit();
                        return(String.Empty);
                    }
                    catch (Exception ex)
                    {
                        connection.Rollback();
                        int logid = Data_API.LogException(connection.Authentication, ex, "Ticket Merge Exception:" + ex.Source);
                        return($"Error merging tickets. Exception #{logid}. Please report this to TeamSupport by either emailing [email protected], or clicking Help/Support Hub in the upper right of your account.");
                    }
                }
            }
            catch (Exception ex)
            {
                int logid = Data_API.LogException(new IDTree.AuthenticationModel(), ex, "Ticket Merge Exception:" + ex.Source);
                return($"Error merging tickets. Exception #{logid}. Please report this to TeamSupport by either emailing [email protected], or clicking Help/Support Hub in the upper right of your account.");
            }
        }
Пример #7
0
 void MergeActions()
 {
     ActionModel[] actions = Source.Actions();
     foreach (ActionModel action in actions)
     {
         Data_API.Update(action, new UpdateArguments("TicketID", Destination.TicketID));
     }
 }
Пример #8
0
        void MergeReminders()
        {
            TicketReminderModel[] reminders = Source.Reminders();
            UpdateArguments       args      = new UpdateArguments("RefID", Destination.TicketID);

            foreach (TicketReminderModel reminderModel in reminders)
            {
                Data_API.Update(Destination, args);
            }
        }
Пример #9
0
        void MergeChildren()
        {
            //TODO: Think about when parentid = ticketid
            UpdateArguments args = new UpdateArguments("ParentID", Destination.TicketID);

            TicketModel[] children = Source.ChildTickets();
            foreach (TicketModel child in children)
            {
                Data_API.Update(child, args);
            }
        }
Пример #10
0
 public static string GetOrganizationAttachmentPath()
 {
     try
     {
         using (ConnectionContext connection = new ConnectionContext())
         {
             return(connection.Organization.AttachmentPath);
         }
     }
     catch (Exception ex)
     {
         Data_API.LogMessage(ActionLogType.Delete, ReferenceType.Attachments, 0, "Unable to find organization attachment path", ex);
     }
     return(String.Empty);
 }
Пример #11
0
 /// <summary>
 /// Get a list of all the action attachments for this ticket - include only the latest for each filename
 /// </summary>
 public static void ReadActionAttachmentsForTicket(int ticketID, ActionAttachmentsByTicketID ticketActionAttachments, out AttachmentProxy[] attachments)
 {
     attachments = null;
     try
     {
         using (ConnectionContext connection = new ConnectionContext())
         {
             TicketModel ticketModel = connection.Ticket(ticketID);
             AttachmentAPI.ReadActionAttachmentsForTicket(ticketModel, ticketActionAttachments, out attachments);
         }
     }
     catch (Exception ex)
     {
         Data_API.LogMessage(ActionLogType.Delete, ReferenceType.Attachments, ticketID, "failed to read action attachments", ex);
     }
 }
Пример #12
0
 /// <summary> Find all the organizations associated with a ticket </summary>
 public static OrganizationTicketModel[] GetOrganizationTickets(int ticketID)
 {
     try
     {
         using (ConnectionContext connection = new ConnectionContext())
         {
             TicketModel ticketModel = new TicketModel(connection, ticketID);
             return(OrganizationTicketModel.GetOrganizationTickets(ticketModel));
         }
     }
     catch (Exception ex)
     {
         Data_API.LogMessage(ActionLogType.Insert, ReferenceType.None, 0, "choke", ex);
     }
     return(null);
 }
Пример #13
0
 public static void CreateAttachment(AttachmentProxy attachment)
 {
     try
     {
         using (ConnectionContext connection = new ConnectionContext())
         {
             IAttachmentDestination model = ClassFactory(connection, attachment);
             Data_API.Create(model as IDNode, attachment);
         }
     }
     catch (Exception ex)
     {
         // TODO - tell user we failed
         Data_API.LogMessage(ActionLogType.Insert, (ReferenceType)attachment.RefType, 0, "choke", ex);
     }
 }
Пример #14
0
        /// <summary>
        /// CREATE
        /// </summary>
        public static void Create <T>(T proxy)
        {
            try
            {
                using (ConnectionContext connection = new ConnectionContext())
                {
                    switch (typeof(T).Name)
                    {
                    case "ActionProxy":
                    {
                        ActionProxy actionProxy = proxy as ActionProxy;
                        Data_API.Create(connection.Ticket(actionProxy.TicketID), actionProxy);
                    }
                    break;

                    case "AttachmentProxy":
                    {
                        AttachmentProxy        attachment = proxy as AttachmentProxy;
                        IAttachmentDestination model      = AttachmentAPI.ClassFactory(connection, attachment);
                        Data_API.Create(model as IDNode, attachment);
                    }
                    break;

                    default:
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                // TODO - tell user we failed to read
                Data_API.LogMessage(ActionLogType.Insert, ReferenceType.None, 0, "choke", ex);
            }
        }
Пример #15
0
        /// <summary>
        /// UPDATE
        /// </summary>
        public static void Update <T>(T proxy)
        {
            try
            {
                using (ConnectionContext connection = new ConnectionContext())
                {
                    switch (typeof(T).Name)
                    {
                    case "ActionProxy":
                        ActionProxy actionProxy = proxy as ActionProxy;
                        //DataAPI.DataAPI.Update(new ActionNode(connection, actionProxy.ActionID), actionProxy);
                        break;

                    case "AttachmentProxy":
                        AttachmentProxy attachmentProxy = proxy as AttachmentProxy;
                        UpdateArguments args            = new UpdateArguments();
                        args.Append("FileName", attachmentProxy.FileName);
                        args.Append("Path", attachmentProxy.Path);
                        args.Append("FilePathID", attachmentProxy.FilePathID.Value);
                        Data_API.Update(new AttachmentModel(connection, attachmentProxy), args);
                        break;

                    default:
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                // TODO - tell user we failed to read
                //int logid = DataAPI.Data_API.LogException(connection.Authentication, ex, "Ticket Merge Exception:" + ex.Source);
                //return $"Error merging tickets. Exception #{logid}. Please report this to TeamSupport by either emailing [email protected], or clicking Help/Support Hub in the upper right of your account.";
            }
        }
Пример #16
0
        /// <summary> Create attachment files </summary>
        public static List <AttachmentProxy> CreateAttachments(HttpContext context, out string _ratingImage)
        {
            List <AttachmentProxy> result = null;

            try
            {
                GetPathMap(context, out PathMap pathMap, out int refID, out _ratingImage);

                using (ConnectionContext connection = new ConnectionContext())
                {
                    // valid ID to add attachment
                    IAttachmentDestination model = ClassFactory(connection, pathMap._refType, refID);
                    HttpFileCollection     files = context.Request.Files;
                    result = new List <AttachmentProxy>();
                    for (int i = 0; i < files.Count; i++)
                    {
                        if (files[i].ContentLength <= 0)
                        {
                            continue;
                        }

                        AttachmentFile  attachmentFile = new AttachmentFile(model, files[i]);            // create the file
                        AttachmentProxy proxy          = AttachmentProxy.ClassFactory(pathMap._refType); // construct the proxy
                        proxy.RefID = refID;
                        InitializeProxy(context, connection, attachmentFile, proxy);
                        Data_API.Create(model as IDNode, proxy);  // save proxy to DB
                        result.Add(proxy);
                    }
                }
            }
            catch (Exception ex)
            {
                _ratingImage = null;
                // TODO - tell user we failed
                Data_API.LogMessage(ActionLogType.Insert, ReferenceType.None, 0, "choke", ex);
            }
            return(result);
        }
Пример #17
0
        /// <summary> TagLinks </summary>
        void MergeTagLinks()
        {
            TagLinkProxy[] sourceTagLinks = Data_API.Read <TagLinkProxy[]>(Source);
            if (sourceTagLinks.Length == 0)
            {
                return;
            }

            TagLinkProxy[] destinationTagLinks = Data_API.Read <TagLinkProxy[]>(Destination);
            foreach (TagLinkProxy tagLinkProxy in sourceTagLinks)
            {
                //// WHERE NOT EXISTS(SELECT* FROM TagLinks WITH (NOLOCK) WHERE RefID={destinationTicket.TicketID} AND TagID = {tag} AND Refype = 17)
                //if (!destinationTagLinks.Where(t => t.TagID == tagLinkProxy.TagID).Any())
                //{
                //    tagLinkProxy.RefID = Destination.TicketID;
                //    TagNode tag = new TagNode(Source.Organization, );
                //    DataAPI.DataAPI.Update(new TagLinkNode(Source, tag), tagLinkProxy);
                //    continue;
                //}

                //DataAPI.DataAPI.Delete(new TagLinkNode(Source, tagLinkProxy.TagLinkID));
            }
        }
Пример #18
0
        /// <summary> Merge1 </summary>
        public void Merge1()
        {
            if (!Connection.CanEdit()) // sufficient permissions?
            {
                return;
            }

            MergeAssets();
            MergeChildren();
            MergeContacts();
            MergeCustomers();
            MergeReminders();
            MergeTagLinks();
            MergeSubscriptions();
            MergeTaskAssociations();
            MergeRelationships();  // 1 and 2
            MergeQueuedTickets();
            MergeActions();

            Data_API.Delete(Source);
            //Source = null;
            //DataAPI.DataAPI.Update(Destination, null);  // update Date Modified
        }
Пример #19
0
        void MergeCustomers()
        {
            OrganizationTicketModel[] customers = Source.OrganizationTickets();
            if (customers.Length == 0)
            {
                return;
            }

            OrganizationTicketModel[] destinationCustomers = Destination.OrganizationTickets();
            foreach (OrganizationTicketModel customer in customers)
            {
                // WHERE NOT EXISTS(SELECT * FROM OrganizationTickets WHERE TicketID ={model.TicketID} and OrganizationId ={proxy.OrganizationID})
                if (!destinationCustomers.Where(c => c.Organization.OrganizationID == customer.Organization.OrganizationID).Any())
                {
                    CustomerProxy customerProxy = new CustomerProxy()
                    {
                        OrganizationID = customer.Organization.OrganizationID
                    };
                    Data_API.Create(Destination, customerProxy);
                }

                Data_API.Delete(customer);
            }
        }
Пример #20
0
        void MergeContacts()
        {
            UserTicketModel[] contacts = Source.UserTickets();
            if (contacts.Length == 0)
            {
                return;
            }

            UserTicketModel[] destinationContacts = Destination.UserTickets();
            foreach (UserTicketModel contact in contacts)
            {
                // WHERE NOT EXISTS(SELECT * FROM UserTickets WHERE TicketID ={model.TicketID} and UserID ={proxy.UserID})
                if (!destinationContacts.Where(c => c.User.UserID == contact.User.UserID).Any())
                {
                    ContactProxy contactProxy = new ContactProxy()
                    {
                        UserID = contact.User.UserID
                    };
                    Data_API.Create(Destination, contactProxy);
                }

                Data_API.Delete(contact);
            }
        }
Пример #21
0
        public static void CreateAttachment(string savePath, int organizationId, AttachmentProxy.References refType, int userID, System.Net.HttpWebResponse httpWebResponse)
        {
            try
            {
                using (ConnectionContext connection = new ConnectionContext())
                {
                    AttachmentProxy attachment = AttachmentProxy.ClassFactory(refType);
                    attachment.RefID          = userID;
                    attachment.OrganizationID = organizationId;
                    attachment.FileName       = Path.GetFileName(savePath);
                    attachment.Path           = savePath;
                    attachment.FileType       = string.IsNullOrEmpty(httpWebResponse.ContentType) ? "application/octet-stream" : httpWebResponse.ContentType;
                    attachment.FileSize       = httpWebResponse.ContentLength;

                    IAttachmentDestination model = ClassFactory(connection, attachment);
                    Data_API.Create(model as IDNode, attachment);
                }
            }
            catch (Exception ex)
            {
                // TODO - tell user we failed
                Data_API.LogMessage(ActionLogType.Insert, (ReferenceType)refType, 0, "choke", ex);
            }
        }
Пример #22
0
        void MergeAssets()
        {
            AssetTicketModel[] assetTickets = Source.AssetTickets();
            if (assetTickets.Length == 0)
            {
                return;
            }

            AssetTicketModel[] destinationAssetTickets = Destination.AssetTickets();
            UpdateArguments    args = new UpdateArguments("TicketID", Destination.TicketID);

            foreach (AssetTicketModel assetTicket in assetTickets)
            {
                // WHERE NOT EXISTS (Select AssetTickets WITH (NOLOCK) WHERE AssetId = {asset} AND TicketId ={sourceTicket.TicketID})
                if (!destinationAssetTickets.Where(a => a.Asset.AssetID == assetTicket.Asset.AssetID).Any())
                {
                    Data_API.Update(assetTicket, args);
                }
                else
                {
                    Data_API.Delete(assetTicket);
                }
            }
        }
Пример #23
0
        public static string DeleteAttachment(int attachmentID, AttachmentProxy.References verifyRefType, int?verifyRefID = null)
        {
            string result = null;

            try
            {
                using (ConnectionContext connection = new ConnectionContext())
                {
                    // validate args
                    AttachmentProxy proxy = Data_API.ReadRefTypeProxy <AttachmentProxy>(connection, attachmentID);
                    result = proxy.FileName;

                    if (verifyRefType == AttachmentProxy.References.None) // support delete no matter the type?
                    {
                        verifyRefType = proxy.RefType;
                    }

                    if (!verifyRefID.HasValue) // if no explicit refID provided, use the proxy
                    {
                        verifyRefID = proxy.RefID;
                    }

                    // type safe construction
                    IAttachmentDestination model = null;
                    switch (verifyRefType)
                    {
                    case AttachmentProxy.References.Actions:
                        model = new ActionModel(connection, verifyRefID.Value);
                        if (!(model as ActionModel).CanEdit())      // is user authorized to do the delete?
                        {
                            return(null);
                        }
                        break;

                    case AttachmentProxy.References.Assets:
                        model = new AssetModel(connection, verifyRefID.Value);
                        break;

                    //case AttachmentProxy.References.ChatAttachments:
                    //    break;
                    case AttachmentProxy.References.CompanyActivity:
                    {
                        int organizationID = connection._db.ExecuteQuery <int>($"Select RefID from Notes WITH (NOLOCK) WHERE NoteID = {verifyRefID.Value}").Min();
                        model = new NoteModel(new OrganizationModel(connection, organizationID), verifyRefID.Value);
                    }
                    break;

                    case AttachmentProxy.References.ContactActivity:
                    {
                        int userID = connection._db.ExecuteQuery <int>($"Select RefID from Notes WITH (NOLOCK) WHERE NoteID = {verifyRefID.Value}").Min();
                        model = new NoteModel(new UserModel(connection, userID), verifyRefID.Value);
                    }
                    break;

                    //case AttachmentProxy.References.Contacts:
                    //    break;
                    //case AttachmentProxy.References.CustomerHubLogo:
                    //    break;
                    //case AttachmentProxy.References.None:
                    //    break;
                    case AttachmentProxy.References.Organizations:
                        model = new OrganizationModel(connection, verifyRefID.Value);
                        break;

                    case AttachmentProxy.References.ProductVersions:
                        model = new ProductVersionModel(connection, verifyRefID.Value);
                        break;

                    case AttachmentProxy.References.Tasks:
                        model = new TaskModel(connection, verifyRefID.Value);
                        break;

                    case AttachmentProxy.References.UserPhoto:
                    case AttachmentProxy.References.Users:
                        model = new UserModel(connection, verifyRefID.Value);
                        break;

                    case AttachmentProxy.References.WaterCooler:
                        model = new WatercoolerMsgModel(connection, verifyRefID.Value);
                        break;

                    default:
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                        throw new Exception($"unrecognized RefType {verifyRefType} in DeleteAttachment");
                    }

                    // do the delete
                    Data_API.Delete(new AttachmentModel(model, attachmentID));
                    AttachmentFile file = new AttachmentFile(model, proxy);
                    file.Delete();
                }
            }
            catch (Exception ex)
            {
                Data_API.LogMessage(ActionLogType.Delete, ReferenceType.Attachments, attachmentID, "Unable to delete attachment", ex);
            }
            return(result);
        }
Пример #24
0
        /// <summary>
        /// READ - read the proxy corresponding to the ID
        /// </summary>
        public static T Read <T>(int id) where T : class
        {
            T t = default(T);

            try
            {
                using (ConnectionContext connection = new ConnectionContext())
                {
                    switch (typeof(T).Name) // alphabetized list
                    {
                    case "ActionProxy":
                    {
                        Table <ActionProxy> table = connection._db.GetTable <ActionProxy>();
                        var q = from action in table where action.ActionID == id select action;
                        t = q.Single() as T;
                    }

                        //string query = $"SET NOCOUNT OFF; SELECT [ActionID], [ActionTypeID], [SystemActionTypeID], [Name], [TimeSpent], [DateStarted], [IsVisibleOnPortal], [IsKnowledgeBase], [ImportID], [DateCreated], [DateModified], [CreatorID], [ModifierID], [TicketID], [ActionSource], [DateModifiedBySalesForceSync], [SalesForceID], [DateModifiedByJiraSync], [JiraID], [Pinned], [Description], [IsClean], [ImportFileID] FROM [dbo].[Actions] WITH (NOLOCK) WHERE ([ActionID] = {id})";
                        //IEnumerable<ActionProxy> stuff = connection._db.ExecuteQuery<ActionProxy>(query);

                        //ActionProxy proxy = connection._db.ExecuteQuery<ActionProxy>(query).Min();

                        //t = new ActionNode(connection, id).ActionProxy() as T;
                        ////t = DataAPI.DataAPI.Read<T>(new ActionNode(connection, id));
                        break;

                    case "ActionProxy[]":
                        t = new TicketModel(connection, id).ActionProxies() as T;
                        //t = DataAPI.DataAPI.Read<T>(new TicketNode(connection, id));
                        break;

                    case "AttachmentProxy":
                        t = Data_API.ReadRefTypeProxy <AttachmentProxy>(connection, id) as T;
                        break;

                    case "AttachmentProxy[]":
                        t = Data_API.Read <T>(new ActionModel(connection, id));
                        break;

                    //case CustomValueProxy proxy:
                    //    t = Data_API.Read<T>(new TicketModel(connection, id));
                    //    break;
                    case "TicketProxy":
                        t = Data_API.Read <T>(new TicketModel(connection, id));
                        break;

                    case "UserProxy":
                    {
                        Table <UserProxy> table = connection._db.GetTable <UserProxy>();
                        var q = from user in table where user.UserID == id select user;
                        t = q.Single() as T;
                    }                                    //t = DataAPI.DataAPI.Read<T>(new UserNode(connection, id));
                    break;

                    default:
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                int logid = Data_API.LogException(new IDTree.AuthenticationModel(), ex, "Ticket Merge Exception:" + ex.Source);
            }
            return(t);
        }