Exemplo n.º 1
0
 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));
     }
 }
Exemplo n.º 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));
     }
 }
        [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);
        }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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);
   }
 }
Exemplo n.º 8
0
        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));
            }
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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));
     }
 }
Exemplo n.º 11
0
 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));
     }
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 13
0
 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));
     }
 }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 16
0
 public ActionResult <Keep> Create([FromBody] Keep keep)
 {
     keep.UserId = HttpContext.User.FindFirstValue("Id");
     return(Ok(_service.Create(keep)));
 }