Ejemplo n.º 1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3TG_SETP_1356 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here


            ORM_TMS_PRO_Tags tags = new ORM_TMS_PRO_Tags();
            foreach (var tag in Parameter.TagValue)
            {
                //tags.TMS_PRO_TagID = new Guid();
                tags.Tenant_RefID = securityTicket.TenantID;
                tags.TagValue     = tag;
                tags.Save(Connection, Transaction);
            }
            ORM_TMS_PRO_Project_2_Tag tag2proj = new ORM_TMS_PRO_Project_2_Tag();
            tag2proj.Project_RefID = Parameter.Project_RefID;
            tag2proj.IsDeleted     = false;
            tag2proj.Tenant_RefID  = securityTicket.TenantID;
            tag2proj.Tag_RefID     = tags.TMS_PRO_TagID;
            tag2proj.Save(Connection, Transaction);


            return(returnValue);

            #endregion UserCode
        }
Ejemplo n.º 2
0
        private static Guid SaveTag(DbConnection Connection, DbTransaction Transaction, String Tag, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket)
        {
            ORM_TMS_PRO_Tags NewTag = new ORM_TMS_PRO_Tags();

            NewTag.IsDeleted     = false;
            NewTag.TagValue      = Tag;
            NewTag.TMS_PRO_TagID = Guid.NewGuid();
            NewTag.Tenant_RefID  = securityTicket.TenantID;

            NewTag.Save(Connection, Transaction);

            return(NewTag.TMS_PRO_TagID);
        }
Ejemplo n.º 3
0
        private static FR_Base SaveTagsForFeature(DbConnection Connection, DbTransaction Transaction, Guid Feature_ID, String[] Tags, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket)
        {
            FR_Base retVal = new FR_Base();

            if (Tags != null && Tags.ToList().Count != 0)
            {
                foreach (String tag in Tags)
                {
                    ORM_TMS_PRO_Tags.Query searchForTag = new ORM_TMS_PRO_Tags.Query();
                    searchForTag.IsDeleted = false;
                    searchForTag.TagValue  = tag;

                    ORM_TMS_PRO_Tags TagExists = ORM_TMS_PRO_Tags.Query.Search(Connection, Transaction, searchForTag).FirstOrDefault();


                    ORM_TMS_PRO_Feature_2_Tag Feature_2_Tag = new ORM_TMS_PRO_Feature_2_Tag();

                    Feature_2_Tag.AssignmentID = Guid.NewGuid();
                    Feature_2_Tag.IsDeleted    = false;
                    Feature_2_Tag.Tenant_RefID = securityTicket.TenantID;

                    Feature_2_Tag.Feature_RefID = Feature_ID;

                    if (TagExists != null && TagExists.TMS_PRO_TagID != Guid.Empty)
                    {
                        Feature_2_Tag.Tag_RefID = TagExists.TMS_PRO_TagID;
                    }

                    if (TagExists == null || TagExists.TMS_PRO_TagID == Guid.Empty)
                    {
                        Guid NewTag_ID = SaveTag(Connection, Transaction, tag, securityTicket);
                        Feature_2_Tag.Tag_RefID = NewTag_ID;
                    }


                    Feature_2_Tag.Save(Connection, Transaction);
                }
            }

            else
            {
                retVal.Status = FR_Status.Error_Internal;

                return(retVal);
            }
            retVal.Status = FR_Status.Success;

            return(retVal);
        }
