コード例 #1
0
ファイル: KeepsController.cs プロジェクト: austinhugus/Keepr
 public ActionResult <Keep> Post([FromBody] Keep newKeep)
 {
     try {
         var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         newKeep.UserId = userId;
         return(Ok(_ks.Create(newKeep)));
     } catch (Exception e) {
         return(BadRequest(e.Message));
     }
 }
コード例 #2
0
 public ActionResult <Keep> Create([FromBody] Keep newKeep)
 {
     try
     {
         newKeep.UserId = HttpContext.User.FindFirstValue("Id");
         return(Ok(_ks.Create(newKeep)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #3
0
        [Fact] // Checks if Create can create new Keep
        public void CanCreate()
        {
            Keep newKeep = new Keep {
                Name = "newKeep"
            };

            moqKeepsRepository.Setup(repo => repo.Create(newKeep)).Returns(newKeep);

            var result = keepsService.Create(newKeep);

            Assert.Equal(newKeep, result);
        }
コード例 #4
0
 public ActionResult <Keep> Post([FromBody] Keep newKeep)
 {
     try
     {
         string userId = findUserInfo();
         newKeep.UserId = userId;
         return(Ok(_ks.Create(newKeep)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #5
0
        public async Task <ActionResult <Keep> > Create([FromBody] Keep newKeep)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                return(Ok(_service.Create(newKeep, userInfo.Id)));
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #6
0
 public ActionResult <Keep> Create([FromBody] Keep newKeep)
 {
     try
     {
         string reqUserId = HttpContext.User.FindFirstValue("Id");
         User   user      = _as.GetUserById(reqUserId);
         newKeep.UserId = user.Id;
         return(Ok(_ks.Create(newKeep)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #7
0
 public ActionResult<Keep> Post([FromBody] Keep newKeep)
 {
   try
   {
     // NOTE DONT TRUST THE USER TO TELL YOU WHO THEY ARE!!!!
     string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
     newKeep.UserId = userId;
     return Ok(_ks.Create(newKeep));
   }
   catch (Exception e)
   {
     return BadRequest(e.Message);
   }
 }
コード例 #8
0
ファイル: KeepsController.cs プロジェクト: JoeAlmanza/keepr
        public async Task <ActionResult <Keep> > Create([FromBody] Keep newKeep)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                newKeep.CreatorId = userInfo.Id;
                newKeep.Creator   = userInfo;
                return(Ok(_ks.Create(newKeep)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #9
0
        public async Task <ActionResult <Keep> > Create([FromBody] Keep newKeep)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                newKeep.CreatorId = userInfo.Id;
                Keep created = _keepsService.Create(newKeep);
                created.Creator = userInfo;
                return(Ok(created));
            }
            catch (System.Exception error)
            {
                return(BadRequest(error.Message));
            }
        }
コード例 #10
0
 public ActionResult <Keep> Post([FromBody] Keep newKeep)
 {
     try
     {
         Claim user = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier);
         if (user == null)
         {
             throw new Exception("Must be logged in.");
         }
         newKeep.UserId = user.Value;
         return(Ok(_ks.Create(newKeep)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #11
0
ファイル: KeepsController.cs プロジェクト: KaydenCooper/keepr
 public ActionResult <Keep> Post([FromBody] Keep newKeep)
 {
     try
     {
         var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier);
         newKeep.UserId = userId.Value;
         if (userId == null)
         {
             throw new Exception("Please Login to Continue!");
         }
         return(Ok(_ks.Create(newKeep)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #12
0
 public ActionResult <Keep> Create([FromBody] Keep newKeep)
 {
     try
     {
         Claim user = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier);
         if (user == null)
         {
             throw new Exception("User Id 'userId', is incorrect, make sure you're currently logged in");
         }
         newKeep.UserId = user.Value;
         return(Ok(_ks.Create(newKeep)));
     }
     catch (Exception error)
     {
         return(BadRequest(error.Message));
     }
 }
コード例 #13
0
ファイル: KeepsController.cs プロジェクト: Dakota-Logan/keppr
 public ActionResult <Keep> Post([FromBody] Keep newKeep)
 {
     try
     {
         var ctx = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier);
         if (ctx == null)
         {
             throw new Exception("You need to be logged in to do that!");
         }
         string userId = ctx.Value;
         newKeep.UserId = userId;
         return(Ok(_ks.Create(newKeep)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #14
0
        public async Task <ActionResult <Keep> > Create([FromBody] Keep newKeep)
        {
            try
            {
                //gets the logged in users info and assigns as a Profile obj.
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                newKeep.CreatorId = userInfo.Id;
                //Create the Keep
                Keep createdKeep = _service.Create(newKeep);
                //Set the creator for new Keep to userInfo before returning.
                createdKeep.Creator = userInfo;
                return(Ok(createdKeep));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #15
0
        public async Task <ActionResult <Keep> > CreateAsync([FromBody] Keep keep)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                keep.CreatorId = userInfo.Id;
                keep.Creator   = userInfo;
                if (keep.Img == null)
                {
                    keep.Img = "https://i.ibb.co/cwq36B9/Choko-Scrunch.jpg";
                }
                Keep created = _kService.Create(keep);
                return(Ok(created));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
コード例 #16
0
ファイル: KeepsController.cs プロジェクト: terryphelps/Keeper
 public ActionResult <Keep> Create([FromBody] Keep keep)
 {
     keep.UserId = HttpContext.User.FindFirstValue("Id");
     return(Ok(_service.Create(keep)));
 }