コード例 #1
0
        public ArgumentModel List(int categoryId, int pageSize, int pageNumber)
        {
            var model = new ArgumentModel();

            //SEO
            ViewBag.description = _categoryService.GetById(categoryId).description;

            //List
            var excludeRecords = (pageSize * pageNumber) - pageSize;
            var total          = _argumentService.GetByCategoryId(categoryId).Count;

            model.sectionName = _categoryService.GetById(categoryId).name;
            model.pageSize    = pageSize;
            model.pageTotal   = Math.Ceiling((double)total / pageSize);
            model.arguments   = _argumentService.GetByCategoryId(categoryId);

            foreach (var argument in model.arguments)
            {
                model.argumentsDisplay.Add(new ArgumentDisplay()
                {
                    id         = argument.id,
                    slug       = _slugService.GetById(argument.slugId).name,
                    coverImage = _photoService.GetById(argument.coverImageId).path,
                    title      = argument.name
                });
            }

            return(model);
        }
コード例 #2
0
ファイル: PostController.cs プロジェクト: Elorvetti/TreA
        public PostModel GetByCategoryAndArgumentId(int categoryId, int argumentId, int livello, int idPadre)
        {
            var model = new PostModel();

            model.arguments = _argumentService.GetByCategoryId(categoryId, livello, idPadre);
            model.posts     = _postService.GetAllByCategoryAndArgumentId(categoryId, argumentId);

            return(model);
        }
コード例 #3
0
ファイル: CategoryController.cs プロジェクト: Elorvetti/TreA
        public void UpdateSlug(CategoryModel category)
        {
            var categorySlug = _commonService.cleanStringPath(category.name);

            //Get all argument with this category id and update slug
            var arguments = _argumentService.GetByCategoryId(category.id);

            foreach (var arg in arguments)
            {
                var slug    = _slugService.GetById(arg.slugId).name;
                var replace = _slugService.GetById(category.slugId).name.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray();
                var newSlug = slug.Replace(replace[replace.Length - 1], categorySlug);
                _slugService.Update(arg.slugId, newSlug);
            }

            //Get all post with this category id and update slug
            var posts = _postService.GetAllByCategory(category.id);

            foreach (var post in posts)
            {
                var slug    = _slugService.GetById(post.slugId).name;
                var replace = _slugService.GetById(category.slugId).name.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray();
                var newSlug = slug.Replace(replace[replace.Length - 1], categorySlug);
                _slugService.Update(post.slugId, newSlug);
            }

            var oldSlug   = _slugService.GetById(category.slugId).name;
            var slugArray = oldSlug.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray();
            var name      = oldSlug.Replace(slugArray[slugArray.Length - 1], categorySlug);

            _slugService.Update(category.slugId, name);
        }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: Elorvetti/TreA
        public HomeModel GetCategory()
        {
            var model = new HomeModel();

            var categories = _categoryService.GetAll();

            foreach (var category in categories)
            {
                model.categoryMenus.Add(new CategoryMenu()
                {
                    id       = category.id,
                    name     = category.name,
                    HasChild = _argumentService.GetByCategoryId(category.id).Any() ? true : false,
                });
            }

            return(model);
        }
コード例 #5
0
        public Categories GetCategoryChildId(int id, int idPadre)
        {
            var model = new CategoryModel();

            model.id        = id;
            model.arguments = _argumentService.GetByCategoryId(id, 1, idPadre);
            model.posts     = _postService.GetAllByCategoryId(id);
            return(model);
        }
コード例 #6
0
        public ArgumentModel GetByCategoryId(int id, int level = 1, int idPadre = 0)
        {
            var model = new ArgumentModel();

            model.arguments = _argumentService.GetByCategoryId(id, level, idPadre);
            model.posts     = _postService.GetAllByCategoryAndArgumentId(id, idPadre);

            return(model);
        }
コード例 #7
0
ファイル: RewriteController.cs プロジェクト: Elorvetti/TreA
        public IActionResult Index()
        {
            var request = HttpContext.Request;
            var host    = request.Host;
            var slug    = request.QueryString.Value.Replace("?param=", "/Blog/");

            var entity = _slugService.GetByName(slug).entityname;
            var id     = _slugService.GetByName(slug).id;

            if (entity == "Category")
            {
                var categoryId = _categoryService.GetBySlugId(id).id;
                var arguments  = _argumentService.GetByCategoryId(categoryId);

                var argumentModel = new ArgumentController(_argumentService, _categoryService, _postService, _slugService, _photoService).List(categoryId, 50, 1);

                //SEO
                ViewBag.description = _categoryService.GetById(categoryId).description;

                return(View("~/Views/Argument/List.cshtml", argumentModel));
            }
            else if (entity == "Argument")
            {
                var argumentId = _argumentService.GetBySlugId(id).id;
                var posts      = _postService.GetByArgumentId(argumentId);

                if (posts.Count == 0 || posts.Count > 1)
                {
                    var postListModel = new PostController(_categoryService, _argumentService, _postService, _albumService, _photoService, _videoService, _slugService, _reviewService).List(argumentId, 50, 1);

                    //SEO
                    ViewBag.description = _argumentService.GetById(argumentId).description;

                    return(View("~/Views/Post/List.cshtml", postListModel));
                }
                else
                {
                    var idPost    = posts[0].id;
                    var modelPost = new PostController(_categoryService, _argumentService, _postService, _albumService, _photoService, _videoService, _slugService, _reviewService).GetByPostId(idPost);

                    //SEO
                    ViewBag.description = Regex.Replace(modelPost.testo, "<.*?>", string.Empty).Substring(0, 255);

                    //POST TITLE
                    ViewBag.title    = modelPost.title;
                    ViewBag.subtitle = modelPost.subtitle;

                    return(View("~/Views/Post/GetById.cshtml", modelPost));
                }
            }

            var postId    = _postService.GetBySlugId(id).id;
            var postModel = new PostController(_categoryService, _argumentService, _postService, _albumService, _photoService, _videoService, _slugService, _reviewService).GetByPostId(postId);

            //SEO
            ViewBag.description = Regex.Replace(postModel.testo, "<.*?>", string.Empty).Substring(0, 255);

            //POST TITLE
            ViewBag.title    = postModel.title;
            ViewBag.subtitle = postModel.subtitle;

            return(View("~/Views/Post/GetById.cshtml", postModel));
        }
