Exemple #1
0
        public void Update(TagCloudSettings settings, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                string sql = _sqlManager.GetSql("Sql.UpdateTagCloud.sql");
                dbm.SetSQL(sql);
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.AddParameter("@PageTenantId", FieldType.BigInt, settings.PageTenantId ?? (object)DBNull.Value);
                dbm.AddParameter("@PageId", FieldType.BigInt, settings.PageId ?? (object)DBNull.Value);
                dbm.AddParameter("@DisplayName", FieldType.NVarChar, 256, settings.DisplayName ?? (object)DBNull.Value);
                dbm.AddParameter("@Recursive", FieldType.Bit, settings.Recursive);
                dbm.AddParameter("@NoTagsMessage", FieldType.NVarChar, -1, settings.NoTagsMessage);
                dbm.ExecuteNonQuery();
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Exemple #2
0
        public void Read(TagCloudSettings settings, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                string sql = _sqlManager.GetSql("Sql.ReadTagCloud.sql");
                dbm.SetSQL(sql);
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.ExecuteReader();
                dbm.Read();
                settings.PageTenantId  = dbm.DataReaderValue("PageTenantId") == DBNull.Value ? null : (long?)dbm.DataReaderValue("PageTenantId");
                settings.PageId        = dbm.DataReaderValue("PageId") == DBNull.Value ? null : (long?)dbm.DataReaderValue("PageId");
                settings.DisplayName   = dbm.DataReaderValue("DisplayName") == DBNull.Value ? null : (string)dbm.DataReaderValue("DisplayName");
                settings.Recursive     = (bool)dbm.DataReaderValue("Recursive");
                settings.NoTagsMessage = (string)dbm.DataReaderValue("NoTagsMessage");
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
        public IElementContent GetContent(IElementSettings settings, IPageContext pageContext, IUnitOfWork unitOfWork = null)
        {
            // Get tag cloud content
            TagCloudContent content = new TagCloudContent {
                PartialViewName = "TagCloud"
            };

            // Get folder that tag cloud is targetting
            TagCloudSettings tagCloudSettings = (TagCloudSettings)settings;
            long             tenantId         = tagCloudSettings.PageTenantId ?? pageContext.Page.TenantId;
            long             pageId           = tagCloudSettings.PageId ?? pageContext.Page.PageId;

            if (pageId == pageContext.Page.PageId)
            {
                content.Page = pageContext.Page;
            }
            else
            {
                content.Page = _pageService.Read(tenantId, pageId, unitOfWork);
            }

            // Get tagged list
            content.TaggedList = new List <TagTagged>();
            foreach (Tag tag in pageContext.Tags)
            {
                IList <Tag> tags = pageContext.Tags.Where(t => t.Name != tag.Name).ToList();
                content.TaggedList.Add(new TagTagged
                {
                    Tag = tag,
                    RemoveTaggedList = _pagePortalService.GetTagsAsTextString(TagVariables.Separator, tags)
                });
            }

            // Get tags list if no tags currently selected
            if (content.TaggedList.Count == 0)
            {
                content.TagList = _pageService.ListTags(tenantId, pageId, tagCloudSettings.Recursive, unitOfWork);
            }
            else
            {
                content.TagList = new List <TagCount>();
            }

            // Get related tags list if tags currently selected
            if (content.TaggedList.Count > 0)
            {
                content.RelatedTagList = _pageService.ListTaggedPageTags(tenantId, pageId, pageContext.Tags, tagCloudSettings.Recursive, unitOfWork);
                content.Tags           = _pagePortalService.GetTagsAsTextString(TagVariables.Separator, pageContext.Tags);
            }
            else
            {
                content.RelatedTagList = new List <TagCount>();
            }

            // Return result
            return(content);
        }
Exemple #4
0
        public FormResult PostForm(Form form)
        {
            try
            {
                // Check permissions
                _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

                // Get page and element identifiers
                string[] parts     = form.Context.Split('|');
                long     pageId    = Convert.ToInt64(parts[0]);
                long     elementId = Convert.ToInt64(parts[1]);

                // Get website identifier
                long tenantId = _authenticationService.TenantId;

                // Get tag cloud page
                string pageValue        = ((SelectListField <string>)form.Fields["page"]).Value;
                long?  tagCloudPageId   = pageValue == string.Empty ? null : (long?)Convert.ToInt64(((SelectListField <string>)form.Fields["page"]).Value);
                long?  tagCloudTenantId = tagCloudPageId.HasValue ? (long?)tenantId : null;

                // Get the tag cloud element service
                IAdvancedElementService elementService = (IAdvancedElementService)_elementFactory.GetElementService(FormId);

                // Get updated tag cloud settings
                TagCloudSettings tagCloudSettings = (TagCloudSettings)elementService.New(_authenticationService.TenantId);
                tagCloudSettings.ElementId     = elementId;
                tagCloudSettings.DisplayName   = string.IsNullOrWhiteSpace(((TextField)form.Fields["displayName"]).Value) ? null : ((TextField)form.Fields["displayName"]).Value;
                tagCloudSettings.PageId        = tagCloudPageId;
                tagCloudSettings.PageTenantId  = tagCloudTenantId;
                tagCloudSettings.Recursive     = ((BooleanField)form.Fields["recursive"]).Value;
                tagCloudSettings.NoTagsMessage = ((TextField)form.Fields["noTagsMessage"]).Value;

                // Perform the update
                elementService.Update(tagCloudSettings);

                // Return form result with no errors
                return(_formHelperService.GetFormResult());
            }
            catch (ValidationErrorException ex)
            {
                // Return form result containing errors
                return(_formHelperService.GetFormResultWithValidationErrors(ex.Errors));
            }
            catch (Exception)
            {
                // Return form result containing unexpected error message
                return(_formHelperService.GetFormResultWithErrorMessage(ApplicationResource.UnexpectedErrorMessage));
            }
        }
Exemple #5
0
        public Form GetForm(string context)
        {
            // Check permissions
            _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

            // Get page and element identifiers
            string[] parts     = context.Split('|');
            long     pageId    = Convert.ToInt64(parts[0]);
            long     elementId = Convert.ToInt64(parts[1]);

            // Get current tag cloud settings
            Guid elementTypeId = FormId;
            IAdvancedElementService elementService   = (IAdvancedElementService)_elementFactory.GetElementService(elementTypeId);
            TagCloudSettings        tagCloudSettings = (TagCloudSettings)elementService.New(_authenticationService.TenantId);

            tagCloudSettings.ElementId = elementId;
            elementService.Read(tagCloudSettings);

            // Get possible parent pages for tag cloud
            long tenantId = _authenticationService.TenantId;
            ISearchParameters searchParameters = new SearchParameters {
                PageIndex = 0, PageSize = 1000
            };                                                                                            // TODO: Need way to return all pages, not have some max bound upper limit
            ISearchResult <Page> result = _pageService.List(tenantId, searchParameters, null, PageSortBy.Name, true, true, PageType.Folder, false);

            // Construct form
            Form form = new Form {
                Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context
            };

            form.Fields.Add("displayName", new TextField
            {
                Name                  = "displayName",
                Label                 = ElementResource.TagCloudDisplayNameLabel,
                MaxLength             = TagCloudLengths.DisplayNameMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.TagCloudDisplayNameMaxLengthMessage, "displayName", TagCloudLengths.DisplayNameMaxLength),
                Value                 = tagCloudSettings.DisplayName
            });
            form.Fields.Add("page", new SelectListField <string>
            {
                Name  = "page",
                Label = ElementResource.TagCloudPageLabel,
                Value = tagCloudSettings.PageId == null ? string.Empty : tagCloudSettings.PageId.Value.ToString(),
                Items = new List <ListFieldItem <string> > {
                    new ListFieldItem <string> {
                        Name = ElementResource.FolderDefaultOption, Value = string.Empty
                    }
                }
            });
            foreach (Page page in result.Items)
            {
                ((SelectListField <string>)form.Fields["page"]).Items.Add(new ListFieldItem <string> {
                    Name = page.Name, Value = page.PageId.ToString()
                });
            }
            form.Fields.Add("recursive", new BooleanField
            {
                Name  = "recursive",
                Label = ElementResource.TagCloudRecursiveLabel,
                Value = tagCloudSettings.Recursive
            });
            form.Fields.Add("noTagsMessage", new TextField
            {
                Name                 = "noTagsMessage",
                Label                = ElementResource.TagCloudNoTagsMessageLabel,
                Value                = tagCloudSettings.NoTagsMessage,
                Required             = true,
                RequiredErrorMessage = ElementResource.TagCloudNoTagsMessageRequiredMessage
            });
            form.SubmitLabel = ElementResource.TagCloudButtonLabel;

            // Return result
            return(form);
        }