コード例 #1
0
ファイル: BlogsApiController.cs プロジェクト: jasonh88/Blog
        public HttpResponseMessage CreateBlog(Blogs model)
        {
            BlogsService blogSvc = new BlogsService();
            int          id      = blogSvc.CreateBlog(model);

            return(Request.CreateResponse(HttpStatusCode.OK, id));
        }
コード例 #2
0
 public IActionResult Create(Blog blog)
 {
     if (ModelState.IsValid)
     {
         _service.CreateBlog(blog);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(blog));
 }
コード例 #3
0
        public async Task <ActionResult <Blog> > CreateBlogAsync([FromBody] Blog newBlog)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                newBlog.CreatorId = userInfo.Id;
                Blog created = _service.CreateBlog(newBlog);
                created.Creator = userInfo;
                return(created);
            }
            catch (System.Exception err)
            {
                return(BadRequest(err.Message));
            }
        }
コード例 #4
0
        public async Task <ActionResult <Blog> > Create([FromBody] Blog newBlog)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                Profile fullProfile = _profileService.GetOrCreateAccountProfile(userInfo);
                newBlog.CreatorId = userInfo.Id;

                Blog blog = _service.CreateBlog(newBlog);
                blog.Creator = fullProfile;
                return(Ok(blog));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }