Esempio n. 1
0
        public async Task <IActionResult> ViewAsync(long id)
        {
            string accessToken = await HttpContext.GetTokenAsync("access_token");

            if (!User.Identity.IsAuthenticated)
            {
                return(this.RedirectToAction("Login", "Account"));
            }
            else
            {
                ViewData["account_type"] = IdentityTools.GetAccountType(accessToken);
                ViewData["view"]         = "blog";
                ViewData["blog_id"]      = id;
            }

            var blog = await _blogAndPostClient.GetBlogAsync(id);

            var posts = await _blogAndPostClient.GetBlogPostsAsync(id);

            if (posts == null)
            {
                blog.Posts = new List <PostViewModel>();
            }
            else
            {
                blog.Posts = posts;
            }

            return(View(blog));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetBlogAsync(int id)
        {
            string accessToken = await HttpContext.GetTokenAsync("access_token");

            if (User.Identity.IsAuthenticated)
            {
                ViewData["account_type"] = IdentityTools.GetAccountType(accessToken);
            }
            else
            {
                ViewData["account_type"] = "none";
            }

            var blog = await _blogAndPostClient.GetBlogAsync(id);

            var posts = await _blogAndPostClient.GetBlogPostsAsync(id);

            if (posts == null)
            {
                blog.Posts = new List <PostViewModel>();
            }
            else
            {
                blog.Posts = posts;
            }

            return(PartialView("Show", blog));
        }
Esempio n. 3
0
        public async Task <IActionResult> IndexAsync()
        {
            string accessToken = await HttpContext.GetTokenAsync("access_token");

            if (User.Identity.IsAuthenticated && accessToken != null)
            {
                ViewData["account_type"] = IdentityTools.GetAccountType(accessToken);
                ViewData["view"]         = "home";
            }
            else
            {
                ViewData["account_type"] = "none";
            }


            /*
             * var usersApiUrl = _apiEndpoints.Value.UserApi;
             * var client = new RestClient(usersApiUrl + "user/" + userId);
             * var request = new RestRequest(Method.GET);
             * request.AddHeader("content-type", "application/json");
             * request.AddHeader("authorization", "Bearer " + accessToken);
             * IRestResponse response = client.Execute(request);
             */


            if ((string)ViewData["account_type"] == "administrator")
            {
                return(View("AdminIndex"));
            }
            else if ((string)ViewData["account_type"] == "creator")
            {
                string userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
                var    blogs  = await _blogAndPostClient.GetUserBlogs(userId);

                foreach (var blog in blogs)
                {
                    var posts = await _blogAndPostClient.GetBlogPostsAsync(blog.ID);

                    if (posts == null)
                    {
                        blog.Posts = new List <PostViewModel>();
                    }
                    else
                    {
                        blog.Posts = posts;
                    }
                }
                return(View("CreatorIndex", blogs));
            }
            else
            {
                var ids = await _blogAndPostClient.GetRandomIdsAsync(10);

                return(View(ids));
            }
        }