Beispiel #1
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L3NT_SN_0921 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Base();
            //Put your code here
            ORM_USR_Account noteCreatorAccount = new ORM_USR_Account();
            noteCreatorAccount.Load(Connection, Transaction, Parameter.CreatorID);
            if (Parameter.ProjectNoteID != Guid.Empty)
            {
                if (Parameter.IsDeleted)
                {
                    ORM_CMN_NoteRevision.Query noteRevisionsQuery = new ORM_CMN_NoteRevision.Query();
                    noteRevisionsQuery.Note_RefID = Parameter.NoteID;
                    noteRevisionsQuery.IsDeleted  = false;


                    List <ORM_CMN_NoteRevision> existingRevisions = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, noteRevisionsQuery);
                    if (existingRevisions.Count > 1)
                    {
                        existingRevisions = existingRevisions.Where(er => er.CMN_NoteRevisionID != Parameter.NoteRevisionID).OrderBy(er => er.Version).ToList();
                        noteRevisionsQuery.CMN_NoteRevisionID = Parameter.NoteRevisionID;
                        ORM_CMN_NoteRevision.Query.SoftDelete(Connection, Transaction, noteRevisionsQuery);

                        ORM_CMN_Note parentNote = new ORM_CMN_Note();
                        parentNote.Load(Connection, Transaction, Parameter.NoteID);
                        parentNote.Current_NoteRevision_RefID = existingRevisions.Last().CMN_NoteRevisionID;
                        parentNote.Save(Connection, Transaction);
                    }
                    else
                    {
                        ORM_CMN_Note.Query cmnNoteQuery = new ORM_CMN_Note.Query();
                        cmnNoteQuery.CMN_NoteID = Parameter.NoteID;
                        ORM_CMN_Note.Query.SoftDelete(Connection, Transaction, cmnNoteQuery);

                        ORM_TMS_PRO_Project_Notes.Query projectNotesQuery = new ORM_TMS_PRO_Project_Notes.Query();
                        projectNotesQuery.Ext_CMN_Note_RefID = Parameter.NoteID;
                        ORM_TMS_PRO_Project_Notes.Query.SoftDelete(Connection, Transaction, projectNotesQuery);

                        ORM_CMN_NoteRevision.Query.SoftDelete(Connection, Transaction, noteRevisionsQuery);

                        ORM_TMS_PRO_Project_Note_Collaborators.Query notesCollaboratorQuery = new ORM_TMS_PRO_Project_Note_Collaborators.Query();
                        notesCollaboratorQuery.ProjectNote_RefID = Parameter.ProjectNoteID;
                        ORM_TMS_PRO_Project_Note_Collaborators.Query.SoftDelete(Connection, Transaction, notesCollaboratorQuery);

                        ORM_TMS_PRO_Project_Note_2_Tag.Query note2tagQuery = new ORM_TMS_PRO_Project_Note_2_Tag.Query();
                        note2tagQuery.Project_Note_RefID = Parameter.ProjectNoteID;
                        ORM_TMS_PRO_Project_Note_2_Tag.Query.SoftDelete(Connection, Transaction, note2tagQuery);
                    }
                }
                else
                {
                    ORM_TMS_PRO_Project_Notes existingProjectNote = new ORM_TMS_PRO_Project_Notes();
                    existingProjectNote.Load(Connection, Transaction, Parameter.ProjectNoteID);
                    ORM_CMN_NoteRevision existingNoteVersion = new ORM_CMN_NoteRevision();
                    existingNoteVersion.Load(Connection, Transaction, Parameter.NoteRevisionID);
                    if (Parameter.SaveAsNewVersion)
                    {
                        ORM_CMN_NoteRevision.Query RevisionCountQuery = new ORM_CMN_NoteRevision.Query();
                        RevisionCountQuery.Note_RefID = Parameter.NoteID;

                        ORM_CMN_NoteRevision newNoteVersion = new ORM_CMN_NoteRevision();
                        newNoteVersion.CreatedBy_BusinessParticipant_RefID = noteCreatorAccount.BusinessParticipant_RefID;
                        newNoteVersion.Content      = Parameter.Content;
                        newNoteVersion.Note_RefID   = Parameter.NoteID;
                        newNoteVersion.Tenant_RefID = securityTicket.TenantID;
                        newNoteVersion.Version      = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, RevisionCountQuery).Count + 1;
                        newNoteVersion.Title        = Parameter.Title;
                        newNoteVersion.Save(Connection, Transaction);
                        if (Parameter.ReplaceCreator)
                        {
                            //Find current creator of note and make him a collaborator to this note
                            ORM_USR_Account.Query currentCreatorQuery = new ORM_USR_Account.Query();
                            currentCreatorQuery.BusinessParticipant_RefID = existingNoteVersion.CreatedBy_BusinessParticipant_RefID;
                            currentCreatorQuery.IsDeleted    = false;
                            currentCreatorQuery.Tenant_RefID = securityTicket.TenantID;
                            ORM_USR_Account currentCreator = ORM_USR_Account.Query.Search(Connection, Transaction, currentCreatorQuery).FirstOrDefault();

                            ORM_TMS_PRO_Project_Note_Collaborators.Query noteCollaboratorQuery = new ORM_TMS_PRO_Project_Note_Collaborators.Query();
                            noteCollaboratorQuery.ProjectNote_RefID = Parameter.ProjectNoteID;
                            noteCollaboratorQuery.IsDeleted         = false;
                            noteCollaboratorQuery.Account_RefID     = noteCreatorAccount.USR_AccountID;
                            if (ORM_TMS_PRO_Project_Note_Collaborators.Query.Exists(Connection, Transaction, noteCollaboratorQuery))
                            {
                                //If current creator was collaborator on existing note, delete him, because he has the role of creator now, and
                                //old creator will be added to collaborators.
                                ORM_TMS_PRO_Project_Note_Collaborators.Query.SoftDelete(Connection, Transaction, noteCollaboratorQuery);
                            }
                            ORM_TMS_PRO_Project_Note_Collaborators newNoteCollaborator = new ORM_TMS_PRO_Project_Note_Collaborators();
                            newNoteCollaborator.Account_RefID     = currentCreator.USR_AccountID;
                            newNoteCollaborator.ProjectNote_RefID = Parameter.ProjectNoteID;
                            newNoteCollaborator.Tenant_RefID      = securityTicket.TenantID;
                            newNoteCollaborator.Save(Connection, Transaction);

                            ORM_CMN_Note.Query cmnNoteCreatorUpdateFind = new ORM_CMN_Note.Query();
                            cmnNoteCreatorUpdateFind.CMN_NoteID = Parameter.NoteID;
                            ORM_CMN_Note.Query cmnNoteCreatorUpdate = new ORM_CMN_Note.Query();
                            cmnNoteCreatorUpdate.CreatedBy_BusinessParticipant_RefID = noteCreatorAccount.BusinessParticipant_RefID;
                            ORM_CMN_Note.Query.Update(Connection, Transaction, cmnNoteCreatorUpdateFind, cmnNoteCreatorUpdate);
                        }
                    }
                    else
                    {
                        existingNoteVersion.Content = Parameter.Content;
                        existingNoteVersion.Title   = Parameter.Title;
                        existingNoteVersion.Save(Connection, Transaction);

                        if (existingProjectNote.Project_RefID != Parameter.ProjectID)
                        {
                            existingProjectNote.Project_RefID = Parameter.ProjectID;
                            existingProjectNote.Save(Connection, Transaction);
                        }
                    }

                    //Update note tags (Delete existing ones and save new ones)
                    P_L3TG_ATtN_1738 tagParameter = new P_L3TG_ATtN_1738();
                    tagParameter.ProjectNoteID = Parameter.ProjectNoteID;
                    List <P_L3TG_ATtN_1738a> tagListParameter = new List <P_L3TG_ATtN_1738a>();
                    foreach (var currentTag in Parameter.Tags)
                    {
                        P_L3TG_ATtN_1738a tempTag = new P_L3TG_ATtN_1738a();
                        tempTag.TagValue      = currentTag.TagValue;
                        tempTag.TMS_PRO_TagID = currentTag.TagID;
                        tagListParameter.Add(tempTag);
                    }
                    tagParameter.NoteTags = tagListParameter.ToArray();
                    cls_Add_Tags_to_Note.Invoke(Connection, Transaction, tagParameter, securityTicket);
                }
            }
            else
            {
                ORM_CMN_Note              newCmnNote      = new ORM_CMN_Note();
                ORM_CMN_NoteRevision      newNoteRevision = new ORM_CMN_NoteRevision();
                ORM_TMS_PRO_Project_Notes newProjectNote  = new ORM_TMS_PRO_Project_Notes();

                newNoteRevision.Note_RefID = newCmnNote.CMN_NoteID;
                newNoteRevision.Content    = Parameter.Content;
                newNoteRevision.CreatedBy_BusinessParticipant_RefID = noteCreatorAccount.BusinessParticipant_RefID;
                newNoteRevision.Tenant_RefID = securityTicket.TenantID;
                newNoteRevision.Title        = Parameter.Title;
                newNoteRevision.Version      = 1;
                newNoteRevision.Save(Connection, Transaction);

                newCmnNote.Current_NoteRevision_RefID          = newNoteRevision.CMN_NoteRevisionID;
                newCmnNote.CreatedBy_BusinessParticipant_RefID = noteCreatorAccount.BusinessParticipant_RefID;
                newCmnNote.Tenant_RefID = securityTicket.TenantID;
                newCmnNote.Save(Connection, Transaction);

                newProjectNote.Ext_CMN_Note_RefID = newCmnNote.CMN_NoteID;
                newProjectNote.Project_RefID      = Parameter.ProjectID;
                newProjectNote.Tenant_RefID       = securityTicket.TenantID;
                newProjectNote.Save(Connection, Transaction);

                //Update note tags (Delete existing ones and save new ones)
                P_L3TG_ATtN_1738 tagParameter = new P_L3TG_ATtN_1738();
                tagParameter.ProjectNoteID = newProjectNote.TMS_PRO_Project_NoteID;
                List <P_L3TG_ATtN_1738a> tagListParameter = new List <P_L3TG_ATtN_1738a>();
                foreach (var currentTag in Parameter.Tags)
                {
                    P_L3TG_ATtN_1738a tempTag = new P_L3TG_ATtN_1738a();
                    tempTag.TagValue      = currentTag.TagValue;
                    tempTag.TMS_PRO_TagID = currentTag.TagID;
                    tagListParameter.Add(tempTag);
                }
                tagParameter.NoteTags = tagListParameter.ToArray();
                cls_Add_Tags_to_Note.Invoke(Connection, Transaction, tagParameter, securityTicket);
            }
            return(returnValue);

            #endregion UserCode
        }
