public ActionResult Index() { var model = new TagIndexViewModel(); model.Tags = _tagRepository.GetAll(); return(View(model)); }
public ActionResult ModalSelect() { var model = new TagIndexViewModel(); model.Tags = _tagRepository.GetAll(); return(PartialView(model)); }
// [Route("Browse/ByTag/")] // [Route("Browse/ByTag/{tag}")] public IActionResult ByTag(string tag, int?page) { if (tag == null || tag == string.Empty) { return(this.Redirect("/Browse/Jobs/")); } if (!page.HasValue) { page = 1; } tag = tag.ToLower(); TagIndexViewModel viewModel = new TagIndexViewModel() { Name = tag, PagesCount = (int)Math.Ceiling(this.jobPostsService.GetJobCountByTag(tag) / GlobalConstants.ItemsPerPage), CurrentPage = (int)page, }; viewModel.JobsDisplayViewModel = new JobsDisplayViewModel { JobPosts = this.jobPostsService.GetAllByTag <JobPostViewModel>(tag, page), }; return(this.View(viewModel)); }
public ActionResult Create(TagIndexViewModel vm, int id) { vm.Post = _postRepo.GetPublishedPostById(id); vm.TagsOnPost = _tagRepository.GetTagsByPostId(id); try { foreach (Tag t in vm.TagsOnPost) { var postTag = _postTagRepo.GetPostTagByPostandTag(t.Id, id); if (postTag != null) { _postTagRepo.DeletePostTag(postTag.Id); } } foreach (int tagId in vm.AreChecked) { var newPostTag = new PostTag() { PostId = id, TagId = tagId }; _postTagRepo.AddPostTag(newPostTag); } return(RedirectToAction("Details", "Post", new { id = id })); } catch { return(View()); } }
// GET: PostTagController/Create public ActionResult Create(int id) { var allTags = _tagRepository.GetAllTags(); //get all relationships belonging to this post (PostTag) var postTags = _postTagRepo.GetPostTagsByPostId(id); List <int> foundTagIds = new List <int>(); //1. take the TagId's from each PostTag and add to list of id ints = has rel to this Post foreach (PostTag pt in postTags) { foundTagIds.Add(pt.TagId); } // loop through allTags, if Id is present in list 1 assign boolean true, if not assign boolean false (contains) foreach (Tag t in allTags) { var tId = t.Id; if (foundTagIds.Contains(tId)) { t.Selected = true; } else { t.Selected = false; } } var post = _postRepo.GetPublishedPostById(id); var vm = new TagIndexViewModel() { TagsOnPost = allTags, Post = post, }; return(View(vm)); }
public IActionResult Index() { var vm = new TagIndexViewModel { AllTags = TagService.All() }; return(View(vm)); }
public static TagIndexViewModel ConvertTagToTagIndexViewModel(Tag tag) { TagIndexViewModel tagIndexViewModel = new TagIndexViewModel(); tagIndexViewModel.Id = tag.Id; tagIndexViewModel.Name = tag.Name; tagIndexViewModel.SlugUrl = tag.SlugUrl; tagIndexViewModel.Posts = ClassPostConverter.ConvertListPostsToListPostIndexViewModel(tag.Posts.ToList()); return(tagIndexViewModel); }
public static List <TagIndexViewModel> ConvertListTagsToListTagIndexViewModel(List <Tag> tags) { List <TagIndexViewModel> tagViewModel = new List <TagIndexViewModel>(); foreach (var tag in tags) { TagIndexViewModel tagIndexViewModel = ConvertTagToTagIndexViewModel(tag); tagViewModel.Add(tagIndexViewModel); } return(tagViewModel); }