public IActionResult All(int pageSize, int pageNumber) { var model = new ArgumentModel(); //SEO ViewBag.description = "Categorie disponibili"; //List var excludeRecords = (pageSize * pageNumber) - pageSize; var total = _argumentService.GetAll().Count; model.sectionName = "Lista Categorie"; model.pageSize = pageSize; model.pageTotal = Math.Ceiling((double)total / pageSize); model.arguments = _argumentService.GetAll(); 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, descrizione = argument.description.Length > 200 ? argument.description.Substring(0, 200) : argument.description }); } return(View(model)); }
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); }
public IActionResult Index() { var model = new HomeModel(); //SEO var homeSetting = _homeService.GetSetting(); ViewBag.description = homeSetting.headerTesto; //Get last post var posts = _postService.GetLast(5); var newsletterImageId = _homeService.GetSetting().newsletterImageId; var newsletterBackgroundImage = _photoService.GetById(newsletterImageId).path; model.Newsletter.backgroundImage = newsletterBackgroundImage; foreach (var post in posts) { model.PostDisplays.Add(new PostDisplayModel() { id = post.id, slug = _slugService.GetById(post.slugId).name, coverImage = _photoService.GetById(post.PhotoId).path, title = post.title, testo = Regex.Replace(post.testo, "<.*?>", string.Empty).Substring(0, 200) }); } var podcasts = _podcastService.GetAll(); foreach (var podcast in podcasts) { model.podcasts.Add(new PodcastModel() { id = podcast.id, name = podcast.name, description = podcast.description, path = podcast.path }); } return(View(model)); }
public int InsertSlug(ArgumentModel argument, int categoryId) { var categorySlugId = _categoryService.GetById(categoryId).slugId; var categorySlug = _slugService.GetById(categorySlugId).name; var name = ""; if (argument.idPadre > 0) { var idPadre = _argumentService.GetById(argument.idPadre).id; var nomePadre = _argumentService.GetById(idPadre).name; name = string.Concat(categorySlug, nomePadre, '/', _commonService.cleanStringPath(argument.name), '/'); } else { name = string.Concat(categorySlug, _commonService.cleanStringPath(argument.name), '/'); } var model = new SlugModel(); model.name = name; model.entityname = "Argument"; _slugService.Insert(model); return(_slugService.GetByName(name).id); }
public IActionResult Preview(int id) { var model = new PostModel(); //Convert slugId to Int and Find Post var post = _postService.GetById(id); //BreadCrumb model.categoryName = _categoryService.GetById(post.categoryId).name; var argument = _argumentService.GetById(post.argumentId); if (argument != null) { model.argumentName = argument.name; } model.breadcrumb = string.Concat(model.categoryName, " > ", model.argumentName, " > ", post.title); //Post data model.id = post.id; model.coverImage = _photoService.GetById(post.PhotoId).path; model.title = post.title; model.subtitle = post.subtitle; model.testo = post.testo; model.albumId = post.albumId; model.argumentId = post.argumentId; 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.albumDisplay.Add(_photoService.GetById(Convert.ToInt32(imageId)).path); } } var videoIds = album.idVideo.Split('|'); foreach (var videoId in videoIds) { if (!string.IsNullOrEmpty(videoId)) { model.albumDisplay.Add(_videoService.GetById(Convert.ToInt32(videoId)).path); } } } return(View(model)); }
public IActionResult All(int pageSize, int pageNumber) { var model = new PostModel(); //SEO ViewBag.description = "Tutti i Post disponibili"; var excludeRecords = (pageSize * pageNumber) - pageSize; var total = _postService.GetAllActive().Count; model.sectionName = "Lista Post"; model.pageSize = pageSize; model.pageTotal = Math.Ceiling((double)total / pageSize); model.posts = _postService.GetAllActive(excludeRecords, pageSize); foreach (var post in model.posts) { model.postsDisplay.Add(new PostDisplayModel() { id = post.id, slug = _slugService.GetById(post.slugId).name, coverImage = _photoService.GetById(post.PhotoId).path, title = post.title, testo = Regex.Replace(post.testo, "<.*?>", string.Empty).Substring(0, 200) }); } return(View(model)); }