Beispiel #2
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L3TG_ATtN_1738 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Base();
            //Put your code here
            ORM_TMS_PRO_Tags.Query tagQuery = new ORM_TMS_PRO_Tags.Query();
            tagQuery.Tenant_RefID = securityTicket.TenantID;
            tagQuery.IsDeleted    = false;

            ORM_TMS_PRO_Project_Note_2_Tag.Query note2TagQuery = new ORM_TMS_PRO_Project_Note_2_Tag.Query();
            note2TagQuery.Project_Note_RefID = Parameter.ProjectNoteID;
            note2TagQuery.Tenant_RefID       = securityTicket.TenantID;
            note2TagQuery.IsDeleted          = false;

            //remove existing ones not in the parameter list
            List <ORM_TMS_PRO_Project_Note_2_Tag> existingTags = ORM_TMS_PRO_Project_Note_2_Tag.Query.Search(Connection, Transaction, note2TagQuery);
            if (existingTags != null && existingTags.Count > 0)
            {
                foreach (var currentTag in existingTags)
                {
                    if (!Parameter.NoteTags.ToList().Exists(n => n.TMS_PRO_TagID != null && n.TMS_PRO_TagID != Guid.Empty && n.TMS_PRO_TagID == currentTag.Tag_RefID))
                    {
                        note2TagQuery.Tag_RefID = currentTag.Tag_RefID;
                        ORM_TMS_PRO_Project_Note_2_Tag.Query.SoftDelete(Connection, Transaction, note2TagQuery);
                    }
                }
            }

            foreach (var currentTag in Parameter.NoteTags)
            {
                tagQuery.TagValue = currentTag.TagValue;
                if (!ORM_TMS_PRO_Tags.Query.Exists(Connection, Transaction, tagQuery))
                {
                    //Add tag to database
                    ORM_TMS_PRO_Tags newTagData = new ORM_TMS_PRO_Tags();
                    newTagData.Tenant_RefID = securityTicket.TenantID;
                    newTagData.TagValue     = currentTag.TagValue;
                    newTagData.Save(Connection, Transaction);
                    //Bind to note
                    ORM_TMS_PRO_Project_Note_2_Tag note2Tag = new ORM_TMS_PRO_Project_Note_2_Tag();
                    note2Tag.Project_Note_RefID = Parameter.ProjectNoteID;
                    note2Tag.Tag_RefID          = newTagData.TMS_PRO_TagID;
                    note2Tag.Tenant_RefID       = securityTicket.TenantID;
                    note2Tag.Save(Connection, Transaction);
                }
                else
                {
                    note2TagQuery.Tag_RefID          = currentTag.TMS_PRO_TagID;
                    note2TagQuery.Project_Note_RefID = Parameter.ProjectNoteID;
                    if (!ORM_TMS_PRO_Project_Note_2_Tag.Query.Exists(Connection, Transaction, note2TagQuery))
                    {
                        ORM_TMS_PRO_Project_Note_2_Tag note2Tag = new ORM_TMS_PRO_Project_Note_2_Tag();
                        note2Tag.Project_Note_RefID = Parameter.ProjectNoteID;
                        note2Tag.Tag_RefID          = currentTag.TMS_PRO_TagID;
                        note2Tag.Tenant_RefID       = securityTicket.TenantID;
                        note2Tag.Save(Connection, Transaction);
                    }
                }
            }

            return(returnValue);

            #endregion UserCode
        }