Exemplo n.º 1
0
        public static void Update(IDNode node, UpdateArguments args)
        {
            // TODO - set DateModified, ModifierID...
            string modification = $", ModifierID={node.Connection.UserID}, DateModified={UpdateArguments.ToSql(DateTime.UtcNow)}";

            string command = String.Empty;

            switch (node) // alphabetized list
            {
            case ActionModel model:
                command = $"UPDATE Actions WITH(ROWLOCK) SET {args.ToString()} WHERE ActionID={model.ActionID}";
                break;

            case AttachmentModel model:
                command = $"UPDATE Attachments WITH(ROWLOCK) SET {args.ToString()} WHERE AttachmentID={model.AttachmentID}";
                break;

            case TagLinkModel model:
                command = $"UPDATE TagLinks WITH(ROWLOCK) SET {args.ToString()} WHERE TagLinkID={model.TagLinkID} AND RefType=17";
                break;

            case TaskAssociationModel model:
                command = $"UPDATE TaskAssociations SET {args.ToString()} WHERE TaskID={model.Task.TaskID} AND RefType=17";
                break;

            case TicketModel model:
                command = $"UPDATE Tickets SET {args.ToString()} WHERE TicketID= {model.TicketID}";
                break;

            case TicketReminderModel model:
                command = $" UPDATE Reminders WITH(ROWLOCK) SET {args.ToString()} WHERE ReminderID={model.ReminderID} AND RefType=17";
                break;

            case null:
            default:
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                break;
            }
            node.ExecuteCommand(command);
            // TODO - Log
        }
Exemplo n.º 2
0
        /// <summary>
        /// CREATE - create proxy child for model parent
        /// </summary>
        public static IDNode Create <TProxy>(IDNode idNode, TProxy tProxy) where TProxy : class
        {
            IDNode result = null;

            if (TryCreateAttachment(idNode as IAttachmentDestination, tProxy as AttachmentProxy, out result))
            {
                return(result);
            }

            string modification = $", CreatorID={idNode.Connection.UserID}, DateCreated={UpdateArguments.ToSql(DateTime.UtcNow)}";
            string now          = UpdateArguments.ToSql(DateTime.UtcNow);
            int    creatorID    = idNode.Connection.UserID;
            string command      = String.Empty;

            switch (tProxy) // alphabetized list
            {
            case ActionProxy proxy:
            {
                TicketModel model = (TicketModel)idNode;
                proxy.TicketID    = model.TicketID;
                proxy.CreatorID   = proxy.ModifierID = model.Connection.UserID;
                proxy.DateCreated = proxy.DateModified = DateTime.UtcNow;

                // 1. sql command
                //command = proxy.InsertCommandText();
                //SqlCommand sqlCommand = new SqlCommand(command, model.Connection._connection);
                //int id = Decimal.ToInt32((decimal)sqlCommand.ExecuteScalar());
                //result = new ActionModel(model, id);    // how to bypass Verify?

                // 2. linq
                DataContext         db    = model.Connection._db;
                Table <ActionProxy> table = db.GetTable <ActionProxy>();
                table.InsertOnSubmit(proxy);
                db.SubmitChanges();

                // 3. TeamSupport.Data
                //proxy.ActionID = NewAction(model, proxy);

                result = new ActionModel(model, proxy.ActionID);            // how to bypass Verify?
            }
            break;

            case ContactProxy proxy:
            {
                TicketModel model = (TicketModel)idNode;
                command = $"INSERT INTO UserTickets (TicketID, UserID, DateCreated, CreatorID)" +
                          $"SELECT {model.TicketID}, {proxy.UserID}, '{now}', {creatorID} ";
            }
            break;

            case CustomerProxy proxy:
            {
                TicketModel model = (TicketModel)idNode;
                command = $"INSERT INTO OrganizationTickets (TicketID, OrganizationID, DateCreated, CreatorID, DateModified, ModifierID)" +
                          $"SELECT {model.TicketID}, {proxy.OrganizationID}, '{now}', {creatorID}, '{now}', {creatorID}";
            }
            break;

            case SubscriptionProxy proxy:
            {
                TicketModel model = (TicketModel)idNode;
                command = $"INSERT INTO Subscriptions (RefType, RefID, UserID, DateCreated, DateModified, CreatorID, ModifierID)" +
                          $"SELECT 17, {model.TicketID}, {proxy.UserID}, '{now}','{now}', {creatorID}, {creatorID} ";
            }
            break;

            case TicketProxy proxy:
            {
                UserModel model = (UserModel)idNode;
                proxy.OrganizationID = model.Organization.OrganizationID;
                proxy.CreatorID      = proxy.ModifierID = model.UserID;
                proxy.UserID         = model.Connection.UserID;
                proxy.DateCreated    = proxy.DateModified = DateTime.UtcNow;
                proxy.TicketNumber   = 1 + model.ExecuteQuery <int>($"SELECT MAX(TicketNumber) FROM Tickets WHERE OrganizationID={model.Organization.OrganizationID}").Max();

                // 1. sql command
                //command = proxy.InsertCommandText(proxy.TicketNumber);
                //SqlCommand sqlCommand = new SqlCommand(command, model.Connection._connection);
                //int id = Decimal.ToInt32((decimal)sqlCommand.ExecuteScalar());
                //result = new TicketModel(model.Organization, id);    // how to bypass Verify?

                // 2. linq
                DataContext         db    = model.Organization.Connection._db;
                Table <TicketProxy> table = db.GetTable <TicketProxy>();
                table.InsertOnSubmit(proxy);
                db.SubmitChanges();

                // 3. TeamSupport.Data
                //proxy.TicketID = NewTicket(model, proxy);

                result = new TicketModel(model.Organization, proxy.TicketID);            // how to bypass Verify? - move to UserModel?
            }
            break;

            case null:
            default:
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                break;
            }

            //if (!String.IsNullOrEmpty(command))
            //    idNode.ExecuteCommand(command);
            // TODO - log
            return(result);
        }