示例#1
0
        //Для транслитерации урлов в уже существующих новостях
        //private void GenerateRelativeUrls()
        //{

        //    var hearts = _heartService.GetHearts(typeof(NewsItem).FullName);
        //    StringBuilder sb = new StringBuilder("");
        //    foreach (var heart in hearts)
        //    {
        //        string old = heart.RelativeUrl;
        //        string url = FormattingHelper.ToTranslitedUrl(heart.RelativeUrl, 250);
        //        heart.RelativeUrl = url;
        //        _heartService.UpdateHeart(heart);


        //        sb.AppendLine($"@@@{old}***{url}###");


        //    }

        //    Console.Write(sb.ToString());


        //}

        public IEnumerable <NewsItem> GetAllNews()
        {
            var dataRes = _newsItemGateway.Select();
            var res     = Mapper.Map <ICollection <NewsItem> >(dataRes);

            var hearts = _heartService.GetHearts(res.Select(x => x.HeartId));

            foreach (var newsItem in res)
            {
                var heart = hearts.Single(x => x.HeartId == newsItem.HeartId);
                newsItem.FillHeart(heart);
                FillItem(newsItem);
            }
            return(res);
        }
示例#2
0
        public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            IHeartService categoryService = DependencyResolver.Current.GetService <IHeartService>();
            var           nodes           = new List <DynamicNode>();

            try
            {
                var categories = categoryService.GetHearts(typeof(Category).FullName);
                foreach (var category in categories)
                {
                    DynamicNode dynamicNode = new DynamicNode();
                    // ключ должен быть уникальным для каждой ноды
                    dynamicNode.Key = "category_" + category.HeartId;
                    dynamicNode.RouteValues.Add("relativeUrl", category.RelativeUrl);
                    dynamicNode.Route    = typeof(Category).FullName;
                    dynamicNode.Title    = category.Title;
                    dynamicNode.Protocol = "*";

                    dynamicNode.Attributes.Add("visibility", "MvcSiteMapProvider.Web.Mvc.XmlSiteMapResult");

                    nodes.Add(dynamicNode);
                }
            }
            catch (Exception e)
            {
                // если возникают косяки, не добавляем ничего в сайтмеп
            }

            return(nodes);
        }
示例#3
0
        public ICollection <CommentTopic> GetTopics(int startIndex, int count, out int totalCount)
        {
            var heartIds = _commentGateway.SelectHeartIds(startIndex, count, out totalCount);
            var hearts   = _heartService.GetHearts(heartIds);
            var res      = _mapper.Map <ICollection <CommentTopic> >(hearts);

            return(res);
        }
示例#4
0
        public ICollection <Heart> GetHearts()
        {
            var hearts = _heartService.GetHearts();

            foreach (var heart in hearts)
            {
                var typeObj = GetTypeByName(heart.Type);

                var displayNameAttr = typeObj.GetCustomAttribute <DisplayNameAttribute>();

                var displayName = displayNameAttr != null ? displayNameAttr.DisplayName : heart.Type.Split('.').Last();
                heart.Type = displayName;
            }

            return(hearts);

            //var types = hearts.Select(x => x.Type).Distinct();

            //ICollection<HeartGroup> groups = new List<HeartGroup>();

            //foreach (var type in types)
            //{
            //    var typeObj = GetTypeByName(type);

            //    var displayNameAttr = typeObj.GetCustomAttribute<DisplayNameAttribute>();

            //    var displayName = displayNameAttr != null ? displayNameAttr.DisplayName : type.Split('.').Last();

            //    var group = new HeartGroup() { Title = displayName };
            //    group.Hearts = hearts.Where(x => x.Type == type).ToList();

            //    groups.Add(group);

            //    //IsDefined(typeof(DisplayNameAttribute));
            //}

            //return groups;
        }