Пример #1
0
        /// <summary>
        /// Прикрепление пользователям доступных сайтов
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public override bool updateUserSiteLinks(ContentLinkModel data)
        {
            try
            {
                using (var db = new CMSdb(_context))
                {
                    using (var tran = db.BeginTransaction())
                    {
                        var getSite = db.cms_sitess.Where(s => s.id == data.LinkId);
                        var alias   = getSite.SingleOrDefault().c_alias;

                        //Если существует
                        var linkExist = db.cms_user_site_links
                                        .Where(l => l.f_user == data.ObjctId)
                                        .Where(l => l.f_site == alias);

                        if (linkExist.Any())
                        {
                            if (!data.Checked)
                            {
                                linkExist.Delete();
                            }
                        }
                        else
                        {
                            if (data.Checked)
                            {
                                var cdUserSiteLink = new cms_user_site_link()
                                {
                                    id     = Guid.NewGuid(),
                                    f_user = data.ObjctId,
                                    f_site = alias
                                };
                                db.Insert(cdUserSiteLink);
                            }
                        }

                        var log = new LogModel()
                        {
                            Site     = _domain,
                            Section  = LogSection.Users,
                            Action   = LogAction.change_resolutions,
                            PageId   = data.ObjctId,
                            PageName = alias,
                            UserId   = _currentUserId,
                            IP       = _ip,
                        };
                        insertLog(log);

                        tran.Commit();
                        return(true);
                    }
                }
            }
            catch
            {
                return(false);
            }
        }