コード例 #8
0
        public PostModel GetByPostId(int id)
        {
            var model = new PostModel();

            //Convert slugId to Int and Find Post
            var postId = Convert.ToInt32(id);
            var post   = _postService.GetById(postId);

            //BreadCrumb
            model.categoryId   = _categoryService.GetById(post.categoryId).id;
            model.categoryName = _categoryService.GetById(post.categoryId).name;

            var argument = _argumentService.GetById(post.argumentId);

            if (argument != null)
            {
                model.argumentName = argument.name;

                model.breadcrumb.Add(new breadcrumbs()
                {
                    name = model.categoryName,
                    slug = _slugService.GetById(_categoryService.GetById(model.categoryId).slugId).name
                });

                model.breadcrumb.Add(new breadcrumbs()
                {
                    name = model.argumentName,
                    slug = _slugService.GetById(_argumentService.GetById(post.argumentId).slugId).name
                });

                model.breadcrumb.Add(new breadcrumbs()
                {
                    name = post.title,
                    slug = _slugService.GetById(_postService.GetById(postId).slugId).name
                });
            }
            else
            {
                model.breadcrumb.Add(new breadcrumbs()
                {
                    name = model.categoryName,
                    slug = _slugService.GetById(_categoryService.GetById(model.categoryId).slugId).name
                });

                model.breadcrumb.Add(new breadcrumbs()
                {
                    name = post.title,
                    slug = _slugService.GetById(_postService.GetById(postId).slugId).name
                });
            }

            //SEO
            ViewBag.description = Regex.Replace(post.testo, "<.*?>", string.Empty).Substring(0, 255);

            //Post data
            model.id         = post.id;
            model.argumentId = post.argumentId;
            model.coverImage = _photoService.GetById(post.PhotoId).path;
            model.title      = post.title;
            model.subtitle   = post.subtitle;
            model.testo      = post.testo;
            model.albumId    = post.albumId;

            ViewBag.title    = post.title;
            ViewBag.subtitle = post.subtitle;


            //Related Post
            var realtedPosts = _postService.GetByCategoryId(post.categoryId);

            foreach (var relatedPost in realtedPosts)
            {
                model.realtedPost.Add(new ArgumentDisplay()
                {
                    id       = relatedPost.id,
                    title    = relatedPost.title,
                    subtitle = relatedPost.subtitle,
                    slug     = _slugService.GetById(relatedPost.slugId).name
                });
            }

            //Related argument
            var relatedArguments = _argumentService.GetByCategoryId(post.categoryId);

            foreach (var relatedArgument in relatedArguments)
            {
                model.realtedArgument.Add(new ArgumentDisplay()
                {
                    id         = relatedArgument.id,
                    title      = relatedArgument.name,
                    nOfElement = _postService.GetByArgumentId(relatedArgument.id).Count,
                    slug       = _slugService.GetById(relatedArgument.slugId).name
                });
            }

            //Album
            var album = _albumService.GetById(post.albumId);

            if (album != null)
            {
                var imageIds = album.idImmagini.Split('|');
                foreach (var imageId in imageIds)
                {
                    if (!string.IsNullOrEmpty(imageId))
                    {
                        model.album.Add(_photoService.GetById(Convert.ToInt32(imageId)).path);
                    }
                }

                var videoIds = album.idVideo.Split('|');
                foreach (var videoId in videoIds)
                {
                    if (!string.IsNullOrEmpty(videoId))
                    {
                        model.album.Add(_videoService.GetById(Convert.ToInt32(videoId)).path);
                    }
                }
            }

            var totalReview = _reviewService.GetByPostId(post.id).Count;

            model.sectionName          = "Reviews/";
            model.reviewData.pageSize  = 10;
            model.reviewData.pageTotal = Math.Ceiling((double)totalReview / 10);
            model.reviewData.reviews   = _reviewService.GetByPostId(post.id);

            return(model);
        }