コード例 #1
0
        public async Task <IActionResult> OnPostSaveComment()
        {
            if (HttpContext.User.Identity.Name == null)
            {
                return(Redirect("/Account/Login"));
            }

            HttpResponseMessage response = new HttpResponseMessage();
            var client = _clientFactory.CreateClient();

            var blogComment = new BlogWebSite.Models.BlogComments();

            blogComment.BlogId  = BlogId.GetValueOrDefault(-1);
            blogComment.Comment = Comment;
            blogComment.UserId  = 1;

            client.DefaultRequestHeaders.Add("UserName", HttpContext.User.Identity.Name);
            response = await client.PostAsJsonAsync("https://localhost:44319/api/blogComments/", blogComment);

            if (response.IsSuccessStatusCode)
            {
                return(RedirectToPage("ViewBlog", new { id = BlogId }));
            }
            else
            {
                return(RedirectToPage("ViewBlog", new { id = BlogId }));
            }
        }
コード例 #2
0
        public override IQueryable <Post> GetSatisfiedItems(IQueryable <Post> src)
        {
            if (BlogId.GetValueOrDefault() > 0)
            {
                src = src.Where(x => x.BlogId == BlogId);
            }

            if (PostDateLaterThen > DateTime.MinValue)
            {
                src = src.Where(x => x.PostDate > PostDateLaterThen);
            }

            return(base.GetSatisfiedItems(src));
        }