Пример #2
0
        private async Task <BrandListViewModel.BrandNode> GetBrandNodesAsync(int maxColumns)
        {
            var brandNodes = new BrandListViewModel.BrandNode();

            var allBrandPages = await GetNavigationModelAsync();

            if (!allBrandPages.Any())
            {
                return(brandNodes);
            }

            var average  = Convert.ToInt32(Math.Round((decimal)allBrandPages.Count() / maxColumns, MidpointRounding.AwayFromZero));
            var rowIndex = 0;

            var node = new BrandListViewModel.BrandNode();

            brandNodes.Add(node);
            BrandListViewModel.BrandNode letterGroup = null;
            foreach (var brandPage in allBrandPages)
            {
                if (brandPage.Name is object)
                {
                    var brandContent = new ContentLinkModel()
                    {
                        Name      = brandPage.Name,
                        Url       = brandPage.Url,
                        ExtraInfo = brandPage.ExtraInfo
                    };

                    var firstLetter = brandContent.Name.Substring(0, 1);
                    if (letterGroup == null || !firstLetter.Equals(letterGroup.Value.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        letterGroup = new BrandListViewModel.BrandNode(new ContentLinkModel {
                            Name = firstLetter
                        });
                        node.Add(letterGroup);

                        if (rowIndex > average)
                        {
                            rowIndex = 0;
                            node     = new BrandListViewModel.BrandNode();
                            brandNodes.Add(node);
                        }
                    }

                    letterGroup.Add(new BrandListViewModel.BrandNode(brandContent));
                    rowIndex++;
                }
            }

            if (node.Count == 0)
            {
                brandNodes.Remove(node);
            }

            return(brandNodes);
        }
Пример #3
0
 public ActionResult UpdateUserLinkToSite(ContentLinkModel linkData)
 {
     if (linkData != null)
     {
         var res = _cmsRepository.updateUserSiteLinks(linkData);
         if (res)
         {
             return(Json("Success"));
         }
     }
     //return Response.Status = "OK";
     return(Json("An Error Has occourred")); //Ne
 }
Пример #4
0
        private void UnSelect(ContentLinkModel link)
        {
            link.IsSelected = false;
            if (link.Links == null)
            {
                return;
            }

            foreach (var child in link.Links)
            {
                UnSelect(child);
            }
        }
Пример #5
0
        /// <summary>
        /// Добавляем связи новостей и организаций
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public override bool updateContentLink(ContentLinkModel data)
        {
            try
            {
                using (var db = new CMSdb(_context))
                {
                    using (var tran = db.BeginTransaction())
                    {
                        //var link = db.content_content_links
                        //                        .Where(w => w.f_content == data.ObjctId)
                        //                        .Where(w => w.f_link == data.LinkId);

                        //if(link.Any())
                        //{
                        //    if(!data.Checked)
                        //    {
                        //        //delete
                        //        db.content_content_links
                        //                        .Where(w => w.f_content == data.ObjctId)
                        //                        .Where(w => w.f_link_type == data.LinkType.ToString().ToLower())
                        //                        .Where(w => w.f_link == data.LinkId)
                        //                        .Where(w => w.b_origin != true)
                        //                        .Delete();
                        //    }
                        //}
                        //else
                        //{
                        //    if (data.Checked)
                        //    {
                        //        //insert
                        //        db.content_content_links
                        //                   .Value(v => v.f_content, data.ObjctId)
                        //                   .Value(v => v.f_content_type, data.ObjctType.ToString().ToLower())
                        //                   .Value(v => v.f_link, data.LinkId)
                        //                   .Value(v => v.f_link_type, data.LinkType.ToString().ToLower())
                        //                   .Insert();
                        //    }
                        //}

                        tran.Commit();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                OnDislyEvent(new DislyEventArgs(LogLevelEnum.Debug, "", ex));
                return(false);
            }
        }
Пример #6
0
        private bool IsChildSelected(ContentLinkModel link)
        {
            var anySelected = link.IsSelected;

            if (link.Links == null)
            {
                return(anySelected);
            }
            foreach (var child in link.Links)
            {
                if (IsChildSelected(child))
                {
                    anySelected = child.IsSelected = true;
                }
            }

            return(anySelected);
        }
Пример #7
0
        private List <ContentLinkModel> GetSubCategoryLinks(CategoryModel categoryModel, bool showNextLevel)
        {
            var links = new List <ContentLinkModel>();

            foreach (var subCategory in _categoryService.GetChildCategories(categoryModel.Category.SystemId, Guid.Empty)
                     .Where(x => x.IsPublished(_channelSystemId) && _authorizationService.HasOperation <Category>(Operations.Entity.Read, x.SystemId))
                     .Select(x => x.MapTo <CategoryModel>()))
            {
                var subLinkModel = new ContentLinkModel
                {
                    Name       = subCategory.Category.Localizations.CurrentCulture.Name,
                    IsSelected = _selectedStructureId.Contains(subCategory.Category.SystemId),
                    Url        = _urlService.GetUrl(subCategory.Category)
                };
                if (showNextLevel)
                {
                    subLinkModel.Links = GetSubCategoryLinks(subCategory, false);
                }
                links.Add(subLinkModel);
            }

            return(links);
        }
Пример #8
0
        private List <ContentLinkModel> GetSubPageLinks(PointerPageItem pointerPageItem, bool showNextLevel)
        {
            var links = new List <ContentLinkModel>();

            foreach (var subPage in _pageService.GetChildPages(pointerPageItem.EntitySystemId).Select(x => new PointerPageItem {
                EntitySystemId = x.SystemId, ChannelSystemId = pointerPageItem.ChannelSystemId
            })
                     .Select(x => new Tuple <PointerPageItem, LinkModel>(x, x.MapTo <LinkModel>())).Where(x => x.Item2?.Href != null))
            {
                var subLinkModel = new ContentLinkModel
                {
                    Name       = subPage.Item2.Text,
                    Url        = subPage.Item2.Href,
                    IsSelected = _selectedStructureId.Contains(subPage.Item1.EntitySystemId)
                };
                if (showNextLevel)
                {
                    subLinkModel.Links = GetSubPageLinks(subPage.Item1, false);
                }
                links.Add(subLinkModel);
            }

            return(links);
        }
Пример #9
0
        /// <summary>
        /// Builds model
        /// </summary>
        /// <returns></returns>
        public async Task <NavigationViewModel> BuildAsync()
        {
            var model = new NavigationViewModel();

            SetSelectedPages(_requestModelAccessor.RequestModel.CurrentPageModel, _requestModelAccessor.RequestModel.WebsiteModel.SystemId);
            var megaMenuPages = GetMegaMenuPages();

            foreach (var megaMenuPage in megaMenuPages)
            {
                var linkName = megaMenuPage?.Page?.Localizations.CurrentCulture.Name;
                if (string.IsNullOrEmpty(linkName))
                {
                    continue;
                }
                var contentLinkModel = new ContentLinkModel
                {
                    Name = linkName
                };
                var             categoryModel   = megaMenuPage.GetValue <Guid?>(MegaMenuPageFieldNameConstants.MegaMenuCategory)?.MapTo <CategoryModel>();
                PointerPageItem pointerPageItem = null;
                // If a category is chosen, the link will redirect to the category in the first place
                if (categoryModel != null)
                {
                    if (categoryModel.Category == null || !categoryModel.Category.IsPublished(_channelSystemId))
                    {
                        //Category must be published
                        continue;
                    }
                    contentLinkModel.Url        = _urlService.GetUrl(categoryModel.Category);
                    contentLinkModel.IsSelected = _selectedStructureId.Contains(categoryModel.Category.SystemId);
                }
                else
                {
                    pointerPageItem = megaMenuPage.GetValue <PointerPageItem>(MegaMenuPageFieldNameConstants.MegaMenuPage);
                    var linkModel = pointerPageItem?.MapTo <LinkModel>();
                    if (linkModel == null)
                    {
                        //Page must be active
                        continue;
                    }

                    contentLinkModel.Url        = linkModel.Href;
                    contentLinkModel.IsSelected = _selectedStructureId.Contains(pointerPageItem.EntitySystemId);
                }

                model.ContentLinks.Add(contentLinkModel);

                if (megaMenuPage.GetValue <bool>(MegaMenuPageFieldNameConstants.MegaMenuShowContent))
                {
                    if (megaMenuPage.GetValue <bool>(MegaMenuPageFieldNameConstants.MegaMenuShowSubCategories))
                    {
                        // Show two levels of sub categories/pages
                        contentLinkModel.Links = categoryModel != null?GetSubCategoryLinks(categoryModel, true) : GetSubPageLinks(pointerPageItem, true);
                    }
                    else
                    {
                        // Render mega menu context
                        contentLinkModel.Links = await GetMegaMenuContentAsync(megaMenuPage, categoryModel);
                    }
                }
                if (!contentLinkModel.IsSelected)
                {
                    contentLinkModel.IsSelected = IsChildSelected(contentLinkModel);
                }
            }

            var selectedCount = model.ContentLinks.Count(x => x.IsSelected);

            if (selectedCount <= 1)
            {
                return(model);
            }

            var selectedPagesToClear = model.ContentLinks.Where(x => x.IsSelected).Take(selectedCount - 1);

            foreach (var page in selectedPagesToClear)
            {
                UnSelect(page);
            }
            return(model);
        }
Пример #10
0
        private async Task <List <ContentLinkModel> > GetMegaMenuContentAsync(PageModel pageModel, CategoryModel categoryModel)
        {
            var megaMenuContentLinks = new List <ContentLinkModel>();
            var megaMenus            = pageModel.GetValue <IList <MultiFieldItem> >(MegaMenuPageFieldNameConstants.MegaMenuColumn);

            if (megaMenus != null)
            {
                foreach (var megaMenu in megaMenus)
                {
                    var contentLink = new ContentLinkModel
                    {
                        Name = megaMenu.Fields.GetValue <string>(MegaMenuPageFieldNameConstants.MegaMenuColumnHeader, CultureInfo.CurrentUICulture)
                    };

                    var links = new List <ContentLinkModel>();
                    // Categories has higher priority
                    var categories = megaMenu.Fields.GetValue <IList <PointerItem> >(MegaMenuPageFieldNameConstants.MegaMenuCategories)?.Select(x => x.EntitySystemId.MapTo <CategoryModel>()).Where(x => x != null && x.Category.IsPublished(_channelSystemId));
                    if (categories != null)
                    {
                        links.AddRange(categories.Select(category => new ContentLinkModel()
                        {
                            Name       = category.Category.Localizations.CurrentCulture.Name,
                            Url        = _urlService.GetUrl(category.Category),
                            IsSelected = _selectedStructureId.Contains(category.Category.SystemId)
                        }));
                    }
                    else if (megaMenu.Fields.GetValue <IList <PointerItem> >(MegaMenuPageFieldNameConstants.MegaMenuPages) != null)
                    {
                        var pages = megaMenu.Fields.GetValue <IList <PointerItem> >(MegaMenuPageFieldNameConstants.MegaMenuPages).OfType <PointerPageItem>().ToList().Select(x => new Tuple <Guid, LinkModel>(x.EntitySystemId, x.MapTo <LinkModel>())).Where(x => x.Item2?.Href != null);

                        links.AddRange(pages.Select(contentPageModel => new ContentLinkModel()
                        {
                            Name       = contentPageModel.Item2.Text,
                            Url        = contentPageModel.Item2.Href,
                            IsSelected = _selectedStructureId.Contains(contentPageModel.Item1)
                        }));
                    }
                    // Filters works just with category
                    else if (categoryModel != null && megaMenu.Fields.GetValue <IList <string> >(MegaMenuPageFieldNameConstants.MegaMenuFilters) != null)
                    {
                        links.AddRange(await GetFiltersAsync(categoryModel, megaMenu.Fields.GetValue <IList <string> >(MegaMenuPageFieldNameConstants.MegaMenuFilters).ToList()));
                    }
                    else if (!string.IsNullOrEmpty(megaMenu.Fields.GetValue <string>(MegaMenuPageFieldNameConstants.MegaMenuEditor, CultureInfo.CurrentCulture)))
                    {
                        links.Add(new ContentLinkModel()
                        {
                            Name = _contentProcessorService.Process(megaMenu.Fields.GetValue <string>(MegaMenuPageFieldNameConstants.MegaMenuEditor, CultureInfo.CurrentCulture))
                        });
                    }

                    if (!string.IsNullOrEmpty(megaMenu.Fields.GetValue <string>(MegaMenuPageFieldNameConstants.MegaMenuAdditionalLink, CultureInfo.CurrentCulture)))
                    {
                        var link = string.Empty;
                        var linkToCategoryModel = megaMenu.Fields.GetValue <Guid?>(MegaMenuPageFieldNameConstants.MegaMenuLinkToCategory)?.MapTo <CategoryModel>();
                        if (linkToCategoryModel != null)
                        {
                            if (linkToCategoryModel.Category != null && linkToCategoryModel.Category.IsPublished(_channelSystemId))
                            {
                                link = _urlService.GetUrl(linkToCategoryModel.Category);
                            }
                        }
                        else
                        {
                            var linkedPageModel = megaMenu.Fields.GetValue <PointerPageItem>(MegaMenuPageFieldNameConstants.MegaMenuLinkToPage)?.MapTo <LinkModel>();
                            if (linkedPageModel != null)
                            {
                                link = linkedPageModel.Href;
                            }
                        }
                        if (!string.IsNullOrEmpty(link))
                        {
                            links.Add(new ContentLinkModel()
                            {
                                Attributes = new Dictionary <string, string>
                                {
                                    {
                                        "cssValue", "nav-link"
                                    }
                                },
                                Name = megaMenu.Fields.GetValue <string>(MegaMenuPageFieldNameConstants.MegaMenuAdditionalLink, CultureInfo.CurrentCulture),
                                Url  = link
                            });
                        }
                    }
                    contentLink.Links = links;
                    megaMenuContentLinks.Add(contentLink);
                }
            }

            return(megaMenuContentLinks);
        }
Пример #11
0
 public BrandNode(ContentLinkModel value)
 {
     Value = value;
 }
Пример #12
0
 public abstract bool updateUserSiteLinks(ContentLinkModel link);
Пример #13
0
 public abstract bool updateContentLink(ContentLinkModel model);