Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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
        }