Exemple #1
0
        public ActionResult Index()
        {
            var comments         = _commentRepository.GetAllComments();
            var posts            = _postRepository.GetPostsByUserID(GetUserId()).Select(p => p.PostID);
            var filteredComments = comments.Where(c => posts.Contains(c.PostID)).ToList();

            var model = new AdminDashboardViewModel
            {
                PostCount       = _postRepository.GetPostsByUserID(GetUserId(), 1).Count,
                PagesCount      = _postRepository.GetPostsByUserID(GetUserId(), 2).Count, // at this point non-admin users cannot add pages
                CategoriesCount = _categoryRepository.GetCategories().Count,
                TagsCount       = _tagRepository.GetAllTags().Count,

                AllCommentsCount = filteredComments.Count(),
                ApprovedCount    = filteredComments.Count(c => c.CommentStatus == 0),
                PendingCount     = filteredComments.Count(c => c.CommentStatus == 1),
                SpamCount        = filteredComments.Count(c => c.CommentStatus == 2),

                CanView = GetUserId() == 1,

                BlogName = SettingsRepository.BlogName
            };

            return(View(model));
        }
Exemple #2
0
        public static List <TagEntity> GetTagEntities(this ITag tagRepository, List <string> tags)
        {
            var newTags = new List <string>();
            var allTags = tagRepository.GetAllTags();

            var existingTags = allTags.Select(t => t.TagName.ToLower()).ToList();

            tags.ForEach(tag =>
            {
                if (tag != null && tag.Trim() != string.Empty && !existingTags.Contains(tag.ToLower()) && newTags.SingleOrDefault(newtag => newtag.ToLower() == tag.ToLower()) == null)
                {
                    newTags.Add(tag.Trim());
                }
            });

            var allSlugs = allTags.Select(t => t.TagSlug).ToList();

            var newTagsList = new List <TagEntity>();

            newTags.ForEach(tag =>
            {
                var slug = tag.GetUniqueSlug(allSlugs);
                allSlugs.Add(slug);
                newTagsList.Add(new TagEntity {
                    TagName = tag, TagSlug = slug
                });
            });

            return(newTagsList);
        }
Exemple #3
0
        private TagEntity GetTagEntity(string tagName)
        {
            var tagEntity = _tagRepository.GetAllTags().SingleOrDefault(t => t.TagSlug == tagName.ToLower()) ??
                            new TagEntity {
                TagName = tagName
            };

            return(tagEntity);
        }
Exemple #4
0
        public ActionResult ManageTags([DefaultValue(1)] int page)
        {
            if (!User.IsInRole("SuperAdmin") && !User.IsInRole("Admin"))
            {
                return(RedirectToAction("Index", "Home", new { Area = "" }));
            }

            var allTags  = _tagRepository.GetAllTags();
            var tagModel = new AdminTagsViewModel
            {
                Tags       = allTags.Skip((page - 1) * _itemsPerPage).Take(_itemsPerPage).ToList(),
                PagingInfo = new PagingInformation
                {
                    CurrentPage  = page,
                    ItemsPerPage = _itemsPerPage,
                    TotalItems   = allTags.Count
                },
                OneTimeCode = GetToken(),
                Title       = SettingsRepository.BlogName
            };

            return(View(tagModel));
        }
        private static List<TagEntity> GetSelectedTags(string selectedTags, ITag tagRepository)
        {
            var tagStatus = new List<TagEntity>();

            if (selectedTags.Trim() != string.Empty)
            {
                var selectedTagsSplit = selectedTags.Split(',').ToList();
                var allTags = tagRepository.GetAllTags();

                selectedTagsSplit.ForEach(tag =>
                {
                    var tagEntity = new TagEntity { TagID = allTags.Single(t => t.TagName.ToLower() == tag.ToLower()).TagID };
                    tagStatus.Add(tagEntity);
                });
            }

            return tagStatus;
        }
        private static List <TagEntity> GetSelectedTags(string selectedTags, ITag tagRepository)
        {
            var tagStatus = new List <TagEntity>();

            if (selectedTags.Trim() != string.Empty)
            {
                var selectedTagsSplit = selectedTags.Split(',').ToList();
                var allTags           = tagRepository.GetAllTags();

                selectedTagsSplit.ForEach(tag =>
                {
                    var tagEntity = new TagEntity {
                        TagID = allTags.Single(t => t.TagName.ToLower() == tag.ToLower()).TagID
                    };
                    tagStatus.Add(tagEntity);
                });
            }

            return(tagStatus);
        }
        public ActionResult <IEnumerable <TagReadDto> > GetAllTags()
        {
            var TagItems = _repository.GetAllTags();

            return(Ok(_mapper.Map <IEnumerable <TagReadDto> >(TagItems)));
        }