Ejemplo n.º 4
0
        private static FR_Base SaveTagsFor_EditedFeature(DbConnection Connection, DbTransaction Transaction, Guid Feature_ID, String[] Tags, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket)
        {
            FR_Base retVal = new FR_Base();

            List <String> EditedTags = Tags.ToList();

            List <ORM_TMS_PRO_Feature_2_Tag>      ActiveFeatures2Tags            = new List <ORM_TMS_PRO_Feature_2_Tag>();
            List <ORM_TMS_PRO_Tags>               ActiveTagsForFeature           = new List <ORM_TMS_PRO_Tags>();
            Dictionary <String, ORM_TMS_PRO_Tags> ActiveTagsForFeature_Remaining = new Dictionary <String, ORM_TMS_PRO_Tags>();


            #region Load lists

            ORM_TMS_PRO_Feature_2_Tag.Query search_active_f2t = new ORM_TMS_PRO_Feature_2_Tag.Query();
            search_active_f2t.Feature_RefID = Feature_ID;
            search_active_f2t.IsDeleted     = false;
            search_active_f2t.Tenant_RefID  = securityTicket.TenantID;

            ActiveFeatures2Tags = ORM_TMS_PRO_Feature_2_Tag.Query.Search(Connection, Transaction, search_active_f2t);

            if (ActiveFeatures2Tags != null && ActiveFeatures2Tags.Count != 0)
            {
                foreach (var f2t in ActiveFeatures2Tags)
                {
                    ORM_TMS_PRO_Tags.Query search_active_tag = new ORM_TMS_PRO_Tags.Query();
                    search_active_tag.IsDeleted     = false;
                    search_active_tag.TMS_PRO_TagID = f2t.Tag_RefID;
                    search_active_tag.Tenant_RefID  = securityTicket.TenantID;

                    ORM_TMS_PRO_Tags ActiveTag = ORM_TMS_PRO_Tags.Query.Search(Connection, Transaction, search_active_tag).FirstOrDefault();

                    if (ActiveTag != null)
                    {
                        ActiveTagsForFeature.Add(ActiveTag);
                        ActiveTagsForFeature_Remaining.Add(ActiveTag.TagValue, ActiveTag);
                    }
                }
            }

            #endregion


            #region Delete all tags for Feature

            if (EditedTags == null || EditedTags.Count == 0)
            {
                if (ActiveFeatures2Tags.Count != 0 && ActiveFeatures2Tags != null)
                {
                    foreach (var f2t in ActiveFeatures2Tags)
                    {
                        ORM_TMS_PRO_Feature_2_Tag.Query searchQuery = new ORM_TMS_PRO_Feature_2_Tag.Query();
                        searchQuery.Feature_RefID = f2t.Feature_RefID;
                        searchQuery.Tag_RefID     = f2t.Tag_RefID;
                        searchQuery.IsDeleted     = false;
                        searchQuery.Tenant_RefID  = securityTicket.TenantID;

                        ORM_TMS_PRO_Feature_2_Tag.Query.SoftDelete(Connection, Transaction, searchQuery);
                    }
                }

                retVal.Status = FR_Status.Success;
                return(retVal);
            }

            #endregion


            #region Feature doesn't have any active tags

            if (ActiveFeatures2Tags == null || ActiveFeatures2Tags.Count == 0)
            {
                foreach (var tag in EditedTags)
                {
                    ORM_TMS_PRO_Tags.Query search_if_exists = new ORM_TMS_PRO_Tags.Query();
                    search_if_exists.IsDeleted    = false;
                    search_if_exists.TagValue     = tag;
                    search_if_exists.Tenant_RefID = securityTicket.TenantID;

                    ORM_TMS_PRO_Tags TagExists = ORM_TMS_PRO_Tags.Query.Search(Connection, Transaction, search_if_exists).FirstOrDefault();

                    //tag ne postoji, dodaje se novi
                    if (TagExists == null || TagExists.TMS_PRO_TagID == Guid.Empty)
                    {
                        Guid NewTag_ID = SaveTag(Connection, Transaction, tag, securityTicket);

                        ORM_TMS_PRO_Feature_2_Tag NewFeature2Tag = new ORM_TMS_PRO_Feature_2_Tag();
                        NewFeature2Tag.Feature_RefID = Feature_ID;
                        NewFeature2Tag.IsDeleted     = false;
                        NewFeature2Tag.AssignmentID  = Guid.NewGuid();
                        NewFeature2Tag.Tag_RefID     = NewTag_ID;
                        NewFeature2Tag.Tenant_RefID  = securityTicket.TenantID;

                        NewFeature2Tag.Save(Connection, Transaction);
                    }

                    // tag vec postoji
                    if (TagExists != null && TagExists.TMS_PRO_TagID != Guid.Empty)
                    {
                        ORM_TMS_PRO_Feature_2_Tag NewFeature2Tag = new ORM_TMS_PRO_Feature_2_Tag();
                        NewFeature2Tag.Feature_RefID = Feature_ID;
                        NewFeature2Tag.IsDeleted     = false;
                        NewFeature2Tag.AssignmentID  = Guid.NewGuid();
                        NewFeature2Tag.Tag_RefID     = TagExists.TMS_PRO_TagID;
                        NewFeature2Tag.Tenant_RefID  = securityTicket.TenantID;

                        NewFeature2Tag.Save(Connection, Transaction);
                    }
                }


                retVal.Status = FR_Status.Success;
                return(retVal);
            }

            #endregion


            foreach (var Tag in Tags)
            {
                if (ActiveTagsForFeature.Any(ac => ac.TagValue.Equals(Tag)))
                {
                    EditedTags.Remove(Tag);
                    ActiveTagsForFeature_Remaining.Remove(Tag);
                }
            }


            #region Delete Tags no longer in use

            foreach (var TagToDelete in ActiveTagsForFeature_Remaining)
            {
                ORM_TMS_PRO_Feature_2_Tag.Query searchFeature2Tag = new ORM_TMS_PRO_Feature_2_Tag.Query();
                searchFeature2Tag.IsDeleted     = false;
                searchFeature2Tag.Feature_RefID = Feature_ID;
                searchFeature2Tag.Tag_RefID     = TagToDelete.Value.TMS_PRO_TagID;
                searchFeature2Tag.Tenant_RefID  = securityTicket.TenantID;

                ORM_TMS_PRO_Feature_2_Tag.Query.SoftDelete(Connection, Transaction, searchFeature2Tag);
            }

            #endregion


            #region Add new tags

            foreach (var tag in EditedTags)
            {
                SaveTagsForFeature(Connection, Transaction, Feature_ID, EditedTags.ToArray(), securityTicket);
            }

            #endregion


            retVal.Status = FR_Status.Success;
            return(retVal);
        }
