/// <summary>
        ///
        /// </summary>
        /// <param name="siteTagId"></param>
        public void DeleteFieldsByContentId(long contentId)
        {
            ContentLibrary contLib = new ContentLibrary();

            //DELETE VALUES FOR THE CONTENT and ITS CHILDS
            var values = from v in _context.awContentCustomFieldValues
                         join f in _context.awContentCustomFields on v.customFieldId equals f.customFieldId
                         where f.contentId.Equals(contentId)
                         select v;

            //DELETE FIELDS FOR THE CONTENT and ITS CHILDS
            var fields = from f in _context.awContentCustomFields
                         where f.contentId.Equals(contentId)
                         select f;

            _context.awContentCustomFieldValues.DeleteAllOnSubmit(values);
            _context.awContentCustomFields.DeleteAllOnSubmit(fields);
            _context.SubmitChanges();
        }
Пример #2
0
        /// <summary>
        /// if not exists add static and custom content fields to the form,,,
        /// NOTE: this method DOES NOT call SUBMITCHANGES
        /// </summary>
        /// <param name="contentId"></param>
        /// <param name="contentFormId"></param>
        public void AddFieldsToForm(long contentId, long contentFormId, bool submitChanges)
        {
            //Cleanup if exists
            CleanupCustomFields();

            //Add static fields first
            int sortOrder = 1;

            foreach (string field in Enum.GetNames(typeof(StaticFieldsName)))
            {
                awContentFormFieldSetting set = new awContentFormFieldSetting();
                set.contentFormFieldSettingId = AWAPI_Common.library.MiscLibrary.CreateUniqueId();
                set.contentFormId             = contentFormId;
                set.staticFieldName           = field;
                set.isContentCustomField      = false;
                set.isEnabled = false;
                set.isVisible = false;
                set.sortOrder = sortOrder;

                AddFieldSetting(set);

                sortOrder++;
            }

            //add custom fields
            awContent content = new ContentLibrary().Get(contentId);

            System.Collections.Generic.IEnumerable <AWAPI_Data.CustomEntities.ContentCustomField> cstFlds = new ContentCustomFieldLibrary().GetFieldList(contentId, true);
            if (cstFlds != null && cstFlds.Count() > 0)
            {
                var customFields = from r in cstFlds
                                   where r.isEnabled &&
                                   (r.applyToSubContents == false && r.fieldContentId.Equals(contentId) ||
                                    r.applyToSubContents && r.fieldContentId.Equals(content.parentContentId))
                                   orderby r.sortOrder
                                   select r;
                if (customFields != null && customFields.Count() > 0)
                {
                    cstFlds = customFields.ToList();
                    foreach (AWAPI_Data.CustomEntities.ContentCustomField cf in cstFlds)
                    {
                        awContentFormFieldSetting set = new awContentFormFieldSetting();
                        set.contentFormFieldSettingId = AWAPI_Common.library.MiscLibrary.CreateUniqueId();
                        set.contentFormId             = contentFormId;
                        set.contentCustomFieldId      = cf.customFieldId;
                        set.staticFieldName           = "";
                        set.isContentCustomField      = true;
                        set.isEnabled = false;
                        set.isVisible = false;
                        set.sortOrder = sortOrder;

                        AddFieldSetting(set);

                        sortOrder = sortOrder + 10;
                    }
                }
            }

            if (submitChanges)
            {
                _context.SubmitChanges();
            }
        }