public HttpResponseMessage CreateBlog(Blogs model) { BlogsService blogSvc = new BlogsService(); int id = blogSvc.CreateBlog(model); return(Request.CreateResponse(HttpStatusCode.OK, id)); }
public IActionResult Create(Blog blog) { if (ModelState.IsValid) { _service.CreateBlog(blog); return(RedirectToAction(nameof(Index))); } return(View(blog)); }
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)); } }
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)); } }