Exemple #1
0
        public async Task <IActionResult> Details(int id)
        {
            var post = postService.GetById(id);

            if (post == null)
            {
                return(NotFound());
            }

            await postService.AddClick(id);

            bool allMedias = true;



            var postViewModel = viewService.MapPostViewModel(post, allMedias);

            postViewModel.clickCount = await postService.GetPostClickCount(post.Id);

            var model = new PostEditForm()
            {
                post = postViewModel
            };


            var categoryIds = await postService.GetCategoryIdsAsync(id);

            model.post.categoryId = categoryIds.FirstOrDefault();

            if (Request.IsAjaxRequest())
            {
                return(new ObjectResult(model));
            }

            ViewData["id"]    = id;
            ViewData["model"] = this.ToJsonString(model);


            bool excludeDefault = true;
            var  categories     = await postService.GetCategoriesAsync(excludeDefault);

            var options = categories.Select(c => new { value = c.Id, text = c.Name });



            ViewData["category"] = model.post.categoryId;

            ViewData["categories"] = this.ToJsonString(options);

            return(View("Index"));
        }