コード例 #1
0
 public ActionResult <Blog> Create([FromBody] Blog newBlog)
 {
     try
     {
         return(Ok(_blogsService.Create(newBlog)));
     }
     catch (System.Exception err)
     {
         return(BadRequest(err.Message));
     }
 }
コード例 #2
0
 public ActionResult <Blog> Create([FromBody] Blog newBlog)
 {
     try
     {
         newBlog.CreatorEmail = "*****@*****.**";
         return(Ok(_bs.Create(newBlog)));
     }
     catch (System.Exception err)
     {
         return(BadRequest(err.Message));
     }
 }
コード例 #3
0
 public ActionResult <Blog> Post([FromBody] Blog newBlog)
 {
     try
     {
         var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         newBlog.CreatorId = userId;
         return(Ok(_ks.Create(newBlog)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #4
0
 public ActionResult <Blog> Create([FromBody] Blog newBlog)
 {
     try
     {
         // hard code email for now because there is no auth0, otherwise there'd be models for user profiles
         newBlog.CreatorEmail = "*****@*****.**";
         return(Ok(_bs.Create(newBlog)));
     }
     catch (System.Exception err)
     {
         return(BadRequest(err.Message));
     }
 }
コード例 #5
0
        public void Create_ShouldCreateBlogAndReturnTheId()
        {
            Mapper.Initialize(x => x.AddProfile <MapperConfiguration>());
            var repo = new Mock <IRepository <Blog> >();

            var service = new BlogsService(repo.Object);

            //do
            var result = service.Create("Title", "Content");

            //assert
            result.Should().NotBeNull().And.BeOfType <Task <int> >();
        }
コード例 #6
0
 public ActionResult <Blog> Create([FromBody] Blog newBlog)
 {
     try
     {
         // req.user.sub || req.userInfo.sub
         string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         // NOTE DONT TRUST THE USER TO TELL YOU WHO THEY ARE!!!!
         newBlog.AuthorId = userId;
         return(Ok(_bs.Create(newBlog)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #7
0
        public async Task <ActionResult <Blog> > Create([FromBody] Blog newBlog)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                newBlog.CreatorId = userInfo.Id;
                Blog created = _bs.Create(newBlog);
                created.Creator = userInfo;
                return(Ok(created));
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #8
0
        public ActionResult CreateNewBlog([FromHeader] string password, [FromBody] Blog blog)
        {
            if (password != "rockrockwhite")
            {
                return(BadRequest(new Response <string>(new PasswordError())
                {
                    resultBody = ""
                }));
            }

            _blogsService.Create(blog);
            return(Ok(new Response <Blog>(new Ok())
            {
                resultBody = blog
            }));
        }
コード例 #9
0
        public async Task <ActionResult <Blog> > Post([FromBody] Blog newBlog)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                newBlog.CreatorEmail = userInfo.Email;
                Blog created = _serv.Create(newBlog);
                created.Creator = userInfo;
                return(Ok(created));
            }
            catch (System.Exception error)
            {
                return(BadRequest(error.Message));
            }
        }
コード例 #10
0
        public async Task <ActionResult <Blog> > CreateAsync([FromBody] Blog newBlog)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                newBlog.CreatorId = userInfo.Id;
                Blog created = _service.Create(newBlog);
                //this is your 'populate' for create
                created.Creator = userInfo;
                return(Ok(created));
            }
            catch (Exception err)
            {
                return(BadRequest(err.Message));
            }
        }
コード例 #11
0
        public async Task <ActionResult <Blog> > Create([FromBody] Blog newBlog)
        {
            try
            {
                // TODO[epic=Auth] Get the user info to set the creatorID
                Account userInfo = await HttpContext.GetUserInfoAsync <Account>();

                // safety to make sure an account exists for that user before CREATE-ing stuff.
                Account fullAccount = _acctService.GetOrCreateAccount(userInfo);
                newBlog.CreatorId = userInfo.Id;

                Blog blog = _service.Create(newBlog);
                //TODO[epic=Populate] adds the account to the new object as the creator
                blog.Creator = fullAccount;
                return(Ok(blog));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }