예제 #1
0
        public ActionResult <VaultKeeps> Post([FromBody] VaultKeeps vaultKeep)
        {
            vaultKeep.UserId = HttpContext.User.Identity.Name;
            VaultKeeps result = _vkRepo.AddVaultKeeps(vaultKeep);

            return(Created("/api/vaultKeeps/" + result.Id, result));
        }
예제 #2
0
        public VaultKeeps Create(VaultKeeps newVaultKeeps)
        {
            int id = _vkr.Create(newVaultKeeps);

            newVaultKeeps.Id = id;
            return(newVaultKeeps);
        }
예제 #3
0
 public string Delete(VaultKeeps vk, string userId)
 {
     if (vk == null || vk.UserId != userId)
     {
         throw new Exception("invalid Id");
     }
     _vkr.Delete(vk);
     return("Success");
 }
예제 #4
0
 public VaultKeeps AddVK([FromBody] VaultKeeps newVK)
 {
     if (ModelState.IsValid)
     {
         var user = HttpContext.User;
         return(_db.AddVK(newVK));
     }
     return(null);
 }
예제 #5
0
        //SECTION REMOVE KEEPS FROM VAULTS
        //NOTE referenced petshop for delete. needs review
        public void RemoveKeepFromVault(VaultKeeps vk)
        {
            var success = _db.Execute("DELETE FROM vaultKeeps WHERE vaultId = @VaultId AND keepId = @KeepId AND userId = @UserId", vk);

            if (success != 1)
            {
                throw new Exception("Delete Request Failed.");
            }
            ;
        }
예제 #6
0
        public VaultKeeps Create(VaultKeeps value)
        {
            string query = @"
      INSERT INTO vaultkeeps (vaultId, keepId, userId)
             VALUES(@VaultId, @KeepId, @UserId);";
            int    id    = _db.ExecuteScalar <int>(query, value);

            value.Id = id;
            return(value);
        }
예제 #7
0
        //SECTION ADD KEEPS TO VAULTKEEP (with an ID)

        public VaultKeeps AddKeepToVault(VaultKeeps vaultKeeps)
        {
            int id = _db.ExecuteScalar <int>(@" 
      INSERT INTO vaultKeeps (vaultId, keepId, userId)
      VALUES (@VaultId, @KeepId, @UserId);
      SELECT LAST_INSERT_ID();", vaultKeeps);

            vaultKeeps.Id = id;
            return(vaultKeeps);
        }
예제 #8
0
        public ActionResult <VaultKeeps> Create([FromBody] VaultKeeps vaultkeeps)
        {
            VaultKeeps newVaultKeeps = _vkr.CreateVaultKeeps(vaultkeeps);

            if (newVaultKeeps == null)
            {
                return(BadRequest("Something went wrong."));
            }
            return(Ok(newVaultKeeps));
        }
예제 #9
0
 public VaultKeeps Create([FromBody] VaultKeeps newVaultKeep)
 {
     if (ModelState.IsValid)
     {
         var user = HttpContext.User;
         newVaultKeep.UserId = user.Identity.Name;
         return(db.CreateVaultKeep(newVaultKeep));
     }
     return(null);
 }
예제 #10
0
        public VaultKeeps AddToVault(VaultKeeps toAdd)
        {
            int Id = _db.ExecuteScalar <int>(@"INSERT INTO vaultkeeps (vaultId, keepId, userId)
      VALUES (@vaultId, @keepId, @userId);
      SELECT LAST_INSERT_ID();
      ", toAdd);

            toAdd.id = Id;
            return(toAdd);
        }
예제 #11
0
        public string DeleteVaultKeep(VaultKeeps value)
        {
            string query        = @"DELETE FROM vaultkeeps WHERE vaultId = @VaultId AND keepId = @KeepId AND userId = @UserId;";
            int    rowsAffected = _db.Execute(query, value);

            if (rowsAffected < 1)
            {
                throw new Exception("Invalid Ids");
            }
            return("Successfully Deleted VaultKeep");
        }
예제 #12
0
        public ActionResult <VaultKeeps> Delete([FromBody] VaultKeeps payload)
        {
            string userId = HttpContext.User.Identity.Name;

            payload.UserId = userId;
            if (_vkRepo.DeleteVaultKeeps(payload))
            {
                return(Ok("success"));
            }
            return(NotFound("No Keep FOund"));
        }
예제 #13
0
        //AddKeep vaultkeep
        public VaultKeeps AddVK(VaultKeeps newvk)
        {
            int id = _db.ExecuteScalar <int>(@"
                INSERT INTO vaultkeeps (vaultId, keepId, userId)
                VALUES (@vaultId, @keepId, @userId);
                SELECT LAST_INSERT_ID();
            ", newvk);

            newvk.Id = id;
            return(newvk);
        }
예제 #14
0
        //Delete/put request
        public string Delete(VaultKeeps value)
        {
            string query       = "DELETE FROM vaultkeeps WHERE (vaultId = @VaultId AND keepId = @KeepId AND userId = @UserId)";
            int    changedRows = _db.Execute(query, value);

            if (changedRows < 1)
            {
                throw new Exception("Invalid Id");
            }
            return("Successfully deleted");
        }
        // CREATE VAULTKEEP
        public VaultKeeps CreateVaultKeep(VaultKeeps newVaultKeep)
        {
            int id = _db.ExecuteScalar <int>(@"
      INSERT INTO vaultkeeps (vaultId, keepId, userId)  
      VALUES (@VaultId,@KeepId,@UserId); 
      SELECT LAST_INSERT_ID();
      ", newVaultKeep);

            newVaultKeep.Id = id;
            return(newVaultKeep);
        }
예제 #16
0
        public int Create(VaultKeeps newVaultKeeps)
        {
            string sql = @"
            INSERT INTO vaultKeeps
            (vaultId, keepId, userId)
            VALUES
            (@VaultId, @KeepId, @UserId);
      SELECT LAST_INSERT_ID();
      ";

            return(_db.ExecuteScalar <int>(sql, newVaultKeeps)); //get the new id back from line 36 and return to service
        }
예제 #17
0
 public ActionResult <VaultKeeps> Create([FromBody] VaultKeeps newVaultKeep)
 {
     try
     {
         newVaultKeep.UserId = HttpContext.User.FindFirstValue("Id");
         return(Ok(_vks.Create(newVaultKeep)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
예제 #18
0
 public ActionResult <VaultKeeps> Delete([FromBody] VaultKeeps vaultKeep)
 {
     try
     {
         string userId = HttpContext.User.FindFirstValue("id");
         return(Ok(_vks.Delete(vaultKeep, userId)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public VaultKeeps CreateVaultKeeps(VaultKeeps newVaultKeeps)
        //need to ask about this, should be (vaultkeep newVaultKeep)
        {
            int id = _db.ExecuteScalar <int>(@"
                INSERT INTO vaultkeeps (vaultId, keepId, userId)
                VALUES (@VaultId, @KeepId, @UserId);
                SELECT LAST_INSERT_ID();
            ", newVaultKeeps);

            newVaultKeeps.Id = id;
            return(newVaultKeeps);
        }
예제 #20
0
 public ActionResult <VaultKeeps> Post([FromBody] VaultKeeps value)
 {
     try
     {
         value.UserId = HttpContext.User.FindFirstValue("Id");
         return(Ok(_repo.Create(value)));
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
예제 #21
0
        //AddKeep vaultkeep
        public VaultKeeps AddVK(VaultKeeps newvk)
        {
            // need to first run sql statement to check if keepId is already connected to the vaultId
            // this is to block adding same keeps to vault
            int id = _db.ExecuteScalar <int>(@"
                INSERT INTO vaultkeeps (vaultId, keepId, userId)
                VALUES (@vaultId, @keepId, @userId);
                SELECT LAST_INSERT_ID();
            ", newvk);

            newvk.Id = id;
            return(newvk);
        }
예제 #22
0
        public string Del(VaultKeeps value)
        {
            string query = @"DELETE FROM vaultkeeps WHERE
            (vaultId = @vaultId AND keepId = @keepId AND userId = @userId)";

            int deleted = _db.Execute(query, value);

            if (deleted < 1)
            {
                throw new Exception("Invalid Request");
            }
            return("Delete Complete");
        }
예제 #23
0
 public ActionResult <String> Put([FromBody] VaultKeeps value)
 {
     try
     {
         string userId = HttpContext.User.FindFirstValue("Id");
         value.UserId = userId;
         return(Ok(_repo.Delete(value)));
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
예제 #24
0
 public ActionResult <string> Post([FromBody] VaultKeeps vk)
 {
     try
     {
         string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         vk.UserId = userId;
         return(Ok(_vks.Create(vk)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
예제 #25
0
 public ActionResult <VaultKeeps> AddKeepToVault([FromBody] VaultKeeps vaultKeeps)
 {
     try
     {
         vaultKeeps.UserId = HttpContext.User.FindFirstValue("Id"); //fixed in model
         return(Ok(_repository.AddKeepToVault(vaultKeeps)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
         // return BadRequest("Unable to add this Keep to this Vault."); //<---brooklyn change
     }
 }
예제 #26
0
 public ActionResult <string> DeleteVaultKeep(int id, [FromBody] VaultKeeps value)
 {
     try
     {
         var uid = HttpContext.User.FindFirstValue("Id");
         value.UserId = uid;
         value.Id     = id;
         return(Ok(_repo.DeleteVaultKeep(value)));
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
예제 #27
0
 public ActionResult <String> AddKeepToVault(int id, [FromBody] VaultKeeps vaultKeeps)
 {
     try
     {
         var uid = HttpContext.User.FindFirstValue("Id");
         vaultKeeps.UserId  = uid;
         vaultKeeps.VaultId = id;
         return(Ok(_repo.AddKeepToVault(vaultKeeps)));
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
예제 #28
0
 public ActionResult <VaultKeeps> RemoveKeepFromVault([FromBody] VaultKeeps vk) //jake change to vk
 {
     try
     {
         // attach the your userId to vk here
         vk.UserId = HttpContext.User.FindFirstValue("Id");
         _repository.RemoveKeepFromVault(vk);
         return(Ok("Keep successfully removed from Vault."));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
예제 #29
0
 public ActionResult<string> Put([FromBody] VaultKeeps value)
 {
         try
         {
         var userId = HttpContext.User.FindFirstValue("Id");
         value.UserId = userId;
         return Ok(_repo.Del(value));
         }
         catch (Exception e)
         {
             return BadRequest(e.Message);
         }
   
 }
        // Edit
        public VaultKeeps EditVaultKeep(int id, VaultKeeps VaultKeep)
        {
            VaultKeep.Id = id;
            var i = _db.Execute(@"
                UPDATE vaultkeeps SET
                    vaultId = @VaultId,
                    keepId = @KeepId
                WHERE id = @Id
            ", VaultKeep);

            if (i > 0)
            {
                return(VaultKeep);
            }
            return(null);
        }