Ejemplo n.º 5
0
        protected static FR_L3N_SNN_0921 Execute(DbConnection Connection, DbTransaction Transaction, P_L3N_SNN_0921 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3N_SNN_0921();
            //Put your code here
            if (Parameter.SaveType == "SaveNewVersion")
            {
                if (Parameter.SaveOnlyNewVersion)
                {
                    //only title/content has been changed
                    ORM_TMS_PRO_Project_Notes newProjectNote = new ORM_TMS_PRO_Project_Notes();
                    //save new note version
                    ORM_CMN_NoteRevision newNoteVersion = new ORM_CMN_NoteRevision();
                    newNoteVersion.CMN_NoteRevisionID = Guid.NewGuid();
                    newNoteVersion.Content            = Parameter.Content;
                    newNoteVersion.Title        = Parameter.Title;
                    newNoteVersion.Tenant_RefID = securityTicket.TenantID;
                    newNoteVersion.Note_RefID   = Parameter.NoteID;
                    ORM_CMN_Note note = ORM_CMN_Note.Query.Search(Connection, Transaction, new ORM_CMN_Note.Query()
                    {
                        CMN_NoteID   = Parameter.NoteID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).SingleOrDefault();


                    if (note != null)
                    {
                        ORM_CMN_NoteRevision currentNoteVersion = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, new ORM_CMN_NoteRevision.Query()
                        {
                            CMN_NoteRevisionID = Parameter.NoteRevisionID,
                            Tenant_RefID       = securityTicket.TenantID,
                            IsDeleted          = false
                        }).SingleOrDefault();

                        if (currentNoteVersion != null)
                        {
                            if (Parameter.SaveOverVersion)
                            {
                                newNoteVersion.Version = currentNoteVersion.Version;
                            }
                            else
                            {
                                newNoteVersion.Version = currentNoteVersion.Version + 1;
                            }

                            note.Current_NoteRevision_RefID = newNoteVersion.CMN_NoteRevisionID;
                            note.Save(Connection, Transaction);
                        }
                    }

                    ORM_USR_Account creator = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                    {
                        USR_AccountID = Parameter.CreatorID,
                        Tenant_RefID  = securityTicket.TenantID,
                        IsDeleted     = false
                    }).Single();
                    newNoteVersion.CreatedBy_BusinessParticipant_RefID = creator.BusinessParticipant_RefID;
                    newNoteVersion.Save(Connection, Transaction);
                }

                else
                {
                    ORM_CMN_Note newNote = new ORM_CMN_Note();
                    newNote.CMN_NoteID   = Guid.NewGuid();
                    newNote.Tenant_RefID = securityTicket.TenantID;
                    ORM_USR_Account currentUser = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                    {
                        USR_AccountID = securityTicket.AccountID,
                        Tenant_RefID  = securityTicket.TenantID,
                        IsDeleted     = false
                    }).Single();
                    newNote.CreatedBy_BusinessParticipant_RefID = currentUser.BusinessParticipant_RefID;

                    //create first version of note

                    ORM_CMN_NoteRevision newNoteVersion = new ORM_CMN_NoteRevision();
                    newNoteVersion.CMN_NoteRevisionID = Guid.NewGuid();
                    newNoteVersion.Content            = Parameter.Content;
                    newNoteVersion.Title        = Parameter.Title;
                    newNoteVersion.Tenant_RefID = securityTicket.TenantID;
                    newNoteVersion.Note_RefID   = newNote.CMN_NoteID;
                    newNoteVersion.CreatedBy_BusinessParticipant_RefID = currentUser.BusinessParticipant_RefID;
                    /*******/
                    ORM_CMN_Note note = ORM_CMN_Note.Query.Search(Connection, Transaction, new ORM_CMN_Note.Query()
                    {
                        CMN_NoteID   = Parameter.NoteID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).SingleOrDefault();


                    if (note != null)
                    {
                        if (Parameter.SaveOverVersion)
                        {
                            ORM_CMN_NoteRevision passedNoteVersion = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, new ORM_CMN_NoteRevision.Query()
                            {
                                CMN_NoteRevisionID = Parameter.NoteRevisionID,
                                Tenant_RefID       = securityTicket.TenantID,
                                IsDeleted          = false
                            }).SingleOrDefault();

                            newNoteVersion.Version = passedNoteVersion.Version;
                        }
                        else
                        {
                            ORM_CMN_NoteRevision currentNoteVersion = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, new ORM_CMN_NoteRevision.Query()
                            {
                                CMN_NoteRevisionID = Parameter.NoteRevisionID,
                                Tenant_RefID       = securityTicket.TenantID,
                                IsDeleted          = false
                            }).SingleOrDefault();
                            newNoteVersion.Version = currentNoteVersion.Version + 1;
                        }
                    }
                    /********/


                    newNoteVersion.Save(Connection, Transaction);

                    newNote.Current_NoteRevision_RefID = newNoteVersion.CMN_NoteRevisionID;


                    ORM_TMS_PRO_Project_Notes projectNote = new ORM_TMS_PRO_Project_Notes();


                    ORM_TMS_PRO_Project_Notes newProjectNote = new ORM_TMS_PRO_Project_Notes();
                    newProjectNote.Ext_CMN_Note_RefID     = newNote.CMN_NoteID;
                    newProjectNote.Project_RefID          = Parameter.ProjectID;
                    newProjectNote.Tenant_RefID           = securityTicket.TenantID;
                    newProjectNote.TMS_PRO_Project_NoteID = Guid.NewGuid();
                    newProjectNote.Save(Connection, Transaction);
                    projectNote = newProjectNote;


                    // ADDING/REMOVING COLLABORATORS
                    if (Parameter.Collaborators != null && Parameter.Collaborators.Count() != 0)
                    {
                        //check which project members to remove and which to add
                        var collaboratorsForProjectNote = ORM_TMS_PRO_Project_Note_Collaborators.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Note_Collaborators.Query()
                        {
                            ProjectNote_RefID = projectNote.TMS_PRO_Project_NoteID,
                            Tenant_RefID      = securityTicket.TenantID,
                            IsDeleted         = false
                        });
                        foreach (var collab in collaboratorsForProjectNote)
                        {
                            if (!Parameter.Collaborators.Contains(collab.Account_RefID))
                            {
                                ORM_TMS_PRO_Project_Note_Collaborators CollaboratorToDelete = ORM_TMS_PRO_Project_Note_Collaborators.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Note_Collaborators.Query()
                                {
                                    Account_RefID = collab.Account_RefID,
                                    IsDeleted     = false,
                                    Tenant_RefID  = securityTicket.TenantID
                                }).Single();
                                CollaboratorToDelete.IsDeleted = true;
                                CollaboratorToDelete.Save(Connection, Transaction);
                            }
                        }

                        foreach (var newCollab in Parameter.Collaborators)
                        {
                            if (!collaboratorsForProjectNote.Exists(cpn => cpn.Account_RefID == newCollab))
                            {
                                ORM_TMS_PRO_Project_Note_Collaborators newCollaborator = new ORM_TMS_PRO_Project_Note_Collaborators();
                                newCollaborator.TMS_PRO_Project_Note_CollaboratorID = Guid.NewGuid();
                                newCollaborator.Tenant_RefID      = securityTicket.TenantID;
                                newCollaborator.ProjectNote_RefID = projectNote.TMS_PRO_Project_NoteID;
                                newCollaborator.Account_RefID     = newCollab;
                                newCollaborator.Save(Connection, Transaction);
                            }
                        }
                    }
                    // ADDING/REMOVING TAGS
                    if (Parameter.Tags != null && Parameter.Tags.Count() != 0)
                    {
                        foreach (var tag in Parameter.Tags)
                        {
                            ORM_TMS_PRO_Tags existingTag = ORM_TMS_PRO_Tags.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Tags.Query()
                            {
                                TMS_PRO_TagID = tag.TagID,
                                IsDeleted     = false,
                                Tenant_RefID  = securityTicket.TenantID
                            }).SingleOrDefault();

                            if (existingTag == null)
                            {
                                ORM_TMS_PRO_Tags newTag = new ORM_TMS_PRO_Tags();
                                newTag.TMS_PRO_TagID = Guid.NewGuid();
                                newTag.TagValue      = tag.TagValue;
                                newTag.Tenant_RefID  = securityTicket.TenantID;
                                newTag.Save(Connection, Transaction);

                                ORM_TMS_PRO_Project_Note_2_Tag newTagToNote = new ORM_TMS_PRO_Project_Note_2_Tag();
                                newTagToNote.AssignmentID       = Guid.NewGuid();
                                newTagToNote.Project_Note_RefID = newProjectNote.TMS_PRO_Project_NoteID;
                                newTagToNote.Tag_RefID          = newTag.TMS_PRO_TagID;
                                newTagToNote.Save(Connection, Transaction);
                            }
                            else
                            {
                                ORM_TMS_PRO_Project_Note_2_Tag newTagToNote = new ORM_TMS_PRO_Project_Note_2_Tag();
                                newTagToNote.AssignmentID       = Guid.NewGuid();
                                newTagToNote.Project_Note_RefID = newProjectNote.TMS_PRO_Project_NoteID;
                                newTagToNote.Tag_RefID          = existingTag.TMS_PRO_TagID;
                                newTagToNote.Save(Connection, Transaction);
                            }
                        }
                        var allProjectNote2Tags = ORM_TMS_PRO_Project_Note_2_Tag.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Note_2_Tag.Query()
                        {
                            Project_Note_RefID = Parameter.ProjectNoteID,
                            Tenant_RefID       = securityTicket.TenantID,
                            IsDeleted          = false
                        }
                                                                                              );
                        foreach (var projectNote2Tag in allProjectNote2Tags)
                        {
                            if (!Parameter.Tags.ToList().Exists(tag => tag.TagID == projectNote2Tag.Tag_RefID))
                            {
                                var ProjectNote2TagToDelete = ORM_TMS_PRO_Project_Note_2_Tag.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Note_2_Tag.Query()
                                {
                                    AssignmentID = projectNote2Tag.AssignmentID,
                                    Tenant_RefID = securityTicket.TenantID,
                                    IsDeleted    = false
                                }
                                                                                                          ).Single();
                                ProjectNote2TagToDelete.IsDeleted = true;
                                ProjectNote2TagToDelete.Save(Connection, Transaction);
                            }
                        }
                    }
                    newNote.Save(Connection, Transaction);
                }
                if (Parameter.SaveOverVersion)
                {
                    var noteRevisionForRevisionID = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, new ORM_CMN_NoteRevision.Query()
                    {
                        CMN_NoteRevisionID = Parameter.NoteRevisionID,
                        Tenant_RefID       = securityTicket.TenantID,
                        IsDeleted          = false
                    }).Single();

                    //note
                    ORM_CMN_Note noteToDelete = ORM_CMN_Note.Query.Search(Connection, Transaction, new ORM_CMN_Note.Query()
                    {
                        CMN_NoteID   = Parameter.NoteID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).Single();
                    //all versions of that note
                    var noteRevisionsForNoteID = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, new ORM_CMN_NoteRevision.Query()
                    {
                        Note_RefID   = Parameter.NoteID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    });

                    if (noteToDelete.Current_NoteRevision_RefID == noteRevisionForRevisionID.CMN_NoteRevisionID)
                    {
                        if (noteRevisionsForNoteID.Count() > 1)
                        {
                            //proveriti prvo da li je to trenutna verzija notea, ako jeste i ima ih jos onda brisi ovu, uzmi prethodnu
                            var newCurrentNoteRevision = noteRevisionsForNoteID.Where(nr => nr.Version < noteRevisionForRevisionID.Version).First();
                            noteToDelete.Current_NoteRevision_RefID = newCurrentNoteRevision.CMN_NoteRevisionID;
                            noteRevisionForRevisionID.IsDeleted     = true;
                            noteRevisionForRevisionID.Save(Connection, Transaction);
                            noteToDelete.Save(Connection, Transaction);
                        }
                        else if (noteRevisionsForNoteID.Count() == 1)
                        {
                            noteToDelete.IsDeleted = true;
                            noteToDelete.Save(Connection, Transaction);

                            var projectNotesToDelete = ORM_TMS_PRO_Project_Notes.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Notes.Query()
                            {
                                Ext_CMN_Note_RefID = noteToDelete.CMN_NoteID,
                                Tenant_RefID       = securityTicket.TenantID,
                                IsDeleted          = false
                            });
                            foreach (var item in projectNotesToDelete)
                            {
                                item.IsDeleted = true;
                                item.Save(Connection, Transaction);
                                //delete collaborators and tags regarding that note

                                var currentCollaborators = ORM_TMS_PRO_Project_Note_Collaborators.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Note_Collaborators.Query()
                                {
                                    ProjectNote_RefID = item.TMS_PRO_Project_NoteID,
                                    Tenant_RefID      = securityTicket.TenantID,
                                    IsDeleted         = false
                                });
                                if (currentCollaborators != null)
                                {
                                    foreach (var collaborator in currentCollaborators)
                                    {
                                        collaborator.IsDeleted = true;
                                        collaborator.Save(Connection, Transaction);
                                    }
                                }
                                ORM_TMS_PRO_Project_Note_2_Tag currentTags = ORM_TMS_PRO_Project_Note_2_Tag.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Note_2_Tag.Query()
                                {
                                    Project_Note_RefID = item.TMS_PRO_Project_NoteID,
                                    Tenant_RefID       = securityTicket.TenantID,
                                    IsDeleted          = false
                                }).SingleOrDefault();

                                if (currentTags != null)
                                {
                                    currentTags.IsDeleted = true;
                                    currentTags.Save(Connection, Transaction);
                                }
                            }
                        }
                    }
                    else
                    {
                        //izbrisi samo tu verziju
                        noteRevisionForRevisionID.IsDeleted = true;
                        noteRevisionForRevisionID.Save(Connection, Transaction);
                    }
                    //ako je to poslednja verzija tog notea, izbrisati i note.
                }
            }
            else if (Parameter.SaveType == "SaveNewNote")
            {
                ORM_CMN_Note newNote = new ORM_CMN_Note();
                newNote.CMN_NoteID   = Guid.NewGuid();
                newNote.Tenant_RefID = securityTicket.TenantID;
                ORM_USR_Account currentUser = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                {
                    USR_AccountID = securityTicket.AccountID,
                    Tenant_RefID  = securityTicket.TenantID,
                    //IsDeleted = true
                }).Single();
                newNote.CreatedBy_BusinessParticipant_RefID = currentUser.BusinessParticipant_RefID;

                //create first version of note

                ORM_CMN_NoteRevision newNoteVersion = new ORM_CMN_NoteRevision();
                newNoteVersion.CMN_NoteRevisionID = Guid.NewGuid();
                newNoteVersion.Content            = Parameter.Content;
                newNoteVersion.Title        = Parameter.Title;
                newNoteVersion.Tenant_RefID = securityTicket.TenantID;
                newNoteVersion.Note_RefID   = newNote.CMN_NoteID;
                newNoteVersion.Version      = 1;
                newNoteVersion.CreatedBy_BusinessParticipant_RefID = currentUser.BusinessParticipant_RefID;

                newNoteVersion.Save(Connection, Transaction);

                newNote.Current_NoteRevision_RefID = newNoteVersion.CMN_NoteRevisionID;

                //create new project note
                ORM_TMS_PRO_Project_Notes newProjectNote = new ORM_TMS_PRO_Project_Notes();
                newProjectNote.TMS_PRO_Project_NoteID = Guid.NewGuid();
                newProjectNote.Ext_CMN_Note_RefID     = newNote.CMN_NoteID;
                newProjectNote.Tenant_RefID           = securityTicket.TenantID;
                newProjectNote.Project_RefID          = Parameter.ProjectID;

                newProjectNote.Save(Connection, Transaction);



                if (Parameter.Collaborators != null && Parameter.Collaborators.Count() != 0)
                {
                    foreach (var collab in Parameter.Collaborators)
                    {
                        ORM_TMS_PRO_Project_Note_Collaborators newCollaborators = new ORM_TMS_PRO_Project_Note_Collaborators();
                        newCollaborators.ProjectNote_RefID = newProjectNote.TMS_PRO_Project_NoteID;
                        newCollaborators.TMS_PRO_Project_Note_CollaboratorID = Guid.NewGuid();
                        newCollaborators.Tenant_RefID  = securityTicket.TenantID;
                        newCollaborators.Account_RefID = collab;
                        newCollaborators.Save(Connection, Transaction);
                    }
                }
                if (Parameter.Tags != null && Parameter.Tags.Count() != 0)
                {
                    foreach (var tag in Parameter.Tags)
                    {
                        //todo: search by id
                        ORM_TMS_PRO_Tags existingTag = ORM_TMS_PRO_Tags.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Tags.Query()
                        {
                            TMS_PRO_TagID = tag.TagID,
                            IsDeleted     = false,
                            Tenant_RefID  = securityTicket.TenantID
                        }).SingleOrDefault();

                        if (existingTag == null)
                        {
                            ORM_TMS_PRO_Tags newTag = new ORM_TMS_PRO_Tags();
                            newTag.TMS_PRO_TagID = Guid.NewGuid();
                            newTag.TagValue      = tag.TagValue;
                            newTag.Tenant_RefID  = securityTicket.TenantID;
                            newTag.Save(Connection, Transaction);

                            ORM_TMS_PRO_Project_Note_2_Tag newTagToNote = new ORM_TMS_PRO_Project_Note_2_Tag();
                            newTagToNote.AssignmentID       = Guid.NewGuid();
                            newTagToNote.Project_Note_RefID = newProjectNote.TMS_PRO_Project_NoteID;
                            newTagToNote.Tag_RefID          = newTag.TMS_PRO_TagID;
                            newTagToNote.Save(Connection, Transaction);
                        }
                        else
                        {
                            ORM_TMS_PRO_Project_Note_2_Tag newTagToNote = new ORM_TMS_PRO_Project_Note_2_Tag();
                            newTagToNote.AssignmentID       = Guid.NewGuid();
                            newTagToNote.Project_Note_RefID = newProjectNote.TMS_PRO_Project_NoteID;
                            newTagToNote.Tag_RefID          = existingTag.TMS_PRO_TagID;
                            newTagToNote.Save(Connection, Transaction);
                        }
                    }
                }
                newNote.Save(Connection, Transaction);
            }
            else if (Parameter.SaveType == "DeleteNote")
            {
                var noteRevisionForRevisionID = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, new ORM_CMN_NoteRevision.Query()
                {
                    CMN_NoteRevisionID = Parameter.NoteRevisionID,
                    Tenant_RefID       = securityTicket.TenantID,
                    IsDeleted          = false
                }).Single();

                //note
                ORM_CMN_Note noteToDelete = ORM_CMN_Note.Query.Search(Connection, Transaction, new ORM_CMN_Note.Query()
                {
                    CMN_NoteID   = Parameter.NoteID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single();
                //all versions of that note
                var noteRevisionsForNoteID = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, new ORM_CMN_NoteRevision.Query()
                {
                    Note_RefID   = Parameter.NoteID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                });

                if (noteToDelete.Current_NoteRevision_RefID == noteRevisionForRevisionID.CMN_NoteRevisionID)
                {
                    if (noteRevisionsForNoteID.Count() > 1)
                    {
                        //proveriti prvo da li je to trenutna verzija notea, ako jeste i ima ih jos onda brisi ovu, uzmi prethodnu
                        var newCurrentNoteRevision = noteRevisionsForNoteID.Where(nr => nr.Version < noteRevisionForRevisionID.Version).First();
                        noteToDelete.Current_NoteRevision_RefID = newCurrentNoteRevision.CMN_NoteRevisionID;
                        noteRevisionForRevisionID.IsDeleted     = true;
                        noteRevisionForRevisionID.Save(Connection, Transaction);
                        noteToDelete.Save(Connection, Transaction);
                    }
                    else if (noteRevisionsForNoteID.Count() == 1)
                    {
                        noteToDelete.IsDeleted = true;
                        noteToDelete.Save(Connection, Transaction);

                        var projectNotesToDelete = ORM_TMS_PRO_Project_Notes.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Notes.Query()
                        {
                            Ext_CMN_Note_RefID = noteToDelete.CMN_NoteID,
                            Tenant_RefID       = securityTicket.TenantID,
                            IsDeleted          = false
                        });
                        foreach (var item in projectNotesToDelete)
                        {
                            item.IsDeleted = true;
                            item.Save(Connection, Transaction);
                            //delete collaborators and tags regarding that note

                            var currentCollaborators = ORM_TMS_PRO_Project_Note_Collaborators.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Note_Collaborators.Query()
                            {
                                ProjectNote_RefID = item.TMS_PRO_Project_NoteID,
                                Tenant_RefID      = securityTicket.TenantID,
                                IsDeleted         = false
                            });
                            if (currentCollaborators != null)
                            {
                                foreach (var collaborator in currentCollaborators)
                                {
                                    collaborator.IsDeleted = true;
                                    collaborator.Save(Connection, Transaction);
                                }
                            }
                            ORM_TMS_PRO_Project_Note_2_Tag currentTags = ORM_TMS_PRO_Project_Note_2_Tag.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Note_2_Tag.Query()
                            {
                                Project_Note_RefID = item.TMS_PRO_Project_NoteID,
                                Tenant_RefID       = securityTicket.TenantID,
                                IsDeleted          = false
                            }).SingleOrDefault();

                            if (currentTags != null)
                            {
                                currentTags.IsDeleted = true;
                                currentTags.Save(Connection, Transaction);
                            }
                        }
                    }
                }
                else
                {
                    //izbrisi samo tu verziju
                    noteRevisionForRevisionID.IsDeleted = true;
                    noteRevisionForRevisionID.Save(Connection, Transaction);
                }
            }
            return(returnValue);

            #endregion UserCode
        }
Ejemplo n.º 6
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
        }